Skip to content

Commit

Permalink
cmd/dist: show friendlier error message when building outside a Git repo
Browse files Browse the repository at this point in the history
Fixes golang#9932

Change-Id: I7943470a1784278a5c6e99c3b66c59d4953734ba
Reviewed-on: https://go-review.googlesource.com/5340
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
adg committed Feb 19, 2015
1 parent 5254b7e commit 5f84238
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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.
*/
Expand Down

0 comments on commit 5f84238

Please sign in to comment.