Last active
March 22, 2016 19:56
-
-
Save segovia94/e2e6c42301d3b4c456a5 to your computer and use it in GitHub Desktop.
Git hook to prepend an issue number to commit messages based on the current branch name
This file contains hidden or 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 | |
# Add this file to a git repo's ./git/hooks directory | |
# Automatically adds branch issue ID to the beginning of every commit message. | |
# Branches mush end in "-(int)" like Issue-Name-1234 | |
# Adapted from http://waiting-for-dev.github.io/blog/2014/07/19/append-issue-number-to-commit-message-automatically-with-git-hooks/ | |
# Change the branch issue name for each project | |
REPONAME='SITEFARM' | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
STORY_NUMBER=$(echo $BRANCH_NAME | sed -n 's/.*-\([0-9]\)/\1/p') | |
if [ x != x${STORY_NUMBER} ]; then | |
sed -i.back "1s/^/$REPONAME-$STORY_NUMBER /" "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment