diff options
Diffstat (limited to 'hooks/pre-commit')
| -rwxr-xr-x | hooks/pre-commit | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/hooks/pre-commit b/hooks/pre-commit index c100bb634..6dd281c4a 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/bash |
| 2 | 2 | ||
| 3 | # Enforce citra's whitespace policy | 3 | # Enforce citra's whitespace policy |
| 4 | git config --local core.whitespace tab-in-indent,trailing-space | 4 | git config --local core.whitespace tab-in-indent,trailing-space |
| @@ -7,7 +7,7 @@ paths_to_check="src/ CMakeLists.txt" | |||
| 7 | 7 | ||
| 8 | # If there are whitespace errors, print the offending file names and fail. | 8 | # If there are whitespace errors, print the offending file names and fail. |
| 9 | if ! git diff --cached --check -- $paths_to_check ; then | 9 | if ! git diff --cached --check -- $paths_to_check ; then |
| 10 | cat<<END; | 10 | cat<<END |
| 11 | 11 | ||
| 12 | Error: This commit would contain trailing spaces or tabs, which is against this repo's policy. | 12 | Error: This commit would contain trailing spaces or tabs, which is against this repo's policy. |
| 13 | Please correct those issues before commiting. (Use 'git diff --check' for more details) | 13 | Please correct those issues before commiting. (Use 'git diff --check' for more details) |
| @@ -18,9 +18,26 @@ fi | |||
| 18 | 18 | ||
| 19 | # Check for tabs, since tab-in-indent catches only those at the beginning of a line | 19 | # Check for tabs, since tab-in-indent catches only those at the beginning of a line |
| 20 | if git diff --cached -- $paths_to_check | egrep '^\+.* '; then | 20 | if git diff --cached -- $paths_to_check | egrep '^\+.* '; then |
| 21 | cat<<END; | 21 | cat<<END |
| 22 | Error: This commit would contain a tab, which is against this repo's policy. | 22 | Error: This commit would contain a tab, which is against this repo's policy. |
| 23 | If you know what you are doing, you can try 'git commit --no-verify' to bypass the check. | 23 | If you know what you are doing, you can try 'git commit --no-verify' to bypass the check. |
| 24 | END | 24 | END |
| 25 | exit 1 | 25 | exit 1 |
| 26 | fi | 26 | fi |
| 27 | |||
| 28 | for f in $(git diff --name-only --diff-filter=ACMRTUXB --cached); do | ||
| 29 | if ! echo "$f" | egrep -q "[.](cpp|h)$"; then | ||
| 30 | continue | ||
| 31 | fi | ||
| 32 | if ! echo "$f" | egrep -q "^src/"; then | ||
| 33 | continue | ||
| 34 | fi | ||
| 35 | d=$(diff -u "$f" <(clang-format "$f")) | ||
| 36 | if ! [ -z "$d" ]; then | ||
| 37 | echo "!!! $f not compliant to coding style, here is the fix:" | ||
| 38 | echo "$d" | ||
| 39 | fail=1 | ||
| 40 | fi | ||
| 41 | done | ||
| 42 | |||
| 43 | exit "$fail" | ||