summaryrefslogtreecommitdiffstats
path: root/hooks/commit-msg
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2023-11-30 12:21:17 +0200
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-12-04 17:43:33 +0000
commita50c4e3bc06ca590283d23fff9922628ac69f696 (patch)
treee0fca64c483eb826cda4cc8d878a4075f569aede /hooks/commit-msg
parent0dd0a830b055e177a713bbc81fc7ecdda1605643 (diff)
downloadgit-repo-a50c4e3bc06ca590283d23fff9922628ac69f696.tar.gz
Update commit-msg hook
Modified in https://gerrit-review.googlesource.com/c/gerrit/+/394841. Change-Id: I381e48fbdb92b33454219dd9d945a1756e551a77 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/395577 Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Orgad Shaneh <orgads@gmail.com> Commit-Queue: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Ernesto Rodriguez <guez30nesto@gmail.com>
Diffstat (limited to 'hooks/commit-msg')
-rwxr-xr-xhooks/commit-msg29
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
31fi 31fi
32 32
33# Do not create a change id if requested 33# Do not create a change id if requested
34if test "false" = "$(git config --bool --get gerrit.createChangeId)" ; then 34create_setting=$(git config --get gerrit.createChangeId)
35 exit 0 35case "$create_setting" in
36fi 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 ;;
47esac
37 48
38# Do not create a change id for squash commits.
39if head -n1 "$1" | grep -q '^squash! '; then
40 exit 0
41fi
42 49
43if git rev-parse --verify HEAD >/dev/null 2>&1; then 50if 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
52trap 'rm -f "$dest" "$dest-2"' EXIT 59trap 'rm -f "$dest" "$dest-2"' EXIT
53 60
54if ! git stripspace --strip-comments < "$1" > "${dest}" ; then 61if ! 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
57fi 64fi
@@ -65,7 +72,7 @@ reviewurl="$(git config --get gerrit.reviewUrl)"
65if test -n "${reviewurl}" ; then 72if 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\}"
69else 76else
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
93if ! git -c trailer.where=before interpret-trailers \ 100if ! 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