Commit 24ef1d60 authored by Tamir Duberstein's avatar Tamir Duberstein Committed by Russ Cox

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.

Originally by Tamir Duberstein but updated by iant & rsc to add
the filepath.Join logic.

Fixes #11211 (again).

Change-Id: I6d29b5ae39ba456088ae1fb5d41014cb91c86897
Reviewed-on: https://go-review.googlesource.com/18323Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent fb142ee9
...@@ -322,18 +322,15 @@ func findgoversion() string { ...@@ -322,18 +322,15 @@ 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) if !filepath.IsAbs(gitDir) {
continue gitDir = filepath.Join(goroot, gitDir)
} }
if err != nil || !fi.IsDir() { fi, err := os.Stat(gitDir)
return false return err == nil && fi.IsDir()
}
return true
}
} }
/* /*
......
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