Skip to content

Commit a768197

Browse files
committed
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>
1 parent 16c483b commit a768197

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

cmd/go-contrib-init/contrib.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func main() {
3535
checkWorkingDir()
3636
checkGitOrigin()
3737
checkGitCodeReview()
38+
fmt.Print("All good. Happy hacking!\n" +
39+
"Remember to squash your revised commits and preserve the magic Change-Id lines.\n" +
40+
"Next steps: https://golang.org/doc/contribute.html#commit_changes\n")
3841
}
3942

4043
func checkCLA() {
@@ -139,16 +142,25 @@ func checkGitCodeReview() {
139142
if err != nil {
140143
log.Printf("Error running go get golang.org/x/review/git-codereview: %v", cmdErr(err))
141144
}
145+
log.Printf("Installed git-codereview (ran `go get golang.org/x/review/git-codereview`)")
142146
}
143-
if *dry {
144-
// TODO: check the aliases. For now, just return.
145-
return
146-
}
147+
missing := false
147148
for _, cmd := range []string{"change", "gofmt", "mail", "pending", "submit", "sync"} {
148-
err := exec.Command("git", "config", "alias."+cmd, "codereview "+cmd).Run()
149-
if err != nil {
150-
log.Fatalf("Error setting alias.%s: %v", cmd, cmdErr(err))
149+
v, _ := exec.Command("git", "config", "alias."+cmd).Output()
150+
if strings.Contains(string(v), "codereview") {
151+
continue
152+
}
153+
if *dry {
154+
log.Printf("Missing alias. Run:\n\t$ git config alias.%s \"codereview %s\"", cmd, cmd)
155+
missing = true
156+
} else {
157+
err := exec.Command("git", "config", "alias."+cmd, "codereview "+cmd).Run()
158+
if err != nil {
159+
log.Fatalf("Error setting alias.%s: %v", cmd, cmdErr(err))
160+
}
151161
}
152162
}
153-
163+
if missing {
164+
log.Fatalf("Missing aliases. (While optional, this tool assumes you use them.)")
165+
}
154166
}

0 commit comments

Comments
 (0)