From c024912fb8227db2a1c9232add3b1e7256af170a Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 25 Aug 2009 11:38:11 -0700 Subject: [PATCH] commit-msg: Don't create message with only Change-Id If a user aborts a commit, the commit-msg hook is still called, but with an empty file. We need to leave the empty file alone. Change-Id: I13766135dac267823cb08ab76f67d2000ba2d1ce Signed-off-by: Shawn O. Pearce --- hooks/commit-msg | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/hooks/commit-msg b/hooks/commit-msg index 5b1fe3ae..fd76c074 100755 --- a/hooks/commit-msg +++ b/hooks/commit-msg @@ -1,5 +1,5 @@ #!/bin/sh -# From Gerrit Code Review v2.0.18-100-g98fc90a +# From Gerrit Code Review v2.0.19.1-4-g21d307b # # Part of Gerrit Code Review (http://code.google.com/p/gerrit/) # @@ -23,21 +23,34 @@ MSG="$1" # Check for, and add if missing, a unique Change-Id # add_ChangeId() { - if grep '^Change-Id: ' "$MSG" >/dev/null + clean_message=$(sed -e ' + /^diff --git a\/.*/{ + s/// + q + } + /^Signed-off-by:/d + /^#/d + ' "$MSG" | git stripspace) + if test -z "$clean_message" + then + return + fi + + if grep -i '^Change-Id:' "$MSG" >/dev/null then return fi id=$(_gen_ChangeId) - out="$MSG.new" - ftt="$MSG.footers" + out="$MSG.OUT" + ftt="$MSG.FTT" sed -e '2,${ /^[A-Za-z][A-Za-z0-9-]*: /,$d }' <"$MSG" >"$out" sed -ne '2,${ /^[A-Za-z][A-Za-z0-9-]*: /,$p }' <"$MSG" >"$ftt" - if ! [ -s "$ftt" ] + if ! test -s "$ftt" then echo >>"$out" fi @@ -55,7 +68,7 @@ _gen_ChangeIdInput() { echo "author $(git var GIT_AUTHOR_IDENT)" echo "committer $(git var GIT_COMMITTER_IDENT)" echo - cat "$MSG" + printf '%s' "$clean_message" } _gen_ChangeId() { _gen_ChangeIdInput |