Skip to content
Snippets Groups Projects
Commit c3d0b77f authored by Brad King's avatar Brad King
Browse files

pre-commit: Add whitespace check "no-lf-at-eol"

parent f5602245
No related branches found
No related tags found
No related merge requests found
......@@ -81,6 +81,15 @@ check_tab() {
done
}
# Reject addition of a line without a newline at end-of-file.
check_no_lf_at_eof() {
lines=$(git diff-index -p --cached $against -- "$1" | tail -2)
if echo "$lines" | head -1 | grep -q '^+' &&
echo "$lines" | tail -1 | grep -q '^\\ No newline'; then
echo "$1: No newline at end of file"
fi
}
# Custom whitespace checks.
check_whitespace() {
ws=$(git check-attr whitespace -- "$file" |
......@@ -90,6 +99,9 @@ check_whitespace() {
*,tab-in-indent,*) check_tab "$1" ;;
esac
fi
case ",$ws," in
*,no-lf-at-eof,*) check_no_lf_at_eof "$1" ;;
esac
}
bad=$(git diff-index --name-only --cached $against -- |
while read file; do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment