diff options
author | Benjamin Barenblat <bbaren@debian.org> | 2018-12-29 14:31:32 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@debian.org> | 2018-12-29 14:31:32 -0500 |
commit | 2708a015fcf65f72328be4296a00dd32b1f1c17a (patch) | |
tree | 696f9b5fb84817e1a5c8d9271976a92e25aef18a /dev/tools/check-eof-newline.sh | |
parent | d7d80c5bea564b7cb0eadc33e9ee38c9d9de1cd8 (diff) | |
parent | 9043add656177eeac1491a73d2f3ab92bec0013c (diff) |
Updated version 8.8.2 from 'upstream/8.8.2'
with Debian dir a16bcf46abacaf1a684eda04f02555c984bf540d
Diffstat (limited to 'dev/tools/check-eof-newline.sh')
-rwxr-xr-x | dev/tools/check-eof-newline.sh | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/dev/tools/check-eof-newline.sh b/dev/tools/check-eof-newline.sh new file mode 100755 index 00000000..e244d9ab --- /dev/null +++ b/dev/tools/check-eof-newline.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Usage: check-eof-newline.sh [--fix] FILES... +# 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: +# 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 ]; +then + FIX=1 + shift +fi + +CODE=0 +for f in "$@"; do + if git ls-files --error-unmatch "$f" >/dev/null 2>&1 && \ + git check-attr whitespace -- "$f" | grep -q -v -e 'unset$' -e 'unspecified$' && \ + [ -n "$(tail -c 1 "$f")" ] + then + if [ -n "$FIX" ]; + then + 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 + fi +done + +exit "$CODE" |