cmd/go-contrib-init: add git alias dry run mode, add success message
Updates golang/go#17802
Change-Id: I2b5473bc0539a760c26889497a301808deb5e5ae
Reviewed-on: https://go-review.googlesource.com/45083
Reviewed-by: Steve Francia <spf@golang.org>
diff --git a/cmd/go-contrib-init/contrib.go b/cmd/go-contrib-init/contrib.go
index e4719db..8064950 100644
--- a/cmd/go-contrib-init/contrib.go
+++ b/cmd/go-contrib-init/contrib.go
@@ -35,6 +35,9 @@
checkWorkingDir()
checkGitOrigin()
checkGitCodeReview()
+ fmt.Print("All good. Happy hacking!\n" +
+ "Remember to squash your revised commits and preserve the magic Change-Id lines.\n" +
+ "Next steps: https://golang.org/doc/contribute.html#commit_changes\n")
}
func checkCLA() {
@@ -139,16 +142,25 @@
if err != nil {
log.Printf("Error running go get golang.org/x/review/git-codereview: %v", cmdErr(err))
}
+ log.Printf("Installed git-codereview (ran `go get golang.org/x/review/git-codereview`)")
}
- if *dry {
- // TODO: check the aliases. For now, just return.
- return
- }
+ missing := false
for _, cmd := range []string{"change", "gofmt", "mail", "pending", "submit", "sync"} {
- err := exec.Command("git", "config", "alias."+cmd, "codereview "+cmd).Run()
- if err != nil {
- log.Fatalf("Error setting alias.%s: %v", cmd, cmdErr(err))
+ v, _ := exec.Command("git", "config", "alias."+cmd).Output()
+ if strings.Contains(string(v), "codereview") {
+ continue
+ }
+ if *dry {
+ log.Printf("Missing alias. Run:\n\t$ git config alias.%s \"codereview %s\"", cmd, cmd)
+ missing = true
+ } else {
+ err := exec.Command("git", "config", "alias."+cmd, "codereview "+cmd).Run()
+ if err != nil {
+ log.Fatalf("Error setting alias.%s: %v", cmd, cmdErr(err))
+ }
}
}
-
+ if missing {
+ log.Fatalf("Missing aliases. (While optional, this tool assumes you use them.)")
+ }
}