Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select git mergetool based on file type

When running git mergetool, I'd like to have git select the merge tool used based on the file extension. How can I do this?

A similar question was asked here: Git: configure patterns for difftool and mergetool and the answer was to write a custom merge driver. However, it seems like this would be executed upon git merge, whereas I would like the merge tool to be chosen upon git mergetool.

It seems like there must be some way to specify this with .gitattributes, but I can't seem to figure out how. Any advice?

like image 736
elsevers Avatar asked Apr 26 '14 16:04

elsevers


1 Answers

One solution (since my old answer isn't a good fit for mergetool) is to set as a mergetool a wrapper script.

git config --global merge.tool customMergeTool
git config --global mergetool.customMergeTool.cmd 'customMergeTool.sh \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'

That wrapper script customMergeTool.sh would:

  • check what $BASE is (in particular, its file extension)
  • call the appropriate merge tool based on that extension
  • return the exit status of that mergetool

Here is for instance the script that the OP elsevers came up with: merge-wrapper.

like image 174
VonC Avatar answered Oct 25 '22 08:10

VonC