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>
This commit is contained in:
parent
16c483b02b
commit
a768197954
|
@ -35,6 +35,9 @@ func main() {
|
||||||
checkWorkingDir()
|
checkWorkingDir()
|
||||||
checkGitOrigin()
|
checkGitOrigin()
|
||||||
checkGitCodeReview()
|
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() {
|
func checkCLA() {
|
||||||
|
@ -139,16 +142,25 @@ func checkGitCodeReview() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error running go get golang.org/x/review/git-codereview: %v", cmdErr(err))
|
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 {
|
missing := false
|
||||||
// TODO: check the aliases. For now, just return.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, cmd := range []string{"change", "gofmt", "mail", "pending", "submit", "sync"} {
|
for _, cmd := range []string{"change", "gofmt", "mail", "pending", "submit", "sync"} {
|
||||||
err := exec.Command("git", "config", "alias."+cmd, "codereview "+cmd).Run()
|
v, _ := exec.Command("git", "config", "alias."+cmd).Output()
|
||||||
if err != nil {
|
if strings.Contains(string(v), "codereview") {
|
||||||
log.Fatalf("Error setting alias.%s: %v", cmd, cmdErr(err))
|
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.)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue