Problem with git + DiffMerge on OS X
Asked Answered
P

1

8

I have configured Sourcegear DiffMerge to be my default git merge tool using the following instructions:

git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "diffmerge \"\$LOCAL\" \"\$REMOTE\""

git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd "diffmerge --merge --result=\"\$MERGED\"
\"\$LOCAL\" \"\$BASE\" \"\$REMOTE\""
git config --global mergetool.diffmerge.trustexitcode false

Source: http://www.andrejkoelewijn.com/wp/2010/01/08/configure-diffmerge-with-git/

However when I run git mergetool I get the following error:

DiffMerge Error

What could be the cause of this issue?

Pazpaza answered 14/12, 2010 at 12:43 Comment(4)
Would having an intermediate script help? As in #3780920Latticework
are you able to run the diffmerge command in a terminal outside of using git?Dirigible
I see the same thing. The BASE file does not exist on the local filesystem, but the other files referenced in the diffmerge commandline (in your case, 10new.xml.REMOTE.2128.xml and 10new.xml.LOCAL.2128.xml) do exist. An issue with DiffMerge's expectations of Git behaviour (possibly Git version behaviour)?Glick
I'm unable to reproduce this, what version of Git and Diffmerge do you have? I have git version 1.7.3.4, DiffMerge 3.3.0 (1001)Adriell
H
8

It is possible that there will be no $BASE file, if for instance the two files being merged have no common ancestor, or if you happen to get the conflict when applying or rebasing a patch rather than merging branches. In this case, while the $BASE variable will still be set, there will be no file there.

In your mergetool command, you need to check whether $BASE exists, and do a merge without a common ancestor if it does not. It doesn't look like DiffMerge supports that mode (it supports merging two files with no common ancestor, but it always writes the output to one of the files, not a result file). Instead, you'll need instead to pass in $LOCAL as the $BASE file if $BASE does not exist:

git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
Hotfoot answered 18/4, 2011 at 17:53 Comment(2)
Wow awesome, looks like the only other option is to use the paid Git mergetools. Works great, thanks.Surrey
Awesome tip Brian! I've incorporated it into my Git/DiffMerge setup HOWTO: twobitlabs.com/2011/08/install-diffmerge-git-mac-os-xHayton

© 2022 - 2024 — McMap. All rights reserved.