Last active
August 29, 2015 13:56
-
-
Save letmein/9071357 to your computer and use it in GitHub Desktop.
pre-commit hook
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
#!/bin/sh | |
# put this to .git/hooks/pre-commit | |
function check_commit_stopper { | |
COMMIT_STOPPER=$1 | |
if [ `git diff HEAD | grep $COMMIT_STOPPER | wc -l` -gt 0 ]; then | |
echo "$COMMIT_STOPPER detected, aborting commit." | |
echo "" | |
git grep -n --heading --break $COMMIT_STOPPER -- `git diff HEAD --name-only` | |
exit 1 | |
fi | |
} | |
check_commit_stopper "debugger" | |
check_commit_stopper "NOCOMMIT" | |
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
#!/bin/bash | |
# put this to ./git/hooks/prepare-commit-msg | |
# Extract the story id, provided the branch's name ends with it. Ex: your_branch_234342 | |
STORY_ID=`git branch | egrep '^\* .*' | egrep -o '[0-9]+$'` | |
# The temp file containing the commit message | |
COMMIT_MSG=$1 | |
# Need this for prepending text to the message. | |
TMP_MSG=/tmp/git-commit-tmp-msg | |
if [ -n "$STORY_ID" ]; then | |
grep -q $STORY_ID $TMP_MSG && exit 0 | |
# Prepend the story id to the commit message | |
echo "[#$STORY_ID] PLACEHOLDER" | cat - "$COMMIT_MSG" > "$TMP_MSG" && mv "$TMP_MSG" "$COMMIT_MSG" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment