mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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 <sop@google.com>
This commit is contained in:
parent
15f6579eb3
commit
c024912fb8
@ -1,5 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/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/)
|
# 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
|
# Check for, and add if missing, a unique Change-Id
|
||||||
#
|
#
|
||||||
add_ChangeId() {
|
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
|
then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
id=$(_gen_ChangeId)
|
id=$(_gen_ChangeId)
|
||||||
out="$MSG.new"
|
out="$MSG.OUT"
|
||||||
ftt="$MSG.footers"
|
ftt="$MSG.FTT"
|
||||||
sed -e '2,${
|
sed -e '2,${
|
||||||
/^[A-Za-z][A-Za-z0-9-]*: /,$d
|
/^[A-Za-z][A-Za-z0-9-]*: /,$d
|
||||||
}' <"$MSG" >"$out"
|
}' <"$MSG" >"$out"
|
||||||
sed -ne '2,${
|
sed -ne '2,${
|
||||||
/^[A-Za-z][A-Za-z0-9-]*: /,$p
|
/^[A-Za-z][A-Za-z0-9-]*: /,$p
|
||||||
}' <"$MSG" >"$ftt"
|
}' <"$MSG" >"$ftt"
|
||||||
if ! [ -s "$ftt" ]
|
if ! test -s "$ftt"
|
||||||
then
|
then
|
||||||
echo >>"$out"
|
echo >>"$out"
|
||||||
fi
|
fi
|
||||||
@ -55,7 +68,7 @@ _gen_ChangeIdInput() {
|
|||||||
echo "author $(git var GIT_AUTHOR_IDENT)"
|
echo "author $(git var GIT_AUTHOR_IDENT)"
|
||||||
echo "committer $(git var GIT_COMMITTER_IDENT)"
|
echo "committer $(git var GIT_COMMITTER_IDENT)"
|
||||||
echo
|
echo
|
||||||
cat "$MSG"
|
printf '%s' "$clean_message"
|
||||||
}
|
}
|
||||||
_gen_ChangeId() {
|
_gen_ChangeId() {
|
||||||
_gen_ChangeIdInput |
|
_gen_ChangeIdInput |
|
||||||
|
Loading…
Reference in New Issue
Block a user