1
0
mirror of https://github.com/golang/go synced 2024-11-19 23:24:45 -07:00

cmd/dist: improve isGitRepo to handle git "worktree"s

Simply checking the exit code of `git rev-parse --git-dir` should
suffice here, but that requires deviating from the infrastructure
provided by `run`, so I've left that for a future change.

Fixes #11211.

Change-Id: I7cbad86a8a06578f52f66f734f5447b597ddc962
Reviewed-on: https://go-review.googlesource.com/18213
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Tamir Duberstein 2015-12-30 11:15:38 -05:00 committed by Russ Cox
parent be20948e27
commit ab096d587f

18
src/cmd/dist/build.go vendored
View File

@ -322,18 +322,12 @@ func findgoversion() string {
// isGitRepo reports whether the working directory is inside a Git repository. // isGitRepo reports whether the working directory is inside a Git repository.
func isGitRepo() bool { func isGitRepo() bool {
p := ".git" // NB: simply checking the exit code of `git rev-parse --git-dir` would
for { // suffice here, but that requires deviating from the infrastructure
fi, err := os.Stat(p) // provided by `run`.
if os.IsNotExist(err) { gitDir := chomp(run(goroot, 0, "git", "rev-parse", "--git-dir"))
p = filepath.Join("..", p) fi, err := os.Stat(gitDir)
continue return err == nil && fi.IsDir()
}
if err != nil || !fi.IsDir() {
return false
}
return true
}
} }
/* /*