Reputation: 2259
I keep finding myself forgetting to add refs #ticket to my commits. It's a pain. I usually use at least one branch per ticket, or at least, there might be mutliple branches for one ticket, but usually not the other way around.
So I was thinking of something like add a branch.ticket config option and then retrieving it from probably prepare-commit-msg and prepending "refs #" to my message.
Maybe after this is done, even adding a hook or an alias to ask for a #ticket when I create a new branch.
Can someone help me build these? I'm fairly new at git, and am no bash guru either, but I can figure it out if pointed in the right direction.
By now, I gather I have to call
git config --add branch.<branchname>.ticket <ticketnumber>
and then do something like
prepend `git config branch<branchname>.ticket` $file
basically. I think. Anyone can confirm this? and tell me how to get < branchname >?
Upvotes: 3
Views: 791
Reputation: 301037
You are on right track I believe
There are many ways to get the current branch:
git branch | grep '^*' |sed s/\*\ //
Or use git symbolic-ref HEAD
and get the last part after /
Upvotes: 0
Reputation: 74750
This sounds good. You can get the current branch name (if there is one) with git symbolic-ref HEAD
.
You might want to cut off the /refs/heads/
. I'm using this in my prompt script:
local branchname=$(timeout 1s git symbolic-ref HEAD 2> /dev/null | cut -b 12-)
and then a check on being the empty string.
Upvotes: 2