summaryrefslogtreecommitdiff
path: root/etc/git/commit-msg
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2023-10-08 12:18:13 -0400
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2023-10-22 16:09:04 -0400
commit8005e09b261d65bf0f7469cd8e89423c1c1db820 (patch)
treef98b345a8de8dfeb831e6d20fd82f4890936d825 /etc/git/commit-msg
parentfaeebdc37e9137d62e11175e83988f77496a6641 (diff)
build: Add a commit-msg hook that embeds Change-Id in commit messages.
Partially implements <https://issues.guix.gnu.org/66027>. This will make it possible to track a merged commit back to its original posting on the mailing list, and open the door to new opportunities such as closing fully merged series automatically. * Makefile.am (COMMIT_MSG_MAGIC): New variable. (.git/hooks/commit-msg): New target. * etc/git/commit-msg: New file. * doc/contributing.texi (Configuring Git): Document Change-Id. Series-changes: 3 - Clarify documentation text, as suggested by Simon Change-Id: Ia92fa958eae600fdd4e180bad494c85db8bb4dd6 Reviewed-by: Simon Tournier <zimon.toutoune@gmail.com>
Diffstat (limited to 'etc/git/commit-msg')
-rwxr-xr-xetc/git/commit-msg94
1 files changed, 94 insertions, 0 deletions
diff --git a/etc/git/commit-msg b/etc/git/commit-msg
new file mode 100755
index 00000000000..dfa07918bba
--- /dev/null
+++ b/etc/git/commit-msg
@@ -0,0 +1,94 @@
1#!/bin/sh
2# From Gerrit Code Review 3.6.1
3#
4# Part of Gerrit Code Review (https://www.gerritcodereview.com/)
5#
6# Copyright (C) 2009 The Android Open Source Project
7#
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19
20### Guix modifications start
21COMMIT_MSG_MAGIC=VGhpcyBpcyB0aGUgY29tbWl0LW1zZyBob29rIG9mIEd1aXg=
22top=$(git rev-parse --show-toplevel)
23if test -d "$top/.git/hooks/commit-msg.d/"; then
24 for msg_hook in "$top/.git/hooks/commit-msg.d/"*; do
25 if ! sh "$msg_hook"; then
26 echo "error while running $msg_hook"
27 exit 1
28 fi
29 done
30fi
31### Guix modifications end
32
33set -u
34
35# avoid [[ which is not POSIX sh.
36if test "$#" != 1 ; then
37 echo "$0 requires an argument."
38 exit 1
39fi
40
41if test ! -f "$1" ; then
42 echo "file does not exist: $1"
43 exit 1
44fi
45
46# Do not create a change id if requested
47if test "false" = "$(git config --bool --get gerrit.createChangeId)" ; then
48 exit 0
49fi
50
51if git rev-parse --verify HEAD >/dev/null 2>&1; then
52 refhash="$(git rev-parse HEAD)"
53else
54 refhash="$(git hash-object -t tree /dev/null)"
55fi
56
57random=$({ git var GIT_COMMITTER_IDENT ; echo "$refhash" ; cat "$1"; } | git hash-object --stdin)
58dest="$1.tmp.${random}"
59
60trap 'rm -f "${dest}"' EXIT
61
62if ! git stripspace --strip-comments < "$1" > "${dest}" ; then
63 echo "cannot strip comments from $1"
64 exit 1
65fi
66
67if test ! -s "${dest}" ; then
68 echo "file is empty: $1"
69 exit 1
70fi
71
72reviewurl="$(git config --get gerrit.reviewUrl)"
73if test -n "${reviewurl}" ; then
74 if ! git interpret-trailers --parse < "$1" | grep -q '^Link:.*/id/I[0-9a-f]\{40\}$' ; then
75 if ! git interpret-trailers \
76 --trailer "Link: ${reviewurl%/}/id/I${random}" < "$1" > "${dest}" ; then
77 echo "cannot insert link footer in $1"
78 exit 1
79 fi
80 fi
81else
82 # Avoid the --in-place option which only appeared in Git 2.8
83 # Avoid the --if-exists option which only appeared in Git 2.15
84 if ! git -c trailer.ifexists=doNothing interpret-trailers \
85 --trailer "Change-Id: I${random}" < "$1" > "${dest}" ; then
86 echo "cannot insert change-id line in $1"
87 exit 1
88 fi
89fi
90
91if ! mv "${dest}" "$1" ; then
92 echo "cannot mv ${dest} to $1"
93 exit 1
94fi