Created
May 9, 2023 23:35
-
-
Save bdarcus/a90969f9f063134c55d04a2b6d704e70 to your computer and use it in GitHub Desktop.
pre-commit hook to only run a check on staged files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PREFIX="pre-commit:" | |
fileList=$(git diff --diff-filter=d --cached --name-only) | |
includeFileList=$(echo "$fileList" | grep -E '\.(ts)$') | |
if [ ${#includeFileList} -gt 0 ]; then | |
if ! deno fmt --check ${includeFileList[*]} "$@"; then | |
echo "$PREFIX Commit aborted." | |
echo "$PREFIX You can lint and format manually with 'deno lint'.\n" | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
adapted from:
https://markus.oberlehner.net/blog/lint-only-files-with-changes-on-pre-commit/