]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "cmd/dist: improve isGitRepo to handle git "worktree"s"
authorRuss Cox <rsc@golang.org>
Wed, 6 Jan 2016 17:39:34 +0000 (17:39 +0000)
committerRuss Cox <rsc@golang.org>
Wed, 6 Jan 2016 17:39:43 +0000 (17:39 +0000)
This reverts commit ab096d587f9bb5dcdf895511ee6d213aade7e30f.

Change-Id: Icf366aa43acc41b4f8474edae0297e554368bf14
Reviewed-on: https://go-review.googlesource.com/18321
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/dist/build.go

index 85cf3f913645c656911d24df145a21479b2d4a97..634c52c3b0fe554fab7ef18de9a626849ea81bb5 100644 (file)
@@ -322,12 +322,18 @@ func findgoversion() string {
 
 // isGitRepo reports whether the working directory is inside a Git repository.
 func isGitRepo() bool {
-       // 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()
+       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
+       }
 }
 
 /*