diff --git a/dashboard/builder/vcs.go b/dashboard/builder/vcs.go index 89700eb0..97300c64 100644 --- a/dashboard/builder/vcs.go +++ b/dashboard/builder/vcs.go @@ -95,6 +95,18 @@ func (r *Repo) UpdateTo(hash string) error { r.Lock() defer r.Unlock() + if r.Master.VCS.Cmd == "git" { + cmd := exec.Command("git", "reset", "--hard", hash) + var log bytes.Buffer + err := run(cmd, runTimeout(*cmdTimeout), runDir(r.Path), allOutput(&log)) + if err != nil { + return fmt.Errorf("Error running git update -C %v: %v ; output=%s", hash, err, log.Bytes()) + } + return nil + } + + // Else go down three more levels of abstractions, at + // least two of which are broken for git. return timeout(*cmdTimeout, func() error { return r.Master.VCS.TagSync(r.Path, hash) }) @@ -159,23 +171,38 @@ func (r *Repo) Log() ([]HgLog, error) { return logStruct.Log, nil } -// FullHash returns the full hash for the given Mercurial revision. +// FullHash returns the full hash for the given Git or Mercurial revision. func (r *Repo) FullHash(rev string) (string, error) { r.Lock() defer r.Unlock() var hash string err := timeout(*cmdTimeout, func() error { - data, err := r.Master.VCS.LogAtRev(r.Path, rev, "{node}") - if err != nil { - return err + var data []byte + // Avoid the vcs package for git, since it's broken + // for git, and and we're trying to remove levels of + // abstraction which are increasingly getting + // difficult to navigate. + if r.Master.VCS.Cmd == "git" { + cmd := exec.Command("git", "rev-parse", rev) + var out bytes.Buffer + err := run(cmd, runTimeout(*cmdTimeout), runDir(r.Path), allOutput(&out)) + data = out.Bytes() + if err != nil { + return fmt.Errorf("Failed to find FullHash of %q; git rev-parse: %v, %s", rev, err, data) + } + } else { + var err error + data, err = r.Master.VCS.LogAtRev(r.Path, rev, "{node}") + if err != nil { + return err + } } - s := strings.TrimSpace(string(data)) if s == "" { return fmt.Errorf("cannot find revision") } - if len(s) != 40 { + if len(s) != 40 { // correct for both hg and git return fmt.Errorf("%s returned invalid hash: %s", r.Master.VCS, s) } hash = s