Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TortoiseGit - change default merge message

System description:

  • Windows 7
  • git version 2.10.1.windows.1
  • TortoiseGit 2.3.0.0


I want:

The merge commit message to be different in a fully automated manner (no manual amend)



Summary:

On windows, using tortoiseGit, there is no prepare-commit-msg hook, only start-commit-hook and no matter what the hook script is, I get a windows popup error:

%1 is not a valid Win32 application

Also, I would prefer to only change the commit messages which are "merges".



Steps:

setup the hook:

enter image description here

Set the working tree path to be same as my project's path,
and in "Command Line To Execute" I select the file I prepared:

.git\hooks\prepare-commit-msg

which its content is echo "test".

Then I try to do a commit and get this error:

enter image description here

I've made sure that this script file is indeed the file which is used,
because if I delete it, I get this message:

enter image description here

like image 708
vsync Avatar asked Aug 25 '26 18:08

vsync


1 Answers

TortoiseGit hooks are fully independent of vanilla Git hooks.

You can use any script language or executable as TortoiseGit hook script. However, in the configuration you have to enter a a valid Windows executable as command, e.g. an .exe file, for .js or .vbs scripts you need to specify the interpreter (wscript or cscript) and the path to the script as the interpreter parameter (cf. here). For executing a bash script I think you need to execute bash.exe with the appropriate parameters to a script - I haven't tested this before.

The executed hook gets some parameters from TortoiseGit, those are documented here, e.g. the Start-commit is called when the commit dialog is opened and gets three cli parameters: PATH MESSAGEFILE CWD, whereas PATH is a path to a file containing all entries of the commit dialog, MESSAGEFILE is the path to a file where you can put the contents to which should be used as commit message and CWD is the working tree path.

Examples can be found on https://github.com/TortoiseGit/TortoiseGit/tree/master/contrib/hook-scripts/client-side

PS: In order to check whether this is a merge commit you can check for the existance of .git/MERGE_HEAD.

like image 70
MrTux Avatar answered Aug 27 '26 08:08

MrTux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!