sd: sidebars are now visible in LOOL
[LibreOffice.git] / .git-hooks / commit-msg
blob64fb7924956b3f28f5c504e0053c01cfc1ea57b1
1 #!/bin/sh
3 # An example hook script to check the commit log message.
4 # Called by git-commit with one argument, the name of the file
5 # that has the commit message. The hook should exit with non-zero
6 # status after issuing an appropriate message if it wants to stop the
7 # commit. The hook is allowed to edit the commit message file.
9 # To enable this hook, make this file executable.
11 # Uncomment the below to add a Signed-off-by line to the message.
12 # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
13 # grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
15 # This example catches duplicate Signed-off-by lines.
17 base_dir=$(dirname $0)
18 MSG="$1"
20 abort() {
21 cp $1 $1.save
22 cat >&2 <<EOF
23 Commit aborted, your commit message was saved as '$1.save'.
25 Reason: $2
27 EOF
28 exit 1
31 test "" = "$(grep '^Signed-off-by: ' "$1" |
32 sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
33 abort "$1" "Duplicate Signed-off-by lines."
36 # Check that the first line exists, and is not an asterisk
38 if [ -z "`head -n 1 $1 | grep -v '^[[:blank:]]*\*$'`" ] ; then
39 abort "$1" "Please provide the general description on the first line."
42 # ...and that it is not too long
44 len="`head -n 1 $1 | wc -c`"
45 if [ "$len" -gt 79 ] ; then
46 abort "$1" "The first line is $len characters, please try to fit into 79 characters."
49 fdo_regex='fdo#[0-9]+'
50 if egrep -q "$fdo_regex" $1; then
51 for bugid in `head -n 1 $1 |egrep -o "$fdo_regex" |sed 's/fdo#//'`
53 if [ "`echo $bugid |sed 's/fdo#//'`" -gt 88775 ]; then
54 abort "$1" "The first line contains a suspicious fdo# rereference: 'fdo#$bugid', did you mean tdf#?"
56 done
59 # ...and that it does not continue on the second line
60 if [ "`wc -l < $1`" -gt 1 -a -n "`head -n 2 $1 | tail -n 1 | sed 's/^#.*//'`" ] ; then
61 abort "$1" "The second line is not empty - maybe the first line continues there?"
64 # Check that the message is not a ChangeLog-like one
66 if [ -n "`head -n 1 $1 | grep '^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}.*<.*@.*>'`" ] ; then
67 abort "$1" "The commit message looks like ChangeLog, please use the git form."
70 # Check that lines do not start with '#<something>' (possibly accidental commit,
71 # such as starting the message with '#ifdef', git commits start with '#<whitespace>'.
73 if [ -n "`grep '^#[^[:blank:]]' $1`" ] ; then
74 abort "$1" "Possible accidental comment in the commit message (leading # without space)."
78 #------------------ copied gerrit commit-msg hook to handle ChangeId -->
79 # From Gerrit Code Review 2.3
81 # Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
83 # Copyright (C) 2009 The Android Open Source Project
85 # Licensed under the Apache License, Version 2.0 (the "License");
86 # you may not use this file except in compliance with the License.
87 # You may obtain a copy of the License at
89 # http://www.apache.org/licenses/LICENSE-2.0
91 # Unless required by applicable law or agreed to in writing, software
92 # distributed under the License is distributed on an "AS IS" BASIS,
93 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
94 # See the License for the specific language governing permissions and
95 # limitations under the License.
98 CHANGE_ID_AFTER="Bug|Issue"
100 # Check for, and add if missing, a unique Change-Id
102 add_ChangeId() {
103 clean_message=`sed -e '
104 /^diff --git a\/.*/{
105 s///
108 /^Signed-off-by:/d
109 /^#/d
110 ' "$MSG" | git stripspace`
111 if test -z "$clean_message"
112 then
113 return
116 id=`grep -i '^Change-Id:' "$MSG" | sed -e "s/.*: I//"`
117 temp_msg=`grep -v -i '^Change-Id:' "$MSG"`
118 echo "$temp_msg" > "$MSG"
120 if test -z "$id"
121 then
122 id=`_gen_ChangeId`
124 perl -e '
125 $MSG = shift;
126 $id = shift;
127 $CHANGE_ID_AFTER = shift;
129 undef $/;
130 open(I, $MSG); $_ = <I>; close I;
131 s|^diff --git a/.*||ms;
132 s|^#.*$||mg;
133 exit unless $_;
135 @message = split /\n/;
136 $haveFooter = 0;
137 $startFooter = @message;
138 for($line = @message - 1; $line >= 0; $line--) {
139 $_ = $message[$line];
141 if (/^[a-zA-Z0-9-]+: /) {
142 $haveFooter++;
143 next;
145 next if /^[ []/;
146 $startFooter = $line if ($haveFooter && /^\r?$/);
147 last;
150 @footer = @message[$startFooter+1..@message];
151 @message = @message[0..$startFooter];
152 push(@footer, "") unless @footer;
154 for ($line = 0; $line < @footer; $line++) {
155 $_ = $footer[$line];
156 next if /^($CHANGE_ID_AFTER):/i;
157 last;
159 splice(@footer, $line, 0, "Change-Id: I$id");
161 $_ = join("\n", @message, @footer);
162 open(O, ">$MSG"); print O; close O;
163 ' "$MSG" "$id" "$CHANGE_ID_AFTER"
165 _gen_ChangeIdInput() {
166 echo "tree `git write-tree`"
167 if parent=`git rev-parse HEAD^0 2>/dev/null`
168 then
169 echo "parent $parent"
171 echo "author `git var GIT_AUTHOR_IDENT`"
172 echo "committer `git var GIT_COMMITTER_IDENT`"
173 echo
174 printf '%s' "$clean_message"
176 _gen_ChangeId() {
177 _gen_ChangeIdInput |
178 git hash-object -t commit --stdin
182 add_ChangeId
183 #------------------ copied gerrit commit-msg hook to handle ChangeId <--
186 exit 0
188 # vi:set shiftwidth=4 expandtab: