Skip to content

Instantly share code, notes, and snippets.

@bdarcus
Created May 9, 2023 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdarcus/a90969f9f063134c55d04a2b6d704e70 to your computer and use it in GitHub Desktop.
Save bdarcus/a90969f9f063134c55d04a2b6d704e70 to your computer and use it in GitHub Desktop.
pre-commit hook to only run a check on staged files
#!/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
@bdarcus
Copy link
Author

bdarcus commented May 9, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment