Skip to content

Instantly share code, notes, and snippets.

@bricss
Last active March 17, 2023 01:48
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 bricss/25b089e99bd5005aac51140864d9b89b to your computer and use it in GitHub Desktop.
Save bricss/25b089e99bd5005aac51140864d9b89b to your computer and use it in GitHub Desktop.
Warns before committing if staged files contains focused tests
#!/usr/bin/env bash
# Warns before committing if staged files contains focused tests
# Bypass with `git commit --no-verify`
dict=(describe.only it.only test.only)
status=0
for keyword in "${dict[@]}"; do
rex="/^s*${keyword%.*}.*(?=${keyword#*.})/"
files=$(git diff --staged -G${rex} --name-only)
if [[ $(wc -l <<< "$files") -gt 0 ]]; then
echo "Forbidden keyword '$keyword' in the following files:\n$files"
status=1
fi
done
exit $status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment