git-codereview: do not install hooks for help and invalid commands
Fixes golang/go#34320
Change-Id: I53348a027d1a33d1614d2bad32c75eaca52fac8a
Reviewed-on: https://go-review.googlesource.com/c/review/+/195897
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
diff --git a/git-codereview/review.go b/git-codereview/review.go
index 147733f..a4ea988 100644
--- a/git-codereview/review.go
+++ b/git-codereview/review.go
@@ -137,9 +137,37 @@
}
command, args := os.Args[1], os.Args[2:]
- if command == "help" {
+ var cmd func([]string)
+ switch command {
+ case "help":
fmt.Fprintf(stdout(), help, os.Args[0])
- return
+ return // avoid installing hooks.
+ case "hooks": // in case hooks weren't installed.
+ installHook(args)
+ return // avoid invoking installHook twice.
+ case "branchpoint":
+ cmd = cmdBranchpoint
+ case "change":
+ cmd = cmdChange
+ case "gofmt":
+ cmd = cmdGofmt
+ case "hook-invoke":
+ cmd = cmdHookInvoke
+ case "mail", "m":
+ cmd = cmdMail
+ case "pending":
+ cmd = cmdPending
+ case "rebase-work":
+ cmd = cmdRebaseWork
+ case "submit":
+ cmd = cmdSubmit
+ case "sync":
+ cmd = cmdSync
+ case "test-loadAuth": // for testing only.
+ cmd = func([]string) { loadAuth() }
+ default:
+ flags.Usage()
+ return // avoid installing hooks.
}
// Install hooks automatically, but only if this is a Gerrit repo.
@@ -157,32 +185,7 @@
installHook(hookArgs)
}
- switch command {
- case "branchpoint":
- cmdBranchpoint(args)
- case "change":
- cmdChange(args)
- case "gofmt":
- cmdGofmt(args)
- case "hook-invoke":
- cmdHookInvoke(args)
- case "hooks":
- installHook(args) // in case above was bypassed
- case "mail", "m":
- cmdMail(args)
- case "pending":
- cmdPending(args)
- case "rebase-work":
- cmdRebaseWork(args)
- case "submit":
- cmdSubmit(args)
- case "sync":
- cmdSync(args)
- case "test-loadAuth": // for testing only
- loadAuth()
- default:
- flags.Usage()
- }
+ cmd(args)
}
func expectZeroArgs(args []string, command string) {