From a50c4e3bc06ca590283d23fff9922628ac69f696 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Thu, 30 Nov 2023 12:21:17 +0200 Subject: [PATCH] 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 Tested-by: Orgad Shaneh Commit-Queue: Orgad Shaneh Reviewed-by: Ernesto Rodriguez --- hooks/commit-msg | 29 ++++++++++++++++++----------- 1 file 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 @@ #!/bin/sh -# From Gerrit Code Review 3.6.1 c67916dbdc07555c44e32a68f92ffc484b9b34f0 +# From Gerrit Code Review 3.10.0 d5403dbf335ba7d48977fc95170c3f7027c34659 # # Part of Gerrit Code Review (https://www.gerritcodereview.com/) # @@ -31,14 +31,21 @@ if test ! -f "$1" ; then fi # Do not create a change id if requested -if test "false" = "$(git config --bool --get gerrit.createChangeId)" ; then - exit 0 -fi +create_setting=$(git config --get gerrit.createChangeId) +case "$create_setting" in + false) + exit 0 + ;; + always) + ;; + *) + # Do not create a change id for squash/fixup commits. + if head -n1 "$1" | LC_ALL=C grep -q '^[a-z][a-z]*! '; then + exit 0 + fi + ;; +esac -# Do not create a change id for squash commits. -if head -n1 "$1" | grep -q '^squash! '; then - exit 0 -fi if git rev-parse --verify HEAD >/dev/null 2>&1; then refhash="$(git rev-parse HEAD)" @@ -51,7 +58,7 @@ dest="$1.tmp.${random}" trap 'rm -f "$dest" "$dest-2"' EXIT -if ! git stripspace --strip-comments < "$1" > "${dest}" ; then +if ! cat "$1" | sed -e '/>8/q' | git stripspace --strip-comments > "${dest}" ; then echo "cannot strip comments from $1" exit 1 fi @@ -65,7 +72,7 @@ reviewurl="$(git config --get gerrit.reviewUrl)" if test -n "${reviewurl}" ; then token="Link" value="${reviewurl%/}/id/I$random" - pattern=".*/id/I[0-9a-f]\{40\}$" + pattern=".*/id/I[0-9a-f]\{40\}" else token="Change-Id" value="I$random" @@ -92,7 +99,7 @@ fi # Avoid the --where option which only appeared in Git 2.15 if ! git -c trailer.where=before interpret-trailers \ --trailer "Signed-off-by: $token: $value" < "$dest-2" | - sed -re "s/^Signed-off-by: ($token: )/\1/" \ + sed -e "s/^Signed-off-by: \($token: \)/\1/" \ -e "/^Signed-off-by: SENTINEL/d" > "$dest" ; then echo "cannot insert $token line in $1" exit 1