Skip to content

Instantly share code, notes, and snippets.

@tadejm
Forked from tscolari/aaa-prepare-commit.md
Created November 22, 2013 17:53
Show Gist options
  • Save tadejm/7604092 to your computer and use it in GitHub Desktop.
Save tadejm/7604092 to your computer and use it in GitHub Desktop.
  • add prepare-commit-msg it to ./.git/hooks/
  • Make it executable (chmod +x filename)

It should prepend [#STORY_ID] into your commit message when the editor pops up. Your branch must be in this format to work: branch-description-blabla-STORY_ID

it skips the prepaend if:

  • The branch doesn't end in a story id (integer)
  • The original commit message starts with "Merge"
cat $1 | head -n 1 | egrep "Merge" && exit 0
BRANCH=$(git rev-parse --abbrev-ref HEAD)
STORY_ID=$(echo ${BRANCH##*-})
if [[ "$STORY_ID" =~ ^[0-9]+$ ]]
then
original_message=$(cat $1)
echo "[#${STORY_ID}] ${original_message}" > $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment