Skip to content

Commit

Permalink
hooks: Add pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Jul 4, 2024
1 parent 8d62122 commit c8aa0f3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .git-template/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
set -e

if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 # Initial commit; diff against an empty tree object.
fi

# Redirect output to stderr.

exec 1>&2

# Don't allow non-ASCII characters in filenames.

if test $(git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0; then
echo "Tryna add non-ASCII filenames"
exit 1
fi

# If there are terminating whitespaces, print the offending file names and fail.

git diff-index --check --cached $against --

# Run `pnpm format` and fail if it fails.

exec pnpm format

0 comments on commit c8aa0f3

Please sign in to comment.