Navigation Menu

Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
commit-msg: Don't create message with only Change-Id
Browse files Browse the repository at this point in the history
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 <sop@google.com>
  • Loading branch information
spearce committed Aug 25, 2009
1 parent 15f6579 commit c024912
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions 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/)
#
Expand All @@ -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
Expand All @@ -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 |
Expand Down

0 comments on commit c024912

Please sign in to comment.