git-mergetool
invokes a three-way merge tool - that is, a tool that produces a merge result from two branches and the common ancestor. There are four files in all - three input files and an output file.
However, you are invoking the mergetool
with only three inputs: the two branches and the merge result. Thus, it is using the merge result as the common ancestor - the file that git-merge
has written the merge file (with conflict markers). Instead, you need to invoke your merge tool with the two sides ($LOCAL
, $REMOTE
) and the common ancestor $BASE
, telling it to place the merge result into $MERGED
.
Your 3-way merge tool should be capable of actually distinguishing between the common ancestor and the output file. You should talk to your tool's author to determine if this is true and suggest to them that their tool is deficient if they cannot.
If you really love your deficient merge tool, however, you can create a script that:
- Copies
$BASE
to a temporary file - Invokes the three-way merge tool using the
$LOCAL
,$REMOTE
and the temporary file - Checks the exit code for success and on a successful merge, copies the temporary file to
$MERGED
- Returns the exit code from the merge tool