Commit 80ca8c5d authored by David Symonds's avatar David Symonds

cmd/go: fix detached heads that are remnants of bad git clones.

Fixes #6042.

R=adg
CC=golang-dev
https://golang.org/cl/12923043
parent 3fe9b11c
...@@ -223,9 +223,36 @@ func (v *vcsCmd) create(dir, repo string) error { ...@@ -223,9 +223,36 @@ func (v *vcsCmd) create(dir, repo string) error {
// download downloads any new changes for the repo in dir. // download downloads any new changes for the repo in dir.
func (v *vcsCmd) download(dir string) error { func (v *vcsCmd) download(dir string) error {
if err := v.fixDetachedHead(dir); err != nil {
return err
}
return v.run(dir, v.downloadCmd) return v.run(dir, v.downloadCmd)
} }
// fixDetachedHead switches a Git repository in dir from a detached head to the master branch.
// Go versions before 1.2 downloaded Git repositories in an unfortunate way
// that resulted in the working tree state being on a detached head.
// That meant the repository was not usable for normal Git operations.
// Go 1.2 fixed that, but we can't pull into a detached head, so if this is
// a Git repository we check for being on a detached head and switch to the
// real branch, almost always called "master".
// TODO(dsymonds): Consider removing this for Go 1.3.
func (v *vcsCmd) fixDetachedHead(dir string) error {
if v != vcsGit {
return nil
}
// "git symbolic-ref HEAD" succeeds iff we are not on a detached head.
if err := v.runVerboseOnly(dir, "symbolic-ref HEAD"); err == nil {
// not on a detached head
return nil
}
if buildV {
log.Printf("%s on detached head; repairing", dir)
}
return v.run(dir, "checkout master")
}
// tags returns the list of available tags for the repo in dir. // tags returns the list of available tags for the repo in dir.
func (v *vcsCmd) tags(dir string) ([]string, error) { func (v *vcsCmd) tags(dir string) ([]string, error) {
var tags []string var tags []string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment