]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: show friendlier error message when building outside a Git repo
authorAndrew Gerrand <adg@golang.org>
Thu, 19 Feb 2015 21:34:30 +0000 (08:34 +1100)
committerAndrew Gerrand <adg@golang.org>
Thu, 19 Feb 2015 22:33:45 +0000 (22:33 +0000)
Fixes #9932

Change-Id: I7943470a1784278a5c6e99c3b66c59d4953734ba
Reviewed-on: https://go-review.googlesource.com/5340
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/dist/build.go

index 3932c0bc42fc1278e796b1f9a7a5e41e5580cbed..141d3c9660719f1e64f073db8da2e9507d0c3f81 100644 (file)
@@ -296,6 +296,11 @@ func findgoversion() string {
                return chomp(readfile(path))
        }
 
+       // Show a nicer error message if this isn't a Git repo.
+       if !isGitRepo() {
+               fatal("FAILED: not a Git repo; must put a VERSION file in $GOROOT")
+       }
+
        // Otherwise, use Git.
        // What is the current branch?
        branch := chomp(run(goroot, CheckExit, "git", "rev-parse", "--abbrev-ref", "HEAD"))
@@ -321,6 +326,22 @@ func findgoversion() string {
        return tag
 }
 
+// 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
+       }
+}
+
 /*
  * Initial tree setup.
  */