Skip to content

Commit

Permalink
cmd/go-contrib-init: add git-codereview bits
Browse files Browse the repository at this point in the history
Updates golang/go#17802

Change-Id: Ic5278804203029926dd5a26e571f79aaafb13110
Reviewed-on: https://go-review.googlesource.com/45080
Reviewed-by: Steve Francia <[email protected]>
  • Loading branch information
bradfitz committed Jun 7, 2017
1 parent fe66dd2 commit 154c88c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion cmd/go-contrib-init/contrib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -31,6 +34,7 @@ func main() {
checkGoroot()
checkWorkingDir()
checkGitOrigin()
checkGitCodeReview()
}

func checkCLA() {
Expand Down Expand Up @@ -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++
Expand All @@ -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))
}
}

}

0 comments on commit 154c88c

Please sign in to comment.