diff options
Diffstat (limited to 'hooks/commit-msg')
-rwxr-xr-x | hooks/commit-msg | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/hooks/commit-msg b/hooks/commit-msg index 8c6476fa..112df63f 100755 --- a/hooks/commit-msg +++ b/hooks/commit-msg | |||
@@ -1,5 +1,5 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | # From Gerrit Code Review 3.6.1 c67916dbdc07555c44e32a68f92ffc484b9b34f0 | 2 | # From Gerrit Code Review 3.10.0 d5403dbf335ba7d48977fc95170c3f7027c34659 |
3 | # | 3 | # |
4 | # Part of Gerrit Code Review (https://www.gerritcodereview.com/) | 4 | # Part of Gerrit Code Review (https://www.gerritcodereview.com/) |
5 | # | 5 | # |
@@ -31,14 +31,21 @@ if test ! -f "$1" ; then | |||
31 | fi | 31 | fi |
32 | 32 | ||
33 | # Do not create a change id if requested | 33 | # Do not create a change id if requested |
34 | if test "false" = "$(git config --bool --get gerrit.createChangeId)" ; then | 34 | create_setting=$(git config --get gerrit.createChangeId) |
35 | exit 0 | 35 | case "$create_setting" in |
36 | fi | 36 | false) |
37 | exit 0 | ||
38 | ;; | ||
39 | always) | ||
40 | ;; | ||
41 | *) | ||
42 | # Do not create a change id for squash/fixup commits. | ||
43 | if head -n1 "$1" | LC_ALL=C grep -q '^[a-z][a-z]*! '; then | ||
44 | exit 0 | ||
45 | fi | ||
46 | ;; | ||
47 | esac | ||
37 | 48 | ||
38 | # Do not create a change id for squash commits. | ||
39 | if head -n1 "$1" | grep -q '^squash! '; then | ||
40 | exit 0 | ||
41 | fi | ||
42 | 49 | ||
43 | if git rev-parse --verify HEAD >/dev/null 2>&1; then | 50 | if git rev-parse --verify HEAD >/dev/null 2>&1; then |
44 | refhash="$(git rev-parse HEAD)" | 51 | refhash="$(git rev-parse HEAD)" |
@@ -51,7 +58,7 @@ dest="$1.tmp.${random}" | |||
51 | 58 | ||
52 | trap 'rm -f "$dest" "$dest-2"' EXIT | 59 | trap 'rm -f "$dest" "$dest-2"' EXIT |
53 | 60 | ||
54 | if ! git stripspace --strip-comments < "$1" > "${dest}" ; then | 61 | if ! cat "$1" | sed -e '/>8/q' | git stripspace --strip-comments > "${dest}" ; then |
55 | echo "cannot strip comments from $1" | 62 | echo "cannot strip comments from $1" |
56 | exit 1 | 63 | exit 1 |
57 | fi | 64 | fi |
@@ -65,7 +72,7 @@ reviewurl="$(git config --get gerrit.reviewUrl)" | |||
65 | if test -n "${reviewurl}" ; then | 72 | if test -n "${reviewurl}" ; then |
66 | token="Link" | 73 | token="Link" |
67 | value="${reviewurl%/}/id/I$random" | 74 | value="${reviewurl%/}/id/I$random" |
68 | pattern=".*/id/I[0-9a-f]\{40\}$" | 75 | pattern=".*/id/I[0-9a-f]\{40\}" |
69 | else | 76 | else |
70 | token="Change-Id" | 77 | token="Change-Id" |
71 | value="I$random" | 78 | value="I$random" |
@@ -92,7 +99,7 @@ fi | |||
92 | # Avoid the --where option which only appeared in Git 2.15 | 99 | # Avoid the --where option which only appeared in Git 2.15 |
93 | if ! git -c trailer.where=before interpret-trailers \ | 100 | if ! git -c trailer.where=before interpret-trailers \ |
94 | --trailer "Signed-off-by: $token: $value" < "$dest-2" | | 101 | --trailer "Signed-off-by: $token: $value" < "$dest-2" | |
95 | sed -re "s/^Signed-off-by: ($token: )/\1/" \ | 102 | sed -e "s/^Signed-off-by: \($token: \)/\1/" \ |
96 | -e "/^Signed-off-by: SENTINEL/d" > "$dest" ; then | 103 | -e "/^Signed-off-by: SENTINEL/d" > "$dest" ; then |
97 | echo "cannot insert $token line in $1" | 104 | echo "cannot insert $token line in $1" |
98 | exit 1 | 105 | exit 1 |