0

My feature branches are called feature/x_somename where x is the ticket number. Everytime I start a new commit, the following shall happen:

  1. Parse the ticket number from the branch name.
  2. Put refs #x: in the commit message (where x is the ticket number).
  3. Show commit dialog with the prepared commit message

How can I do this?

Tim Pohlmann
  • 4,140
  • 3
  • 32
  • 61

1 Answers1

0

It can be done using TortoiseGit hooks (not to be confused with git hooks):

  1. 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`
    
  2. In the TortoiseGit settings go to Hook Scripts.

  3. Press Add.
  4. Check Enabled.
  5. Choose path this hook should work for (* for all paths)
  6. Put the path to the batch script in the Command Line To Execute box.
  7. Press Ok and close settings.
  8. 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.

Tim Pohlmann
  • 4,140
  • 3
  • 32
  • 61