LGPL-2.1
1999-2021 The Coq Development Team,; Institut National de Recherche en Informatique et en Automatique (INRIA),; Centre National de la Recherche Scientifique (CNRS),; Microsoft corporation; and contributors
debian/copyright
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# Usage: check-eof-newline.sh [--fix] FILES... |
| 4 |
# Detect missing end of file newlines for FILES. |
| 5 |
# Files are skipped if untracked by git and depending on gitattributes. |
| 6 |
# With --fix, automatically append a newline. |
| 7 |
# Exit status: |
| 8 |
# Without --fix: 1 if any file had a missing newline, 0 otherwise. |
| 9 |
# With --fix: 1 if any non writable file had a missing newline, 0 otherwise. |
| 10 |
|
| 11 |
FIX= |
| 12 |
if [ "$1" = --fix ]; |
| 13 |
then |
| 14 |
FIX=1 |
| 15 |
shift |
| 16 |
fi |
| 17 |
|
| 18 |
REDBOLD="\033[31m" |
| 19 |
YELLOW="\033[33m" |
| 20 |
RESET="\033[0m" |
| 21 |
|
| 22 |
function colorprint |
| 23 |
{ |
| 24 |
if [ "$COQ_CI_COLOR" ]; then |
| 25 |
printf "$1%s$RESET\n" "$2" |
| 26 |
else |
| 27 |
printf '%s\n' "$2" |
| 28 |
fi |
| 29 |
} |
| 30 |
|
| 31 |
CODE=0 |
| 32 |
for f in "$@"; do |
| 33 |
if git ls-files --error-unmatch "$f" >/dev/null 2>&1 && \ |
| 34 |
git check-attr whitespace -- "$f" | grep -q -v -e 'unset$' -e 'unspecified$' && \ |
| 35 |
[ -n "$(tail -c 1 "$f")" ] |
| 36 |
then |
| 37 |
if [ -n "$FIX" ]; |
| 38 |
then |
| 39 |
if [ -w "$f" ]; |
| 40 |
then |
| 41 |
echo >> "$f" |
| 42 |
colorprint "$YELLOW" "Newline appended to file $f!" |
| 43 |
else |
| 44 |
colorprint "$REDBOLD" "File $f is missing a newline and not writable!" |
| 45 |
CODE=1 |
| 46 |
fi |
| 47 |
else |
| 48 |
colorprint "$REDBOLD" "No newline at end of file $f!" |
| 49 |
CODE=1 |
| 50 |
fi |
| 51 |
fi |
| 52 |
done |
| 53 |
|
| 54 |
exit "$CODE" |