pulse: fix oneshot event mask thinko.
[profile/ivi/speech-recognition.git] / githooks / pre-commit
1 #!/bin/bash
2 #
3 # This is a modified version of the stock git sample pre-commit hook.
4 # In addition to the stock whitespace error checks, this one will also
5 # reject any commits that try to insert TABs to *.c or *.h files.
6
7 if git rev-parse --verify HEAD >/dev/null 2>&1
8 then
9         against=HEAD
10 else
11         # Initial commit: diff against an empty tree object
12         against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
13 fi
14
15 # If you want to allow non-ascii filenames set this variable to true.
16 allownonascii=$(git config hooks.allownonascii)
17
18 # Redirect output to stderr.
19 exec 1>&2
20
21 # Cross platform projects tend to avoid non-ascii filenames; prevent
22 # them from being added to the repository. We exploit the fact that the
23 # printable range starts at the space character and ends with tilde.
24 if [ "$allownonascii" != "true" ] &&
25         # Note that the use of brackets around a tr range is ok here, (it's
26         # even required, for portability to Solaris 10's /usr/bin/tr), since
27         # the square bracket bytes happen to fall in the designated range.
28         test $(git diff --cached --name-only --diff-filter=A -z $against |
29           LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
30 then
31         echo "Error: Attempt to add a non-ascii file name."
32         echo
33         echo "This can cause problems if you want to work"
34         echo "with people on other platforms."
35         echo
36         echo "To be portable it is advisable to rename the file ..."
37         echo
38         echo "If you know what you are doing you can disable this"
39         echo "check using:"
40         echo
41         echo "  git config hooks.allownonascii true"
42         echo
43         exit 1
44 fi
45
46 # If there are whitespace errors, print the offending file names and fail.
47 git diff-index --check --cached $against --
48 status=$?
49
50 if [ "$status" != "0" ]; then
51     echo ""
52     echo "WARNING:"
53     echo "WARNING: Your commit would introduce whitespace errors and was"
54     echo "WARNING: hence rejected. Please fix those errors before trying"
55     echo "WARNING: to commit again."
56     echo "WARNING:"
57     exit 1
58 fi
59
60 # Check if any TABS have been added to .c or .h files...
61 file=""
62 git diff --cached $against | \
63     while read -r line; do
64         case $line in
65             diff\ --git\ a/*)         # 1st diff line, dig out file name
66                 file="${line##*b/}"
67                 echo "Checking changes to $file..."
68                 continue
69                 ;;
70         esac
71         case $file in
72             *.h|*.c) ;;               # we process C source code,
73             *) continue;;             # and skip any other files
74         esac
75         case $line in
76             +*\ *) ;;                 # we flag insertions containing a TAB,
77             *) continue;;             # and skip all other changes
78         esac
79
80         echo "WARNING:"
81         echo "WARNING: In $file: ($line)"
82         echo "WARNING:"
83         echo "WARNING: Your commit would introduce TABS in a *.c or *.h"
84         echo "WARNING: file and was hence rejected. We prefer not to use"
85         echo "WARNING: TABS in source code to avoid TAB-size dependent"
86         echo "WARNING: incorrect indentation to sneak in. Please fix those"
87         echo "WARNING: errors before trying to commit again."
88         echo "WARNING:"
89         exit 1
90     done
91
92 # Check if this commit attempts to mix changes to autogenerated files
93 # files with changes to ordinary file and give the user a gentle push
94 # against the idea...
95 auto="`git diff --cached $against | grep ^diff | grep -e -func-info.c`"
96 plain="`git diff --cached $against | grep ^diff | grep -v -e -func-info.c`"
97 if [ -n "$auto" -a -n "$plain" ]; then
98     echo "WARNING:"
99     echo "WARNING: Your commit tries to mix changes to ordinary and"
100     echo "WARNING: automatically generated files. Doing so makes it"
101     echo "WARNING: more difficult to merge your changes with changes"
102     echo "WARNING: of others working in parallel with you."
103     echo "WARNING:"
104     echo "WARNING: Please consider leaving out the following files"
105     echo "WARNING: from this commit and separating changes to them"
106     echo "WARNING: to a subsequent commit of its own:"
107     echo "WARNING:"
108     git diff --cached $against | grep ^diff | grep func-info.c | \
109         sed 's#^diff .* b/#WARNING:     #g'
110     echo "WARNING:"
111     echo "WARNING: In case you really need to commit all of these"
112     echo "WARNING: changes together you can disable this check by"
113     echo "WARNING: passing the -n option to 'git commit'."
114
115     exit 1
116 fi
117
118 exit $?