Skip to content

Instantly share code, notes, and snippets.

@Frizi
Created June 28, 2020 20:00
Show Gist options
  • Save Frizi/1cb774149789c194590454b09f6d053c to your computer and use it in GitHub Desktop.
Save Frizi/1cb774149789c194590454b09f6d053c to your computer and use it in GitHub Desktop.
Git pre-commit hook to prevent checking in "nocheckin" or other specified strings.
#!/bin/sh
exec git show ":$1"
#!/bin/bash
declare -a arr=("nocheckin" "dbg!")
for i in "${arr[@]}"
do
git diff --cached --name-only | xargs rg --with-filename --pre ".git/hooks/git-show-staged.sh" -n "$i" && echo "COMMIT REJECTED! Found '$i' references. Please remove them before commiting." && exit 1
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment