From 8cefdd3289776ed58199e5f608802546d6681eef Mon Sep 17 00:00:00 2001 From: Gaƫtan Gilbert Date: Thu, 8 Feb 2018 17:13:12 +0100 Subject: pre-commit: fail gracefully if fixing whitespace removes all changes --- dev/tools/pre-commit | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'dev/tools/pre-commit') diff --git a/dev/tools/pre-commit b/dev/tools/pre-commit index c5f6868d15..656455aee9 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 -- cgit v1.2.3