diff options
author | ng0 <ng0@n0.is> | 2019-09-29 10:30:10 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-29 10:30:10 +0000 |
commit | dd298ca059ed935560cccfa020127c93b4d3f823 (patch) | |
tree | 97d5330a31bd61df24ffcca8efed92107150e889 /contrib | |
parent | f5759dbc478ddf83b8a1d31d1580c845b9480633 (diff) | |
download | gnunet-dd298ca059ed935560cccfa020127c93b4d3f823.tar.gz gnunet-dd298ca059ed935560cccfa020127c93b4d3f823.zip |
add precommit hook example
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/uncrustify_precommit | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/contrib/uncrustify_precommit b/contrib/uncrustify_precommit new file mode 100644 index 000000000..bf7bac4ef --- /dev/null +++ b/contrib/uncrustify_precommit | |||
@@ -0,0 +1,34 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # use as .git/hooks/pre-commit | ||
4 | |||
5 | exec 1>&2 | ||
6 | |||
7 | RET=0 | ||
8 | |||
9 | changed=$(git diff --cached --name-only) | ||
10 | crustified="" | ||
11 | |||
12 | for f in $changed; | ||
13 | do | ||
14 | # compare result of uncrustify with changes | ||
15 | # | ||
16 | # only change any of the invocations here if | ||
17 | # they are portable across all cmp and shell | ||
18 | # implementations! | ||
19 | uncrustify -q -c uncrustify.cfg -f $f | cmp -s $f - | ||
20 | if test $? = 1 ; | ||
21 | then | ||
22 | crustified=" $crustified $f" | ||
23 | RET=1 | ||
24 | fi | ||
25 | done | ||
26 | |||
27 | if [ $RET = 1 ]; | ||
28 | then | ||
29 | echo "Run" | ||
30 | echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}" | ||
31 | echo "before commiting." | ||
32 | fi | ||
33 | |||
34 | exit $RET | ||