diff --git a/dashboard/builder/env.go b/dashboard/builder/env.go index 26530a54..a49843d1 100644 --- a/dashboard/builder/env.go +++ b/dashboard/builder/env.go @@ -117,8 +117,11 @@ func (b *Builder) envvWindows() []string { // and returns the path workpath/go/src, the location of all go build scripts. func (env *goEnv) setup(repo *Repo, workpath, hash string, envv []string) (string, error) { goworkpath := filepath.Join(workpath, "go") - if _, err := repo.Clone(goworkpath, hash); err != nil { - return "", fmt.Errorf("error cloning repository: %s", err) + if err := repo.Export(goworkpath, hash); err != nil { + return "", fmt.Errorf("error exporting repository: %s", err) + } + if err := ioutil.WriteFile(filepath.Join(goworkpath, "VERSION"), []byte(hash), 0644); err != nil { + return "", fmt.Errorf("error writing VERSION file: %s", err) } return filepath.Join(goworkpath, "src"), nil } diff --git a/dashboard/builder/vcs.go b/dashboard/builder/vcs.go index dc0057aa..66dc251c 100644 --- a/dashboard/builder/vcs.go +++ b/dashboard/builder/vcs.go @@ -61,6 +61,24 @@ func (r *Repo) Clone(path, rev string) (*Repo, error) { }, nil } +// Export exports the current Repo at revision rev to a new destination. +func (r *Repo) Export(path, rev string) error { + r.Lock() + defer r.Unlock() + + downloadPath := r.Path + if !r.Exists() { + _, err := r.Clone(path, rev) + return err + } + + args := []string{r.Master.VCS.Cmd, "archive", "-t", "files", "-r", rev, path} + if err := run(*cmdTimeout, nil, downloadPath, args...); err != nil { + return fmt.Errorf("executing %s: %v", strings.Join(args, " "), err) + } + return nil +} + // UpdateTo updates the working copy of this Repo to the // supplied revision. func (r *Repo) UpdateTo(hash string) error {