To eliminate the need to constantly type out the ticket information at the beginning of a commit message, this script uses the built in git hook system to prepend commits with the ticket information from the branch name. For example, if your branch is named:
b-51392/fixed-minor-visual-bug
the hook will grab the ticket information at the beginning of the branch name and prepend it to your comments:
$ git commit -m "Test commit message"
[b-51392/fixed-minor-visual-bug 74cfe0e] B-51392: Test commit message.
1 file changed, 1 insertion(+)
$ git log
commit 74cfe0eddf3fa9f2056a95aa06085cc4e2e57520
Author: Andrew Mussey
Date: Tue Oct 29 10:25:27 2013 -0400
B-51392: Test commit message.
In order for this to work as expected, the ticket must be in the format of:
[Ticket info]/[Title]
On top of this, the expected format of the ticket name is one of the following:
[Single Letter]-[Series of numbers] (such as b-51231 or d-42132)
hackday
Any other ticket name is currently discarded.
Copy this file to your local git repo, and save it in the .git/hooks directory as prepare-commit-msg
. Then, run:
chmod +x prepare-commit-msg
It's as easy as that!
Note: You will have to do this for each repo.
If you have the git bash prompt plugin installed: