3

I'm using git mergetool with beyondcompare4 for solving git merge conflicts. In my project files I often have tags for date/time/version-list that always gives me an merge conflict. I would like to automate the resolutions of those conflicts. For e.g. selecting the latest date, or highest version number (there's a clear logic that i could script).

How could I achieve it?

Here's what i tried so far:

  • I tried to look for the git hook, but found none that fits my purpose. There's nothing like pre-merge hook

  • I wrote powershell script that loops through the merge conflicts, solves them according to my logic, and stages the changes. It works well if it's the only conflict within the file. If there are more conflicts, I cannot stage the changes, since it will stage conflicts as well. On another hand, if I run git mergetool after executing my script, BC4 ignores the changes the script have done, and shows those lines as conflicts.

  • Looked for possibilities to run custom script using BC4 but it seems it does not have such a feature.

Any help appreciated,

Gintautas

Gintautas
  • 33
  • 3
  • 1
    Doing this at `git mergetool` time is later than you should; the place to do them is earlier, in a *merge driver*. See https://stackoverflow.com/q/44212642/1256452 – torek Mar 09 '19 at 00:56
  • If I understand it correctly, custom merge driver completely overrides standard default merge driver. Meaning, I have to deal with all merge conflicts, not only the ones I want to fix automatically. Right? – Gintautas Mar 09 '19 at 16:47
  • 1
    Yes. Fortunately, Git provides `git merge-file`, which implements the same low-level merge as the built in merge driver. So you can read the three inputs, find which input(s) have resolveable dateinfo conflicts, put the desired dateinfo into updated input files, and then run `git merge-file` on those updated inputs. (Here the word "dateinfo" is meant to cover your "date/time/version-list" combination.) – torek Mar 09 '19 at 17:51
  • 1
    This solution has some issues; in particular you don't get the `-X` extended flags. The merge driver code in Git really could use more %-directives. – torek Mar 09 '19 at 17:52

0 Answers0