diff options
| author | Maxim Cournoyer <maxim@guixotic.coop> | 2025-08-01 14:46:58 +0900 |
|---|---|---|
| committer | Maxim Cournoyer <maxim@guixotic.coop> | 2026-06-12 18:19:18 +0900 |
| commit | 81a7856dd893aab74ff5562aa6d90aa7ec70c05f (patch) | |
| tree | 7765c72c7b1e115d9e2d404bc4fcf54d4bea793c /etc/git/commit-msg | |
| parent | e6566646240708a8e65e69a9ba6570f67bb7e986 (diff) | |
Revert "build: Add a commit-msg hook that embeds Change-Id in commit messages."
This reverts commit 8005e09b261d65bf0f7469cd8e89423c1c1db820 and follow-ups.
This was added 2 years ago to be able to trace commits between the git
repository and the guix-patches tracker, and to implement a solution to
automatically close merged commits (which has not materialized).
Since we have now migrated to Codeberg, the cross-referencing between reviewed
commits (pull requests) and the actual commits merged can be done in the
Codeberg UI (via the 'manually merged' option), and Codeberg also supports
closing a bug via the "Fixes: #NNN" git trailer, and as a convention we can
add a "Merges: !NNN" git trailer in a commit closing a PR (the actual closing
is not yet implemented by Forgejo), which mostly obsoletes the purpose of the
Change-Id git trailer.
Diffstat (limited to 'etc/git/commit-msg')
| -rwxr-xr-x | etc/git/commit-msg | 124 |
1 files changed, 0 insertions, 124 deletions
diff --git a/etc/git/commit-msg b/etc/git/commit-msg deleted file mode 100755 index 7175c158123..00000000000 --- a/etc/git/commit-msg +++ /dev/null | |||
| @@ -1,124 +0,0 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # Part of Gerrit Code Review (https://www.gerritcodereview.com/) | ||
| 4 | # | ||
| 5 | # Copyright (C) 2009 The Android Open Source Project | ||
| 6 | # | ||
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 8 | # you may not use this file except in compliance with the License. | ||
| 9 | # You may obtain a copy of the License at | ||
| 10 | # | ||
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 12 | # | ||
| 13 | # Unless required by applicable law or agreed to in writing, software | ||
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 16 | # See the License for the specific language governing permissions and | ||
| 17 | # limitations under the License. | ||
| 18 | |||
| 19 | ### Guix modifications start | ||
| 20 | COMMIT_MSG_MAGIC=VGhpcyBpcyB0aGUgY29tbWl0LW1zZyBob29rIG9mIEd1aXg= | ||
| 21 | top=$(git rev-parse --show-toplevel) | ||
| 22 | if test -d "$top/.git/hooks/commit-msg.d/"; then | ||
| 23 | for msg_hook in "$top/.git/hooks/commit-msg.d/"*; do | ||
| 24 | if ! sh "$msg_hook"; then | ||
| 25 | echo "error while running $msg_hook" | ||
| 26 | exit 1 | ||
| 27 | fi | ||
| 28 | done | ||
| 29 | fi | ||
| 30 | ### Guix modifications end | ||
| 31 | |||
| 32 | set -u | ||
| 33 | |||
| 34 | # avoid [[ which is not POSIX sh. | ||
| 35 | if test "$#" != 1 ; then | ||
| 36 | echo "$0 requires an argument." | ||
| 37 | exit 1 | ||
| 38 | fi | ||
| 39 | |||
| 40 | if test ! -f "$1" ; then | ||
| 41 | echo "file does not exist: $1" | ||
| 42 | exit 1 | ||
| 43 | fi | ||
| 44 | |||
| 45 | # Do not create a change id if requested | ||
| 46 | case "$(git config --get gerrit.createChangeId)" in | ||
| 47 | false) | ||
| 48 | exit 0 | ||
| 49 | ;; | ||
| 50 | always) | ||
| 51 | ;; | ||
| 52 | *) | ||
| 53 | # Do not create a change id for squash/fixup commits. | ||
| 54 | if head -n1 "$1" | LC_ALL=C grep -q '^[a-z][a-z]*! '; then | ||
| 55 | exit 0 | ||
| 56 | fi | ||
| 57 | ;; | ||
| 58 | esac | ||
| 59 | |||
| 60 | |||
| 61 | if git rev-parse --verify HEAD >/dev/null 2>&1; then | ||
| 62 | refhash="$(git rev-parse HEAD)" | ||
| 63 | else | ||
| 64 | refhash="$(git hash-object -t tree /dev/null)" | ||
| 65 | fi | ||
| 66 | |||
| 67 | random=$({ git var GIT_COMMITTER_IDENT ; echo "$refhash" ; cat "$1"; } | git hash-object --stdin) | ||
| 68 | dest="$1.tmp.${random}" | ||
| 69 | |||
| 70 | trap 'rm -f "$dest" "$dest-2"' EXIT | ||
| 71 | |||
| 72 | if ! sed -e '/>8/q' "$1" | git stripspace --strip-comments > "${dest}" ; then | ||
| 73 | echo "cannot strip comments from $1" | ||
| 74 | exit 1 | ||
| 75 | fi | ||
| 76 | |||
| 77 | if test ! -s "${dest}" ; then | ||
| 78 | echo "file is empty: $1" | ||
| 79 | exit 1 | ||
| 80 | fi | ||
| 81 | |||
| 82 | reviewurl="$(git config --get gerrit.reviewUrl)" | ||
| 83 | if test -n "${reviewurl}" ; then | ||
| 84 | token="Link" | ||
| 85 | value="${reviewurl%/}/id/I$random" | ||
| 86 | pattern=".*/id/I[0-9a-f]\{40\}" | ||
| 87 | else | ||
| 88 | token="Change-Id" | ||
| 89 | value="I$random" | ||
| 90 | pattern=".*" | ||
| 91 | fi | ||
| 92 | |||
| 93 | if git interpret-trailers --no-divider --parse < "$1" | grep -q "^$token: $pattern$" ; then | ||
| 94 | exit 0 | ||
| 95 | fi | ||
| 96 | |||
| 97 | # There must be a Signed-off-by trailer for the code below to work. Insert a | ||
| 98 | # sentinel at the end to make sure there is one. | ||
| 99 | # Avoid the --in-place option which only appeared in Git 2.8 | ||
| 100 | if ! git interpret-trailers \ | ||
| 101 | --no-divider \ | ||
| 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 | --no-divider \ | ||
| 114 | --trailer "Signed-off-by: $token: $value" < "$dest-2" | | ||
| 115 | sed -e "s/^Signed-off-by: \($token: \)/\1/" \ | ||
| 116 | -e "/^Signed-off-by: SENTINEL/d" > "$dest" ; then | ||
| 117 | echo "cannot insert $token line in $1" | ||
| 118 | exit 1 | ||
| 119 | fi | ||
| 120 | |||
| 121 | if ! mv "${dest}" "$1" ; then | ||
| 122 | echo "cannot mv ${dest} to $1" | ||
| 123 | exit 1 | ||
| 124 | fi | ||
