Uniglot/Hooks/scripts.d/whitespace

23 lines
644 B
Plaintext
Raw Normal View History

#!/bin/bash
# Sourced from https://github.com/git/git/blob/master/templates/hooks--pre-commit.sample
2023-04-19 00:03:49 -05:00
if git ls-files | grep -v .tar.gz | xargs --delimiter='\n' grep -irlE '\s\+$'; then
2022-10-26 19:38:18 -05:00
echo The above lines have trailing whitespace. Run "sed -i 's/\s\+$//'" on the affected files.
exit 1
fi
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi
# Redirect output to stderr.
exec 1>&2
2022-10-26 19:38:18 -05:00
# If there are whitespace errors, print the offending file names and fail.
2022-10-26 19:38:18 -05:00
exec git diff-index --check --cached $against --