summaryrefslogtreecommitdiff
path: root/etc/git
diff options
context:
space:
mode:
Diffstat (limited to 'etc/git')
-rwxr-xr-xetc/git/commit-msg124
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
20COMMIT_MSG_MAGIC=VGhpcyBpcyB0aGUgY29tbWl0LW1zZyBob29rIG9mIEd1aXg=
21top=$(git rev-parse --show-toplevel)
22if 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
29fi
30### Guix modifications end
31
32set -u
33
34# avoid [[ which is not POSIX sh.
35if test "$#" != 1 ; then
36 echo "$0 requires an argument."
37 exit 1
38fi
39
40if test ! -f "$1" ; then
41 echo "file does not exist: $1"
42 exit 1
43fi
44
45# Do not create a change id if requested
46case "$(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 ;;
58esac
59
60
61if git rev-parse --verify HEAD >/dev/null 2>&1; then
62 refhash="$(git rev-parse HEAD)"
63else
64 refhash="$(git hash-object -t tree /dev/null)"
65fi
66
67random=$({ git var GIT_COMMITTER_IDENT ; echo "$refhash" ; cat "$1"; } | git hash-object --stdin)
68dest="$1.tmp.${random}"
69
70trap 'rm -f "$dest" "$dest-2"' EXIT
71
72if ! sed -e '/>8/q' "$1" | git stripspace --strip-comments > "${dest}" ; then
73 echo "cannot strip comments from $1"
74 exit 1
75fi
76
77if test ! -s "${dest}" ; then
78 echo "file is empty: $1"
79 exit 1
80fi
81
82reviewurl="$(git config --get gerrit.reviewUrl)"
83if test -n "${reviewurl}" ; then
84 token="Link"
85 value="${reviewurl%/}/id/I$random"
86 pattern=".*/id/I[0-9a-f]\{40\}"
87else
88 token="Change-Id"
89 value="I$random"
90 pattern=".*"
91fi
92
93if git interpret-trailers --no-divider --parse < "$1" | grep -q "^$token: $pattern$" ; then
94 exit 0
95fi
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
100if ! 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
105fi
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
112if ! 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
119fi
120
121if ! mv "${dest}" "$1" ; then
122 echo "cannot mv ${dest} to $1"
123 exit 1
124fi