It can be done using TortoiseGit hooks (not to be confused with git hooks):
Create a batch file with the following lines (just copy and paste):
:: try to parse ticket number from branchname (expected format: "sometext/ticketnumber_sometext")
for /f "tokens=2 delims=/_" %%i in ('git rev-parse --abbrev-ref HEAD') do set c=%%i
:: print "refs #ticketnumber: "
if defined c echo refs #%c%: >> %2`
In the TortoiseGit settings go to Hook Scripts
.
- Press
Add
.
- Check
Enabled
.
- Choose path this hook should work for (
*
for all paths)
- Put the path to the batch script in the
Command Line To Execute
box.
- Press
Ok
and close settings.
- Close and reopen all other TortoiseGit windows to ensure the hook is setup.
What does the batch file do?
git rev-parse --abbrev-ref HEAD
returns the branchname.
The for
command splits the result by /
and _
.
It will then take the second part of this split and saves it in %%i.
It then saves %%i to the variable c.
The if
just checks if c is defined and if so prints the result.