aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2016-08-01 08:42:20 +0200
committerJosh Bleecher Snyder <josharian@gmail.com>2016-08-01 16:56:21 +0000
commit748a6d4e5a0ffe1e2a92e4ae5dcd6ee67a4b1b43 (patch)
treed4a80f034d79cdf3a4df4e46a83f1bb18f5bfe9b
parentc272006fd6c67460073f6630cb366d1e62f66721 (diff)
downloadgo-x-review-748a6d4e5a0ffe1e2a92e4ae5dcd6ee67a4b1b43.tar.xz
git-codereview: fix commitmsg hook when verbose
If the commit message is verbose it shows the diff being committed. This can be shown by either `git commit --verbose` or setting the following in your git config: [commit] verbose = true The diff is uncomented and shown after a "everything below will be removed" comment section. Identify it and do remove everything under it, as otherwise the diff would get mixed up with the commit message. Fixes golang/go#16376. Change-Id: Ia69aeaf36a1c8471da423a142fb233168d455a5d Reviewed-on: https://go-review.googlesource.com/25342 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
-rw-r--r--git-codereview/hook.go10
-rw-r--r--git-codereview/hook_test.go5
2 files changed, 14 insertions, 1 deletions
diff --git a/git-codereview/hook.go b/git-codereview/hook.go
index 63e8fd7..0e8f075 100644
--- a/git-codereview/hook.go
+++ b/git-codereview/hook.go
@@ -212,6 +212,8 @@ func hookCommitMsg(args []string) {
var (
fixupBang = []byte("fixup!")
squashBang = []byte("squash!")
+
+ ignoreBelow = []byte("\n# ------------------------ >8 ------------------------\n")
)
// isFixup reports whether text is a Git fixup! or squash! commit,
@@ -220,8 +222,14 @@ func isFixup(text []byte) bool {
return bytes.HasPrefix(text, fixupBang) || bytes.HasPrefix(text, squashBang)
}
-// stripComments strips lines that begin with "#".
+// stripComments strips lines that begin with "#" and removes the
+// "everything below will be removed" section containing the diff when
+// using commit --verbose.
func stripComments(in []byte) []byte {
+ // Issue 16376
+ if i := bytes.Index(in, ignoreBelow); i >= 0 {
+ in = in[:i+1]
+ }
return regexp.MustCompile(`(?m)^#.*\n`).ReplaceAll(in, nil)
}
diff --git a/git-codereview/hook_test.go b/git-codereview/hook_test.go
index ca1fff3..0d171c0 100644
--- a/git-codereview/hook_test.go
+++ b/git-codereview/hook_test.go
@@ -66,6 +66,11 @@ func TestHookCommitMsg(t *testing.T) {
{in: "all: gofmt\nahhh", want: "all: gofmt\n\nahhh"},
{in: "all: gofmt\n\nahhh", want: "all: gofmt\n\nahhh"},
{in: "all: gofmt\n\n\nahhh", want: "all: gofmt\n\n\nahhh"},
+ // Issue 16376
+ {
+ in: "all: gofmt\n# ------------------------ >8 ------------------------\ndiff",
+ want: "all: gofmt\n",
+ },
}
for _, tt := range rewrites {
write(t, gt.client+"/in.txt", tt.in)