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?

theycallmemorty
  • 11,427
  • 12
  • 47
  • 68
  • Would having an intermediate script help? As in http://stackoverflow.com/questions/3780420/is-it-possible-to-use-winmerge-to-view-git-diffs-from-cygwin/4314057#4314057 – VonC Dec 14 '10 at 13:39
  • are you able to run the diffmerge command in a terminal outside of using git? – brycemcd Dec 14 '10 at 16:04
  • 1
    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)? – Chris Burgess Dec 19 '10 at 23:39
  • 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) – catsby Jan 10 '11 at 15:38

1 Answers1

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"'
Brian Campbell
  • 289,867
  • 55
  • 346
  • 327
  • Wow awesome, looks like the only other option is to use the paid Git mergetools. Works great, thanks. – Amala Apr 29 '11 at 17:49
  • 2
    Awesome tip Brian! I've incorporated it into my Git/DiffMerge setup HOWTO: http://twobitlabs.com/2011/08/install-diffmerge-git-mac-os-x/ – ToddH Aug 18 '11 at 19:57