From 85bcd29052d30db75df5b8e8aeeb91b0327077f2 Mon Sep 17 00:00:00 2001 From: Gaƫtan Gilbert Date: Tue, 23 Jan 2018 16:36:25 +0100 Subject: pre-commit: add files after fixing ending newlines. --- dev/tools/check-eof-newline.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'dev/tools/check-eof-newline.sh') diff --git a/dev/tools/check-eof-newline.sh b/dev/tools/check-eof-newline.sh index c5a654e21d..e244d9ab80 100755 --- a/dev/tools/check-eof-newline.sh +++ b/dev/tools/check-eof-newline.sh @@ -4,8 +4,9 @@ # Detect missing end of file newlines for FILES. # Files are skipped if untracked by git and depending on gitattributes. # With --fix, automatically append a newline. -# Exit status: 1 if any file had a missing newline, 0 otherwise -# (regardless of --fix). +# Exit status: +# Without --fix: 1 if any file had a missing newline, 0 otherwise. +# With --fix: 1 if any non writable file had a missing newline, 0 otherwise. FIX= if [ "$1" = --fix ]; @@ -22,12 +23,18 @@ for f in "$@"; do then if [ -n "$FIX" ]; then - echo >> "$f" - echo "Newline appended to file $f!" + if [ -w "$f" ]; + then + echo >> "$f" + echo "Newline appended to file $f!" + else + echo "File $f is missing a newline and not writable!" + CODE=1 + fi else echo "No newline at end of file $f!" + CODE=1 fi - CODE=1 fi done -- cgit v1.2.3