Skip to content

Instantly share code, notes, and snippets.

@letmein
Last active August 29, 2015 13:56
Show Gist options
  • Save letmein/9071357 to your computer and use it in GitHub Desktop.
Save letmein/9071357 to your computer and use it in GitHub Desktop.
pre-commit hook
#!/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"
#!/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