Skip to content

Commit

Permalink
Add more Git hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
doublep committed Feb 3, 2025
1 parent ca27cf4 commit 512784d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 9 additions & 2 deletions githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#!/bin/sh

DISCLAIMER="Remember that you can ignore these checks and force-commit with 'git commit -n'"

# This can be used in a comment as a reminder to self.
git diff-index --cached -S "DONOTCOMMIT" HEAD --patch --exit-code ":!githooks" \
|| { echo; echo "Have you forgotten about the “DONOTCOMMIT”?"; exit 1; }
|| { echo; echo "Have you forgotten about the “DONOTCOMMIT”?"; echo $DISCLAIMER; exit 1; }

git diff-index --cached HEAD -u . \
| egrep -C3 "^-.*DONOTCHANGETHIS" \
&& { echo "There is a changed line with DONOTCHANGETHIS in it"; echo $DISCLAIMER; exit 1; } \
|| true

# Eldev functions can be used during development, but must not be committed.
git diff-index --cached -S "eldev-" HEAD --patch --exit-code ":!githooks" ":!Eldev" \
|| { echo; echo "Don't commit code relying on Eldev!"; exit 1; }
|| { echo; echo "Don't commit code relying on Eldev!"; echo $DISCLAIMER; exit 1; }
10 changes: 10 additions & 0 deletions githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

DISCLAIMER="Remember that you can ignore these checks and force-push with 'git push --no-verify'"

REMOTE=$1

git log "$REMOTE/HEAD..HEAD" \
| egrep -C5 "DONOTPUSH" \
&& { echo "There is a not-yet-pushed commit with DONOTPUSH in its message"; echo $DISCLAIMER; exit 1; } \
|| true

0 comments on commit 512784d

Please sign in to comment.