mirror of
https://github.com/golang/go
synced 2024-11-23 11:00:08 -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. 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/18323 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
fb142ee9b9
commit
24ef1d60f0
19
src/cmd/dist/build.go
vendored
19
src/cmd/dist/build.go
vendored
@ -322,18 +322,15 @@ 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"))
|
||||
if !filepath.IsAbs(gitDir) {
|
||||
gitDir = filepath.Join(goroot, gitDir)
|
||||
}
|
||||
fi, err := os.Stat(gitDir)
|
||||
return err == nil && fi.IsDir()
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user