From 23ef425564bf52bea4724240f32bc6da1a155d42 Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Sat, 4 Mar 2017 12:38:36 -0800 Subject: [PATCH] devcam/hook: handle 'verbose' commits See https://github.com/golang/go/issues/16376, and the related https://go-review.googlesource.com/#/c/25342/. Prior to this change, `git commit -v` would result in a nonsensical commit message. Change-Id: Ib11de27488b01fccff07b9385f7fa988bc6fe165 --- dev/devcam/hook.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dev/devcam/hook.go b/dev/devcam/hook.go index 8b686bbbf..12b49d335 100644 --- a/dev/devcam/hook.go +++ b/dev/devcam/hook.go @@ -41,6 +41,8 @@ var hookFiles = []string{ "commit-msg", } +var ignoreBelow = []byte("\n# ------------------------ >8 ------------------------\n") + func (c *hookCmd) installHook() error { root, err := repoRoot() if err != nil { @@ -131,8 +133,12 @@ func (c *hookCmd) RunCommand(args []string) error { return nil } -// stripComments strips lines that begin with "#". +// stripComments strips lines that begin with "#" and removes the diff section +// contained in verbose commits. func stripComments(in []byte) []byte { + if i := bytes.Index(in, ignoreBelow); i >= 0 { + in = in[:i+1] + } return regexp.MustCompile(`(?m)^#.*\n`).ReplaceAll(in, nil) }