Skip to content

Commit 9f1834e

Browse files
nthiebaudFridrich Strba
authored and
Fridrich Strba
committed
add automatic git hook setting in autogen.sh
Change-Id: I95eb02dc2d347337d7b85f85d6459353278fb137 Reviewed-on: https://gerrit.libreoffice.org/5748 Reviewed-by: Fridrich Strba <[email protected]> Tested-by: Fridrich Strba <[email protected]>
1 parent 27a9dd7 commit 9f1834e

File tree

5 files changed

+366
-7
lines changed

5 files changed

+366
-7
lines changed

.git-hooks/README

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Git hooks are executable scripts you can place in $GIT_DIR/hooks directory to trigger action at certain points.
2+
3+
There are two groups of these hooks: client side and server side.
4+
The client-side hooks:
5+
are for client operations such as committing and merging.
6+
The server-side hooks:
7+
are for Git server operations such as receiving pushed commits.
8+
9+
See Also [ http://git-scm.com/book/en/Customizing-Git-Git-Hooks ]

.git-hooks/commit-msg

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#!/bin/sh
2+
#
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.
8+
#
9+
# To enable this hook, make this file executable.
10+
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"
14+
15+
# This example catches duplicate Signed-off-by lines.
16+
17+
base_dir=$(dirname $0)
18+
MSG="$1"
19+
20+
abort() {
21+
cp $1 $1.save
22+
cat >&2 <<EOF
23+
Commit aborted, your commit message was saved as '$1.save'.
24+
25+
Reason: $2
26+
27+
EOF
28+
exit 1
29+
}
30+
31+
test "" = "$(grep '^Signed-off-by: ' "$1" |
32+
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
33+
abort "$1" "Duplicate Signed-off-by lines."
34+
}
35+
36+
# Check that the first line exists, and is not an asterisk
37+
38+
if [ -z "`head -n 1 $1 | grep -v '^[[:blank:]]*\*$'`" ] ; then
39+
abort "$1" "Please provide the general description on the first line."
40+
fi
41+
42+
# ...and that it is not too long
43+
44+
if [ "`head -n 1 $1 | wc -c`" -gt 79 ] ; then
45+
abort "$1" "The first line is too long, please try to fit into 79 characters."
46+
fi
47+
48+
# ...and that it does not continue on the second line
49+
if [ "`wc -l < $1`" -gt 1 -a -n "`head -n 2 $1 | tail -n 1 | sed 's/^#.*//'`" ] ; then
50+
abort "$1" "The second line is not empty - maybe the first line continues there?"
51+
fi
52+
53+
# Check that the message is not a ChangeLog-like one
54+
55+
if [ -n "`head -n 1 $1 | grep '^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}.*<.*@.*>'`" ] ; then
56+
abort "$1" "The commit message looks like ChangeLog, please use the git form."
57+
fi
58+
59+
# Check for whitespace in front of *'s
60+
61+
if [ -n "`sed '/^#/,$d' $1 | grep '^[[:space:]]\+\*.*:'`" -a -z "`grep '^\*' $1`" ] ; then
62+
abort "$1" "Please don't use whitespace in front of '* file: Description.' entries."
63+
fi
64+
65+
# Check that lines do not start with '#<something>' (possibly accidental commit,
66+
# such as starting the message with '#ifdef', git commits start with '#<whitespace>'.
67+
68+
if [ -n "`grep '^#[^[:blank:]]' $1`" ] ; then
69+
abort "$1" "Possible accidental comment in the commit message (leading # without space)."
70+
fi
71+
72+
73+
#------------------ copied gerrit commit-msg hook to handle ChangeId -->
74+
# From Gerrit Code Review 2.3
75+
#
76+
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
77+
#
78+
# Copyright (C) 2009 The Android Open Source Project
79+
#
80+
# Licensed under the Apache License, Version 2.0 (the "License");
81+
# you may not use this file except in compliance with the License.
82+
# You may obtain a copy of the License at
83+
#
84+
# http://www.apache.org/licenses/LICENSE-2.0
85+
#
86+
# Unless required by applicable law or agreed to in writing, software
87+
# distributed under the License is distributed on an "AS IS" BASIS,
88+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
89+
# See the License for the specific language governing permissions and
90+
# limitations under the License.
91+
#
92+
93+
CHANGE_ID_AFTER="Bug|Issue"
94+
95+
# Check for, and add if missing, a unique Change-Id
96+
#
97+
add_ChangeId() {
98+
clean_message=`sed -e '
99+
/^diff --git a\/.*/{
100+
s///
101+
q
102+
}
103+
/^Signed-off-by:/d
104+
/^#/d
105+
' "$MSG" | git stripspace`
106+
if test -z "$clean_message"
107+
then
108+
return
109+
fi
110+
111+
id=`grep -i '^Change-Id:' "$MSG" | sed -e "s/.*: I//"`
112+
temp_msg=`grep -v -i '^Change-Id:' "$MSG"`
113+
echo "$temp_msg" > "$MSG"
114+
115+
if test -z "$id"
116+
then
117+
id=`_gen_ChangeId`
118+
fi
119+
perl -e '
120+
$MSG = shift;
121+
$id = shift;
122+
$CHANGE_ID_AFTER = shift;
123+
124+
undef $/;
125+
open(I, $MSG); $_ = <I>; close I;
126+
s|^diff --git a/.*||ms;
127+
s|^#.*$||mg;
128+
exit unless $_;
129+
130+
@message = split /\n/;
131+
$haveFooter = 0;
132+
$startFooter = @message;
133+
for($line = @message - 1; $line >= 0; $line--) {
134+
$_ = $message[$line];
135+
136+
if (/^[a-zA-Z0-9-]+: /) {
137+
$haveFooter++;
138+
next;
139+
}
140+
next if /^[ []/;
141+
$startFooter = $line if ($haveFooter && /^\r?$/);
142+
last;
143+
}
144+
145+
@footer = @message[$startFooter+1..@message];
146+
@message = @message[0..$startFooter];
147+
push(@footer, "") unless @footer;
148+
149+
for ($line = 0; $line < @footer; $line++) {
150+
$_ = $footer[$line];
151+
next if /^($CHANGE_ID_AFTER):/i;
152+
last;
153+
}
154+
splice(@footer, $line, 0, "Change-Id: I$id");
155+
156+
$_ = join("\n", @message, @footer);
157+
open(O, ">$MSG"); print O; close O;
158+
' "$MSG" "$id" "$CHANGE_ID_AFTER"
159+
}
160+
_gen_ChangeIdInput() {
161+
echo "tree `git write-tree`"
162+
if parent=`git rev-parse HEAD^0 2>/dev/null`
163+
then
164+
echo "parent $parent"
165+
fi
166+
echo "author `git var GIT_AUTHOR_IDENT`"
167+
echo "committer `git var GIT_COMMITTER_IDENT`"
168+
echo
169+
printf '%s' "$clean_message"
170+
}
171+
_gen_ChangeId() {
172+
_gen_ChangeIdInput |
173+
git hash-object -t commit --stdin
174+
}
175+
176+
177+
add_ChangeId
178+
#------------------ copied gerrit commit-msg hook to handle ChangeId <--
179+
180+
181+
exit 0

.git-hooks/post-merge

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
# Do not warn if there were no real merge
4+
git rev-parse -q --verify HEAD^2 >/dev/null || exit
5+
6+
echo
7+
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
8+
echo "! You probably used 'git pull' instead of 'git pull -r' !"
9+
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
10+
echo
11+
echo "You can still fix it - please do 'git pull -r' now."
12+
echo

.git-hooks/pre-commit

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env perl
2+
3+
# A hook script to verify what is about to be committed.
4+
# Called by "git commit" with no arguments. The hook should
5+
# exit with non-zero status after issuing an appropriate message
6+
# if it wants to stop the commit.
7+
8+
use strict;
9+
#use File::Copy;
10+
#use Cwd;
11+
12+
$ENV{LC_ALL} = "C";
13+
14+
sub check_whitespaces($)
15+
{
16+
my ($h) = @_;
17+
my $src_limited = "c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pmk|pl|pm|sdi|sh|src|tab|ui|xcu|xml";
18+
my $src_full = "c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|mk|MK|pmk|pl|pm|sdi|sh|src|tab|ui|xcu|xml";
19+
20+
my $found_bad = 0;
21+
my $filename;
22+
my $reported_filename = "";
23+
my $lineno;
24+
sub bad_line
25+
{
26+
my ($why, $line, $file_filter) = @_;
27+
if (!defined $file_filter || $filename =~ /\.($file_filter)$/)
28+
{
29+
if (!$found_bad)
30+
{
31+
print STDERR "*\n";
32+
print STDERR "* You have some suspicious patch lines:\n";
33+
print STDERR "*\n";
34+
$found_bad = 1;
35+
}
36+
if ($reported_filename ne $filename)
37+
{
38+
print STDERR "* In $filename\n";
39+
$reported_filename = $filename;
40+
}
41+
print STDERR "* $why (line $lineno)\n";
42+
print STDERR "$filename:$lineno:$line\n";
43+
}
44+
}
45+
open( FILES, "git-diff-index -p -M --cached $h |" ) || die "Cannot run git diff-index.";
46+
while (<FILES>)
47+
{
48+
if (m|^diff --git a/(.*) b/\1$|)
49+
{
50+
$filename = $1;
51+
next;
52+
}
53+
if (/^@@ -\S+ \+(\d+)/)
54+
{
55+
$lineno = $1 - 1;
56+
next;
57+
}
58+
if (/^ /)
59+
{
60+
$lineno++;
61+
next;
62+
}
63+
if (s/^\+//)
64+
{
65+
$lineno++;
66+
chomp;
67+
if (/\s$/)
68+
{
69+
bad_line("trailing whitespace", $_ , $src_limited);
70+
}
71+
if (/\s* /)
72+
{
73+
bad_line("indent with Tab", $_, $src_limited);
74+
}
75+
if (/^(?:[<>=]){7}$/)
76+
{
77+
bad_line("unresolved merge conflict", $src_full);
78+
}
79+
if (/SAL_DEBUG/)
80+
{
81+
bad_line("temporary debug in commit", $_, $src_limited);
82+
}
83+
if (/<property name="use_markup">True<\/property>/)
84+
{
85+
bad_line("use font attributes instead of use-markup", $_, $src_limited);
86+
}
87+
}
88+
}
89+
if ( $found_bad)
90+
{
91+
exit($found_bad);
92+
}
93+
}
94+
95+
# Do the work :-)
96+
97+
# Initial commit: diff against an empty tree object
98+
my $against="4b825dc642cb6eb9a060e54bf8d69288fbee4904";
99+
if ( system( "git rev-parse --verify HEAD >/dev/null 2>&1" ) == 0 )
100+
{
101+
$against="HEAD"
102+
}
103+
104+
# If you want to allow non-ascii filenames set this variable to true.
105+
my $allownonascii=`git config hooks.allownonascii`;
106+
107+
# Cross platform projects tend to avoid non-ascii filenames; prevent
108+
# them from being added to the repository. We exploit the fact that the
109+
# printable range starts at the space character and ends with tilde.
110+
if ( $allownonascii ne "true" &&
111+
# Note that the use of brackets around a tr range is ok here, (it's
112+
# even required, for portability to Solaris 10's /usr/bin/tr), since
113+
# the square bracket bytes happen to fall in the designated range.
114+
`git diff --cached --name-only --diff-filter=A -z $against | \
115+
LC_ALL=C tr -d '[ -~]\\0'` ne "" )
116+
{
117+
print <<EOM;
118+
Error: Attempt to add a non-ascii file name.
119+
120+
This can cause problems if you want to work
121+
with people on other platforms.
122+
123+
To be portable it is advisable to rename the file ...
124+
125+
If you know what you are doing you can disable this
126+
check using:
127+
128+
git config hooks.allownonascii true
129+
130+
EOM
131+
exit( 1 );
132+
}
133+
134+
# fix whitespace in code
135+
check_whitespaces( $against);
136+
137+
# all OK
138+
exit( 0 );
139+
# vi:set shiftwidth=4 expandtab:

autogen.sh

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
#!/bin/sh
2+
3+
set_git_hooks()
4+
{
5+
# assume that the current directory is the source tree
6+
if [ -d ".git" ] ; then
7+
for hook in $(ls -1 .git-hooks) ; do
8+
cd .git/hooks
9+
if [ ! -e "${hook?}" -o -L "${hook?}" ] ; then
10+
rm -f "${hook?}"
11+
ln -sf "../../.git-hooks/${hook?}" "${hook?}"
12+
fi
13+
cd - > /dev/null
14+
done
15+
fi
16+
}
17+
218
TESTLIBTOOLIZE="glibtoolize libtoolize"
319

420
LIBTOOLIZEFOUND="0"
@@ -9,6 +25,8 @@ test -z "$srcdir" && srcdir=.
925
olddir=`pwd`
1026
cd $srcdir
1127

28+
set_git_hooks
29+
1230
aclocal --version > /dev/null 2> /dev/null || {
1331
echo "error: aclocal not found"
1432
exit 1
@@ -19,16 +37,16 @@ automake --version > /dev/null 2> /dev/null || {
1937
}
2038

2139
for i in $TESTLIBTOOLIZE; do
22-
if which $i > /dev/null 2>&1; then
23-
LIBTOOLIZE=$i
24-
LIBTOOLIZEFOUND="1"
25-
break
26-
fi
40+
if which $i > /dev/null 2>&1; then
41+
LIBTOOLIZE=$i
42+
LIBTOOLIZEFOUND="1"
43+
break
44+
fi
2745
done
2846

2947
if [ "$LIBTOOLIZEFOUND" = "0" ]; then
30-
echo "$0: need libtoolize tool to build libvisio" >&2
31-
exit 1
48+
echo "$0: need libtoolize tool to build libvisio" >&2
49+
exit 1
3250
fi
3351

3452
amcheck=`automake --version | grep 'automake (GNU automake) 1.5'`

0 commit comments

Comments
 (0)