From 16c483b02b3c9045d0a117e3646ed075e9e67e23 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 7 Jun 2017 23:28:22 +0000 Subject: [PATCH] cmd/go-contrib-init: don't assume user is in root directory of git checkout Updates golang/go#17802 Change-Id: I8eeae42f395dee4eedd17114f10bb56536783089 Reviewed-on: https://go-review.googlesource.com/45082 Reviewed-by: Steve Francia --- cmd/go-contrib-init/contrib.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/go-contrib-init/contrib.go b/cmd/go-contrib-init/contrib.go index 01f8d71b..e4719dbd 100644 --- a/cmd/go-contrib-init/contrib.go +++ b/cmd/go-contrib-init/contrib.go @@ -94,15 +94,16 @@ func checkGitOrigin() { if _, err := exec.LookPath("git"); err != nil { log.Fatalf("You don't appear to have git installed. Do that.") } - if _, err := os.Stat(".git"); err != nil { - log.Fatalf("You are not currently in a git checkout of https://go.googlesource.com/%s", *repo) - } + wantRemote := "https://go.googlesource.com/" + *repo remotes, err := exec.Command("git", "remote", "-v").Output() if err != nil { - log.Fatalf("Error running git remote -v: %v", cmdErr(err)) + msg := cmdErr(err) + if strings.Contains(msg, "Not a git repository") { + log.Fatalf("Your current directory is not in a git checkout of %s", wantRemote) + } + log.Fatalf("Error running git remote -v: %v", msg) } matches := 0 - wantRemote := "https://go.googlesource.com/" + *repo for _, line := range strings.Split(string(remotes), "\n") { line = strings.TrimSpace(line) if !strings.HasPrefix(line, "origin") {