diff options
| author | Gaëtan Gilbert | 2018-01-23 16:36:25 +0100 |
|---|---|---|
| committer | Gaëtan Gilbert | 2018-02-08 17:16:39 +0100 |
| commit | 85bcd29052d30db75df5b8e8aeeb91b0327077f2 (patch) | |
| tree | 791ce33ee2a14a628be9aa8ecbf6e2f23d6f64d5 /dev/tools/check-eof-newline.sh | |
| parent | 04a3fa7eac845039b0b1a11d1a5958486f183a4d (diff) | |
pre-commit: add files after fixing ending newlines.
Diffstat (limited to 'dev/tools/check-eof-newline.sh')
| -rwxr-xr-x | dev/tools/check-eof-newline.sh | 17 |
1 files changed, 12 insertions, 5 deletions
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 |
