diff options
| author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2025-02-10 23:18:37 +0900 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2025-02-22 23:55:24 +0900 |
| commit | b93b7c4a91023c45ca8fc26e17215bb807d43eb5 (patch) | |
| tree | 688368849e16cdfc732cf91d610639c477f7aa53 /etc/git | |
| parent | fc3ae7052036d232e2ce9b69d2c28bd1157ce49e (diff) | |
etc: Update the commit-msg hook.
Update our copy to the latest version retrieved from
<https://gerrit.googlesource.com/gerrit/+/refs/heads/master/resources/com/google/gerrit/server/tools/root/hooks/commit-msg>.
This change contains an improved version which avoids creating duplicate
Change-Id git trailer when rebasing.
* etc/git/commit-msg: Update to latest version, taking care to preserve our changes.
Change-Id: Ie6ae6aa5e81cd4fce28a6be5cd68ca0a61cdebc0
Diffstat (limited to 'etc/git')
| -rwxr-xr-x | etc/git/commit-msg | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/etc/git/commit-msg b/etc/git/commit-msg index dfa07918bba..69bd1fcde18 100755 --- a/etc/git/commit-msg +++ b/etc/git/commit-msg | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | # From Gerrit Code Review 3.6.1 | 2 | # From Gerrit Code Review 3.11.1. |
| 3 | # | 3 | # |
| 4 | # Part of Gerrit Code Review (https://www.gerritcodereview.com/) | 4 | # Part of Gerrit Code Review (https://www.gerritcodereview.com/) |
| 5 | # | 5 | # |
| @@ -44,9 +44,20 @@ if test ! -f "$1" ; then | |||
| 44 | fi | 44 | fi |
| 45 | 45 | ||
| 46 | # Do not create a change id if requested | 46 | # Do not create a change id if requested |
| 47 | if test "false" = "$(git config --bool --get gerrit.createChangeId)" ; then | 47 | case "$(git config --get gerrit.createChangeId)" in |
| 48 | exit 0 | 48 | false) |
| 49 | fi | 49 | exit 0 |
| 50 | ;; | ||
| 51 | always) | ||
| 52 | ;; | ||
| 53 | *) | ||
| 54 | # Do not create a change id for squash/fixup commits. | ||
| 55 | if head -n1 "$1" | LC_ALL=C grep -q '^[a-z][a-z]*! '; then | ||
| 56 | exit 0 | ||
| 57 | fi | ||
| 58 | ;; | ||
| 59 | esac | ||
| 60 | |||
| 50 | 61 | ||
| 51 | if git rev-parse --verify HEAD >/dev/null 2>&1; then | 62 | if git rev-parse --verify HEAD >/dev/null 2>&1; then |
| 52 | refhash="$(git rev-parse HEAD)" | 63 | refhash="$(git rev-parse HEAD)" |
| @@ -57,9 +68,9 @@ fi | |||
| 57 | random=$({ git var GIT_COMMITTER_IDENT ; echo "$refhash" ; cat "$1"; } | git hash-object --stdin) | 68 | random=$({ git var GIT_COMMITTER_IDENT ; echo "$refhash" ; cat "$1"; } | git hash-object --stdin) |
| 58 | dest="$1.tmp.${random}" | 69 | dest="$1.tmp.${random}" |
| 59 | 70 | ||
| 60 | trap 'rm -f "${dest}"' EXIT | 71 | trap 'rm -f "$dest" "$dest-2"' EXIT |
| 61 | 72 | ||
| 62 | if ! git stripspace --strip-comments < "$1" > "${dest}" ; then | 73 | if ! cat "$1" | sed -e '/>8/q' | git stripspace --strip-comments > "${dest}" ; then |
| 63 | echo "cannot strip comments from $1" | 74 | echo "cannot strip comments from $1" |
| 64 | exit 1 | 75 | exit 1 |
| 65 | fi | 76 | fi |
| @@ -71,21 +82,39 @@ fi | |||
| 71 | 82 | ||
| 72 | reviewurl="$(git config --get gerrit.reviewUrl)" | 83 | reviewurl="$(git config --get gerrit.reviewUrl)" |
| 73 | if test -n "${reviewurl}" ; then | 84 | if test -n "${reviewurl}" ; then |
| 74 | if ! git interpret-trailers --parse < "$1" | grep -q '^Link:.*/id/I[0-9a-f]\{40\}$' ; then | 85 | token="Link" |
| 75 | if ! git interpret-trailers \ | 86 | value="${reviewurl%/}/id/I$random" |
| 76 | --trailer "Link: ${reviewurl%/}/id/I${random}" < "$1" > "${dest}" ; then | 87 | pattern=".*/id/I[0-9a-f]\{40\}" |
| 77 | echo "cannot insert link footer in $1" | ||
| 78 | exit 1 | ||
| 79 | fi | ||
| 80 | fi | ||
| 81 | else | 88 | else |
| 82 | # Avoid the --in-place option which only appeared in Git 2.8 | 89 | token="Change-Id" |
| 83 | # Avoid the --if-exists option which only appeared in Git 2.15 | 90 | value="I$random" |
| 84 | if ! git -c trailer.ifexists=doNothing interpret-trailers \ | 91 | pattern=".*" |
| 85 | --trailer "Change-Id: I${random}" < "$1" > "${dest}" ; then | 92 | fi |
| 86 | echo "cannot insert change-id line in $1" | 93 | |
| 87 | exit 1 | 94 | if git interpret-trailers --parse < "$1" | grep -q "^$token: $pattern$" ; then |
| 88 | fi | 95 | exit 0 |
| 96 | fi | ||
| 97 | |||
| 98 | # There must be a Signed-off-by trailer for the code below to work. Insert a | ||
| 99 | # sentinel at the end to make sure there is one. | ||
| 100 | # Avoid the --in-place option which only appeared in Git 2.8 | ||
| 101 | if ! git interpret-trailers \ | ||
| 102 | --trailer "Signed-off-by: SENTINEL" < "$1" > "$dest-2" ; then | ||
| 103 | echo "cannot insert Signed-off-by sentinel line in $1" | ||
| 104 | exit 1 | ||
| 105 | fi | ||
| 106 | |||
| 107 | # Make sure the trailer appears before any Signed-off-by trailers by inserting | ||
| 108 | # it as if it was a Signed-off-by trailer and then use sed to remove the | ||
| 109 | # Signed-off-by prefix and the Signed-off-by sentinel line. | ||
| 110 | # Avoid the --in-place option which only appeared in Git 2.8 | ||
| 111 | # Avoid the --where option which only appeared in Git 2.15 | ||
| 112 | if ! git -c trailer.where=before interpret-trailers \ | ||
| 113 | --trailer "Signed-off-by: $token: $value" < "$dest-2" | | ||
| 114 | sed -e "s/^Signed-off-by: \($token: \)/\1/" \ | ||
| 115 | -e "/^Signed-off-by: SENTINEL/d" > "$dest" ; then | ||
| 116 | echo "cannot insert $token line in $1" | ||
| 117 | exit 1 | ||
| 89 | fi | 118 | fi |
| 90 | 119 | ||
| 91 | if ! mv "${dest}" "$1" ; then | 120 | if ! mv "${dest}" "$1" ; then |
