Skip to contentSkip to conversation

git difftool does not work with Windows kdiff3

Cygwin 1.7 David Aguilar 1 participant 1 message Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

I added the git list to the CC: list.

Quoted 37 lines · David Antliff

git-mergetool works very well with a native Windows (i.e. not Cygwin) installation of kdiff3 because it creates its working files in the current working directory, usually called ./<original-file>.LOCAL.xxxx.<ext> and ./<original-file>.REMOTE.xxxx.<ext>. Because these paths are relative to the CWD, the non-Cygwin version of kdiff3 handles this fine. E.g:

kdiff3 --auto --L1 build.xml (Base) --L2 build.xml (Local) --L3 build.xml (Remote) -o build.xml ./build.xml.BASE.5512.xml ./build.xml.LOCAL.5512.xml ./build.xml.REMOTE.5512.xml

But git-difftool does something slightly different - it creates the temporary versions of the file in /tmp with a random prefix, e.g. /tmp/Vc0BZy_<original-file>. This causes the Windows version of kdiff3 to fail to open the file, because the path "/tmp/...." is invalid. In my case, the path that would work is "c:/cygwin-1.7/tmp/..." instead:

kdiff3 --auto --L1 "build.xml (A)" --L2 "build.xml (B)" /tmp/Vc0BZy_build.xml build.xml

It's the /tmp/... bit that kdiff3 can't understand. On the other hand, this command does work:

kdiff3 --auto --L1 "build.xml (A)" --L2 "build.xml (B)" c:/cygwin-1.7/tmp/Vc0BZy_build.xml build.xml

Perhaps git-difftool should create the temporary file in CWD just like git-mergetool, rather than the Cygwin-specific path /tmp?

I'm using the Windows version of kdiff3 to avoid dependency on the graphical X libraries that Cygwin's kdiff3 would require. I think it's a fairly common thing to do when working with git on Windows. I can see that the Cygwin version of kdiff3 would probably not exhibit this problem.

Quoted 8 lines

I imagine the same problem will occur with other Windows versions of merge/diff tools.

I also understand if there's no intention by the Cygwin git maintainer to support non-Cygwin gui merge tools, but I don't think I'm the only person using them extensively.

-- David.

git-difftool is built on top of git's GIT_EXTERNAL_DIFF mechanism. So this problem is not specific to difftool.

I don't have a general solution for you but I do have a workaround until a better solution manifests itself.

Here's one workaround:

	$ TMPDIR=.
	$ export TMPDIR

git honors $TMPDIR and that'll make git write files in the current directory.

Likewise, running git difftool should work since the paths handed off to the difftool should be e.g. ./XXXXXX_build.xml.

That said, I don't know if git dereferences the "." thus making the workaround invalid. I haven't tested it.

If that doesn't work then there's another alternative. You could write a simple kdiff3 wrapper script to translate the cygwin paths into Windows-native paths.

Drop it in the front of $PATH and it'll magically work. Otherwise, set the difftool.kdiff3.path configuration variable to the path of the wrapper script and difftool will use your wrapper without it being in $PATH.

I hope that helps for now.

An aside:

I've always tested git-difftool on Windows using msysgit. Windows-native kdiff3 is one of the tools that I've tested and didn't have any problems using msysgit and native kdiff3 together.

cygwin git and msysgit are very different, of course. It's likely that msysgit does a lot more magic to make this possible, but I just wanted to throw that out there.

If anyone knows of a general solution to this problem then I'm all ears.

Good luck and let us know how it goes,

Signature · 1 line
		David