2

I use TortoiseGit on Windows. Everytime I start a new commit, the following shall happen:

  1. Search for added or modified lines containing " TODO"
  2. Add these lines to the commit message (meant as a warning)
  3. Show commit dialog with the prepared commit message

How can I do this?

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

2 Answers2

2

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

  1. Create a batch file with the following line (just copy and paste):

    git diff --color=always | findstr "[32m+[m[32m" | findstr /c:" TODO" >> %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 diff --color=always shows all changes with nice colors.
We use those colors in addition to the + to identify added lines with the first findstr command.
The second findstr command looks for " TODO".
The /c: parameter tells findstr to interpret the space as part of the search pattern.

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

I followed @Tim Pohlmann's answer above and ended up modifying the batch script to be:

git diff | findstr "^+// TODO:" > %2

I made this change because the original command was printing the color specifiers in the TortoiseGit commit dialog.

Additionally, I had to specify the Hook Type as "Start Commit Hook" and check the box labelled "Wait for the script to finish" in the Configure Hook Scripts dialog.

For further clarity, the %2 pipes the output of the command to TortoiseGit's commit dialog.

I looked into adding line numbers, but the git diff command does not support adding line numbers per this post. A simple enough solution is to be more descriptive in my TODO's :)