Last active
August 29, 2015 14:18
-
-
Save Ionshard/e49564fdbbbf0a0ed2a6 to your computer and use it in GitHub Desktop.
Automatically Prepend Ticket ID to Git Commit Message Based on Feature Branch
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 | |
| # | |
| # An example hook script to prepare the commit log message. | |
| # Called by "git commit" with the name of the file that has the | |
| # commit message, followed by the description of the commit | |
| # message's source. The hook's purpose is to edit the commit | |
| # message file. If the hook fails with a non-zero status, | |
| # the commit is aborted. | |
| #If your current branch matches the pattern f/TICKET-ID1234 or f/TICKET-ID1234-some-description | |
| # this script will append [TICKET-ID1234] to your commit message | |
| branch=$(git symbolic-ref -q --short HEAD) | |
| ticket=$(echo $branch | sed -n 's/^f\/\([A-Z]\+-[0-9]\+\)-\?.*/\1/p') | |
| if [ -n "$ticket" ]; then | |
| sed "1s/^/[$ticket] /" $1 > $1.new | |
| mv $1.new $1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like on a mac, the "+" is the problem, so on a mac try
Tada (thanks Corey)