diff options
| author | Shawn O. Pearce <sop@google.com> | 2009-08-25 11:38:11 -0700 |
|---|---|---|
| committer | Shawn O. Pearce <sop@google.com> | 2009-08-25 12:03:55 -0700 |
| commit | c024912fb8227db2a1c9232add3b1e7256af170a (patch) | |
| tree | 2289607dddee108d7796feb25ad2f7e00be224df | |
| parent | 15f6579eb3a2f3cb0e432ed39ac39d8678786161 (diff) | |
| download | git-repo-c024912fb8227db2a1c9232add3b1e7256af170a.tar.gz | |
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>
| -rwxr-xr-x | hooks/commit-msg | 25 |
1 files 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 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | # From Gerrit Code Review v2.0.18-100-g98fc90a | 2 | # From Gerrit Code Review v2.0.19.1-4-g21d307b |
| 3 | # | 3 | # |
| 4 | # Part of Gerrit Code Review (http://code.google.com/p/gerrit/) | 4 | # Part of Gerrit Code Review (http://code.google.com/p/gerrit/) |
| 5 | # | 5 | # |
| @@ -23,21 +23,34 @@ MSG="$1" | |||
| 23 | # Check for, and add if missing, a unique Change-Id | 23 | # Check for, and add if missing, a unique Change-Id |
| 24 | # | 24 | # |
| 25 | add_ChangeId() { | 25 | add_ChangeId() { |
| 26 | if grep '^Change-Id: ' "$MSG" >/dev/null | 26 | clean_message=$(sed -e ' |
| 27 | /^diff --git a\/.*/{ | ||
| 28 | s/// | ||
| 29 | q | ||
| 30 | } | ||
| 31 | /^Signed-off-by:/d | ||
| 32 | /^#/d | ||
| 33 | ' "$MSG" | git stripspace) | ||
| 34 | if test -z "$clean_message" | ||
| 35 | then | ||
| 36 | return | ||
| 37 | fi | ||
| 38 | |||
| 39 | if grep -i '^Change-Id:' "$MSG" >/dev/null | ||
| 27 | then | 40 | then |
| 28 | return | 41 | return |
| 29 | fi | 42 | fi |
| 30 | 43 | ||
| 31 | id=$(_gen_ChangeId) | 44 | id=$(_gen_ChangeId) |
| 32 | out="$MSG.new" | 45 | out="$MSG.OUT" |
| 33 | ftt="$MSG.footers" | 46 | ftt="$MSG.FTT" |
| 34 | sed -e '2,${ | 47 | sed -e '2,${ |
| 35 | /^[A-Za-z][A-Za-z0-9-]*: /,$d | 48 | /^[A-Za-z][A-Za-z0-9-]*: /,$d |
| 36 | }' <"$MSG" >"$out" | 49 | }' <"$MSG" >"$out" |
| 37 | sed -ne '2,${ | 50 | sed -ne '2,${ |
| 38 | /^[A-Za-z][A-Za-z0-9-]*: /,$p | 51 | /^[A-Za-z][A-Za-z0-9-]*: /,$p |
| 39 | }' <"$MSG" >"$ftt" | 52 | }' <"$MSG" >"$ftt" |
| 40 | if ! [ -s "$ftt" ] | 53 | if ! test -s "$ftt" |
| 41 | then | 54 | then |
| 42 | echo >>"$out" | 55 | echo >>"$out" |
| 43 | fi | 56 | fi |
| @@ -55,7 +68,7 @@ _gen_ChangeIdInput() { | |||
| 55 | echo "author $(git var GIT_AUTHOR_IDENT)" | 68 | echo "author $(git var GIT_AUTHOR_IDENT)" |
| 56 | echo "committer $(git var GIT_COMMITTER_IDENT)" | 69 | echo "committer $(git var GIT_COMMITTER_IDENT)" |
| 57 | echo | 70 | echo |
| 58 | cat "$MSG" | 71 | printf '%s' "$clean_message" |
| 59 | } | 72 | } |
| 60 | _gen_ChangeId() { | 73 | _gen_ChangeId() { |
| 61 | _gen_ChangeIdInput | | 74 | _gen_ChangeIdInput | |
