-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #628 from bclement-ocp/bclement/precommit
Better pre-commit hook
- Loading branch information
Showing
2 changed files
with
38 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
#!/bin/sh | ||
|
||
git_repo=`git rev-parse --show-toplevel` | ||
cd $git_repo/rsc/extra | ||
if git rev-parse --verify HEAD >/dev/null 2>&1 | ||
then | ||
against=HEAD | ||
else | ||
# Initial commit: diff against an empty tree object | ||
against=$(git hash-object -t tree /dev/null) | ||
fi | ||
|
||
res=`./check_style.sh` | ||
echo $res | ||
# Redirect output to stderr. | ||
exec 1>&2 | ||
|
||
if [ "$res" = "All files have correct style" ] ; then | ||
./check_indentation.sh | ||
exit $? | ||
else | ||
exit 1 | ||
# Reindent files using ocp-indent | ||
errors=0 | ||
files=$(git diff --cached --name-only --diff-filter=ACMR -z HEAD | grep -Ez '\.ml[ily]?$' | xargs -0) | ||
for f in $files; do | ||
cmp -s <(git show ":$f") <(git show ":$f" | ocp-indent) | ||
if [[ $? -ne 0 ]]; then | ||
echo "$f: indentation errors." | ||
ocp-indent -i "$f" | ||
git diff -- "$f" | ||
errors=$((errors+1)) | ||
fi | ||
done | ||
|
||
if [[ $errors -ne 0 ]]; then | ||
exit 1 | ||
fi | ||
|
||
# If there are whitespace errors, print the offending file names and fail. | ||
exec git diff-index --check --cached $against -- |