Last active
March 17, 2023 01:48
-
-
Save bricss/25b089e99bd5005aac51140864d9b89b to your computer and use it in GitHub Desktop.
Warns before committing if staged files contains focused tests
This file contains 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
#!/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