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:
parent
24a7fa781c
commit
d76ba60748
|
|
@ -95,6 +95,18 @@ func (r *Repo) UpdateTo(hash string) error {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
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 timeout(*cmdTimeout, func() error {
|
||||||
return r.Master.VCS.TagSync(r.Path, hash)
|
return r.Master.VCS.TagSync(r.Path, hash)
|
||||||
})
|
})
|
||||||
|
|
@ -159,23 +171,38 @@ func (r *Repo) Log() ([]HgLog, error) {
|
||||||
return logStruct.Log, nil
|
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) {
|
func (r *Repo) FullHash(rev string) (string, error) {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
|
|
||||||
var hash string
|
var hash string
|
||||||
err := timeout(*cmdTimeout, func() error {
|
err := timeout(*cmdTimeout, func() error {
|
||||||
data, err := r.Master.VCS.LogAtRev(r.Path, rev, "{node}")
|
var data []byte
|
||||||
if err != nil {
|
// Avoid the vcs package for git, since it's broken
|
||||||
return err
|
// 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))
|
s := strings.TrimSpace(string(data))
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return fmt.Errorf("cannot find revision")
|
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)
|
return fmt.Errorf("%s returned invalid hash: %s", r.Master.VCS, s)
|
||||||
}
|
}
|
||||||
hash = s
|
hash = s
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue