From: Tamir Duberstein Date: Wed, 30 Dec 2015 16:15:38 +0000 (-0500) Subject: cmd/dist: improve isGitRepo to handle git "worktree"s X-Git-Tag: go1.6beta2~132 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ab096d587f9bb5dcdf895511ee6d213aade7e30f;p=gostls13.git 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 --- diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index 634c52c3b0..85cf3f9136 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -322,18 +322,12 @@ func findgoversion() string { // isGitRepo reports whether the working directory is inside a Git repository. func isGitRepo() bool { - p := ".git" - for { - fi, err := os.Stat(p) - if os.IsNotExist(err) { - p = filepath.Join("..", p) - continue - } - if err != nil || !fi.IsDir() { - return false - } - return true - } + // NB: simply checking the exit code of `git rev-parse --git-dir` would + // suffice here, but that requires deviating from the infrastructure + // provided by `run`. + gitDir := chomp(run(goroot, 0, "git", "rev-parse", "--git-dir")) + fi, err := os.Stat(gitDir) + return err == nil && fi.IsDir() } /*