aboutsummaryrefslogtreecommitdiffhomepage
path: root/dev/tools
diff options
context:
space:
mode:
authorGravatar Gaëtan Gilbert <gaetan.gilbert@skyskimmer.net>2018-02-08 17:13:12 +0100
committerGravatar Gaëtan Gilbert <gaetan.gilbert@skyskimmer.net>2018-02-08 17:16:52 +0100
commit8cefdd3289776ed58199e5f608802546d6681eef (patch)
treefa9a0eec5e85c1bddae46207f0091173295f3a9d /dev/tools
parent85bcd29052d30db75df5b8e8aeeb91b0327077f2 (diff)
pre-commit: fail gracefully if fixing whitespace removes all changes
Diffstat (limited to 'dev/tools')
-rwxr-xr-xdev/tools/pre-commit13
1 files changed, 12 insertions, 1 deletions
diff --git a/dev/tools/pre-commit b/dev/tools/pre-commit
index c5f6868d1..656455aee 100755
--- a/dev/tools/pre-commit
+++ b/dev/tools/pre-commit
@@ -36,12 +36,23 @@ then
# reset work tree
git diff-index -p --cached HEAD > "$fixed_index"
- git apply -R "$fixed_index"
+ # If all changes were bad whitespace changes the patch is empty
+ # making git fail. Don't fail now: we fix the worktree first.
+ if [ -s "$fixed_index" ]
+ then
+ git apply -R "$fixed_index"
+ fi
# Fix worktree
git apply --whitespace=fix "$tree"
git diff --name-only -z | xargs -0 dev/tools/check-eof-newline.sh --fix
+ if ! [ -s "$fixed_index" ]
+ then
+ 1>&2 echo "No changes after fixing whitespace issues!"
+ exit 1
+ fi
+
# Check that we did fix whitespace
if ! git diff-index --check --cached HEAD;
then