6

I've got a custom git merge driver configured for pom.xml (Maven) files.

The configuration:

The .gitattributes file:

pom.xml merge=pommerge

And the .gitconfig file:

[merge "pommerge"]
    name = A custom merge driver for Maven's pom.xml
    driver = mergepom.py %O %A %B

This works great for resolving conflicts in this kind of file. Unfortunately this doesn't solve all or problems for pom.xml files.. This driver is only called while merging if and only if the pom.xml is changed in both the main branch (so, the branch in which we call 'git merge otherbranch') and the branche we'd like to merge ('otherbranch').

We'd like to always use our merge driver for pom files, even if the pom file is only changed in 1 branch and can be be merged without conflicts.

Is there a way to force our custom 'pommerge' driver in this situation?

Update I've tried almost anything, but without luck. I even checkout out the git source code and added more logging to the code and installed/MAKE'd it to check if I could find out if there was a specific extension point I could use somehow. But the code is pretty hard to understand in which cases which path in the code is followed, so this effort produced more frustations than solutions;)..

The only way I can make it to work, which is not a solution, is to change the file at both ends (branches), before merging.. But this is not very user friendly

I still hope someone comes up with a genius solution or clue which helps me get a little bit further with this challenge.

Thanks you all for your time!

NickGreen
  • 1,742
  • 16
  • 36
  • Could you do something with a git hook, maybe a pre-commit hook that runs mergepom.py on the file if it's modified? – William Hilton Dec 09 '15 at 17:25
  • @WilliamHilton Is the pre-commit hook called while merging? Because the file may be changed and committed: only while merging the file should be partially reverted (specific branch settings). – NickGreen Dec 14 '15 at 09:48
  • OK, I'm stumped. I tried playing around with .gitattributes to mark pom.xml as binary, but still couldn't force git to create a "conflict" when merging branches when the file was only changed on one branch. – William Hilton Dec 14 '15 at 16:29
  • @WilliamHilton thx for trying! That's also what I encountered unfortunately.. – NickGreen Dec 15 '15 at 14:34

1 Answers1

0

What you want is a custom merge strategy, and you have defined a merge driver.

A driver is called only on conflicts, while a strategy is used anytime two commits are merged.

See this answer for how to set up your solution:

https://stackoverflow.com/a/23140455/6084013

Community
  • 1
  • 1
jkuz
  • 131
  • 1
  • 5