Git custom merge driver with fallback to the built-in driver

Viewed 668

I have a custom merge driver for a type of text file with a specific layout. (It solves basically the same problem as git-merge-changelog: when things are added at the same place, I have rules to decide in in what order to put them.)

This merge driver is based on heuristics and sometimes fails when the changes are too complex. When it fails, I want to fall back to git's default handling of text files.

I've set up .gitattributes:

myfile merge=my-driver

and .gitconfig:

[merge "my-driver"]
    name = My merge driver for myfile
    driver = my-merge-driver %O %A %B

This is fine when my custom merge driver is able to resolve the conflicts. When the driver program can't resolve the conflicts, it returns a non-zero code and doesn't modify %A. This causes git to report a conflict (good), but to leave the current version of the file in place. Instead, I want git to run the built-in text merge driver.

How can I use my custom merge driver, but if it fails, use the built-in driver as a fallback?

1 Answers
Related