aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2016-06-10 07:12:36 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2016-06-14 01:16:19 +0000
commit9f7b28f5a3254d248b82a181bef7195f722ff762 (patch)
tree1097768423f7673660a49de8ef78346007d32dc2
parent4a86a651c993b954a45140a6ae77b4510674faaf (diff)
downloadgo-x-review-9f7b28f5a3254d248b82a181bef7195f722ff762.tar.xz
git-codereview: pass args to installHook
This enables passing -v to 'git codereview hooks' to see what commands are being run. It also means that automatic installation of hooks should respect -n. Change-Id: I812685b43e9ea678641f64b2182b957342a4e43c Reviewed-on: https://go-review.googlesource.com/24002 Reviewed-by: Andrew Gerrand <adg@golang.org>
-rw-r--r--git-codereview/change.go1
-rw-r--r--git-codereview/hook.go3
-rw-r--r--git-codereview/review.go14
3 files changed, 14 insertions, 4 deletions
diff --git a/git-codereview/change.go b/git-codereview/change.go
index 0d47857..fac0f94 100644
--- a/git-codereview/change.go
+++ b/git-codereview/change.go
@@ -21,7 +21,6 @@ func cmdChange(args []string) {
if len(flags.Args()) > 1 {
fmt.Fprintf(stderr(), "Usage: %s change %s [branch]\n", os.Args[0], globalFlags)
os.Exit(2)
-
}
// Checkout or create branch, if specified.
diff --git a/git-codereview/hook.go b/git-codereview/hook.go
index f10c070..04fa87c 100644
--- a/git-codereview/hook.go
+++ b/git-codereview/hook.go
@@ -21,7 +21,8 @@ var hookFiles = []string{
"pre-commit",
}
-func installHook() {
+func installHook(args []string) {
+ flags.Parse(args)
hooksDir := gitPath("hooks")
for _, hookFile := range hookFiles {
filename := filepath.Join(hooksDir, hookFile)
diff --git a/git-codereview/review.go b/git-codereview/review.go
index 779b77c..c83a95b 100644
--- a/git-codereview/review.go
+++ b/git-codereview/review.go
@@ -127,7 +127,17 @@ func main() {
// Install hooks automatically, but only if this is a Gerrit repo.
if haveGerrit() {
- installHook()
+ // Don't pass installHook args directly,
+ // since args might contain args meant for other commands.
+ // Filter down to just global flags.
+ var hookArgs []string
+ for _, arg := range args {
+ switch arg {
+ case "-n", "-v":
+ hookArgs = append(hookArgs, arg)
+ }
+ }
+ installHook(hookArgs)
}
switch command {
@@ -140,7 +150,7 @@ func main() {
case "hook-invoke":
cmdHookInvoke(args)
case "hooks":
- installHook() // in case above was bypassed
+ installHook(args) // in case above was bypassed
case "mail", "m":
cmdMail(args)
case "pending":