Automate git commit messages on each branch

I keep finding myself forgetful to add #ticket refs to my posts. It is a pain. Usually I use at least one branch per ticket, or at least there can be several branches for one ticket, but usually this is not the other way around.

So, I was thinking about how to add the branch.ticket config parameter and then extract it from the prep-commit-msg file and add "refs #" to my post.

Perhaps after that, even adding a hook or an alias to ask #ticket when I create a new branch.

Can someone help me build them? I am new to git, and I am also not without a bash guru, but I can understand this if I pointed in the right direction.

I'm going to call now

git config --add branch.<branchname>.ticket <ticketnumber>

and then do something like

prepend `git config branch<branchname>.ticket` $file

basically. I think. Can anyone confirm this? and tell me how to get <branchname>?

+3
source share
3 answers

There is this hook that does just that and is easier than my plan, because it just uses the branch name as the ticket number, so there is no need to configure the variable:

http://henrik.nyh.se/2009/09/git-hook-to-auto-reference-tickets-from-the-branchname

assuming the first row

#!/usr/bin/env ruby

reminded me that I could write this in python. Of course, Ruby, perl, and bash are better suited for the task.

0
source

That sounds good. You can get the current name of the branch (if any) with git symbolic-ref HEAD.

You can disconnect /refs/heads/. I use this in my script prompt:

local branchname=$(timeout 1s git symbolic-ref HEAD 2> /dev/null | cut -b 12-)

and then checking for an empty string.

+2

,

:

git branch | grep '^*' |sed s/\*\ //

git symbolic-ref HEAD /

0

All Articles