1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:54:40 -07:00

dashboard/builder: don't use vcs TagSync to update a path to a hash

Change-Id: Ic4bbcb294995483482f51e3539b9ba8a741d1a98
Reviewed-on: https://go-review.googlesource.com/1245
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Brad Fitzpatrick 2014-12-09 15:04:26 +11:00
parent 24a7fa781c
commit d76ba60748

View File

@ -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