1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:08:36 -06:00

cmd/go-contrib-init: add git-codereview bits

Updates golang/go#17802

Change-Id: Ic5278804203029926dd5a26e571f79aaafb13110
Reviewed-on: https://go-review.googlesource.com/45080
Reviewed-by: Steve Francia <spf@golang.org>
This commit is contained in:
Brad Fitzpatrick 2017-06-07 23:16:00 +00:00
parent fe66dd2e3e
commit 154c88c09d

View File

@ -21,7 +21,10 @@ import (
"strings"
)
var repo = flag.String("repo", "go", "Which go repo you want to contribute to. Use \"go\" for the core, or e.g. \"net\" for golang.org/x/net/*")
var (
repo = flag.String("repo", "go", "Which go repo you want to contribute to. Use \"go\" for the core, or e.g. \"net\" for golang.org/x/net/*")
dry = flag.Bool("dry-run", false, "Fail with problems instead of trying to fix things.")
)
func main() {
log.SetFlags(0)
@ -31,6 +34,7 @@ func main() {
checkGoroot()
checkWorkingDir()
checkGitOrigin()
checkGitCodeReview()
}
func checkCLA() {
@ -106,6 +110,7 @@ func checkGitOrigin() {
}
if !strings.Contains(line, wantRemote) {
curRemote := strings.Fields(strings.TrimPrefix(line, "origin"))[0]
// TODO: if not in dryRun mode, just fix it?
log.Fatalf("Current directory's git was cloned from %q; origin should be %q", curRemote, wantRemote)
}
matches++
@ -121,3 +126,28 @@ func cmdErr(err error) string {
}
return fmt.Sprint(err)
}
func checkGitCodeReview() {
if _, err := exec.LookPath("git-codereview"); err != nil {
if *dry {
log.Fatalf("You don't appear to have git-codereview tool. While this is technically optional,\n" +
"almost all Go contributors use it. Our documentation and this tool assume it is used.\n" +
"To install it, run:\n\n\t$ go get golang.org/x/review/git-codereview\n\n(Then run go-contrib-init again)")
}
err := exec.Command("go", "get", "golang.org/x/review/git-codereview").Run()
if err != nil {
log.Printf("Error running go get golang.org/x/review/git-codereview: %v", cmdErr(err))
}
}
if *dry {
// TODO: check the aliases. For now, just return.
return
}
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))
}
}
}