git difftool --dir-diff is not creating temp files for Beyond Compare 3 to use
Asked Answered
T

4

28

I'm trying to use git's new (as of git 1.7.11) directory diff command with Beyond Compare 3 as the difftool, but the temporary files are not being created.

For example:

git difftool --dir-diff <branch1> <branch2>

Beyond Compare opens a directory comparison with the correct directories and changed files listed.

However, when I click on any of the files I get the following error:

Unable to load C:\Users\<username>\AppData\Local\Temp\git-difftool.yG8V5\left\<path to some file>: The system cannot find the path specified

So, I check to see if the C:\Users\<username>\AppData\Local\Temp\git-difftool.yG8V5 directory exists and it doesn't.

Beyond Compare 3 works fine as the difftool for non-directory diffs and merges.

I'm using git for Windows (msysgit) 1.8.0.

Here are the relevant .gitconfig settings:

# External Visual Diff/Merge Tool
[diff]
    tool = bc3

[difftool "bc3"]
    path = "C:/Program Files (x86)/Beyond Compare 3/BComp.exe"

[merge]
    tool = bc3

[mergetool "bc3"]
    keepTemporaries = false
    trustExitCode = true
    keepBackup = false
    path = "C:/Program Files (x86)/Beyond Compare 3/BComp.exe"
Thaler answered 9/11, 2012 at 15:32 Comment(1)
It appears that the issue is that Beyond Compare isn't holding the console session (BComp.exe) open when launched with the --dir-diff flag, so Git is deleting the temp directory before BC can read it. According to the BeyondCompare commandline reference, BComp.exe has special behavior when launched from a version control system. I suspect whatever it's using for inference is broken with this flag.Appoggiatura
A
31

There is a solution described here. Basically, if you modify your .gitconfig to use BCompare.exe instead of BComp.exe, the console session will remain open until the Beyond Compare window is closed.

Modify your .gitconfig settings to read:

# External Visual Diff/Merge Tool
[diff]
    tool = bc3

[difftool "bc3"]
    path = "C:/Program Files (x86)/Beyond Compare 3/BCompare.exe"
Appoggiatura answered 30/11, 2012 at 0:31 Comment(2)
This works for me. However, instruction on beyond compare website is wrongBagehot
This did not work for me ("unknown tool"). So, instead of path = ... I got it working with cmd = C:/path/to/bcompare.exe \"$LOCAL\" \"$REMOTE\"Video
P
6

Answer from Scott Wegner is have small drawback - if you try to run 2 compares simultaneously, second will not work. This is because BCompare.exe do not run second application instance and so, close started process too early.

Sadly, BCompare.exe does not understand /solo command line option, so I write small bat file in Beyond Compare 3 installation directory:

C:\Program Files (x86)\Beyond Compare 3\BCompD.bat

start /wait "" "%~dp0/bcomp.exe" %* /solo

and use it as tool

[difftool "bc3dir"]
    path = C:/Program Files (x86)/Beyond Compare 3/bcompd.bat
    cmd = \"C:/Program Files (x86)/Beyond Compare 3/bcompd.bat\" \"$LOCAL\" \"$REMOTE\"

I do not use this as default diff tol, so I name it bc3dir and use like next:

git difftool --dir-diff --tool=bc3dir 760be6d47d35b42a6a2409636b40a5521361e72f^ 760be6d47d35b42a6a2409636b40a5521361e72f
Pack answered 27/2, 2017 at 8:12 Comment(2)
Nice wrapper for BC. +1Ardyth
the bcompare.exe /solo option works fine with the BC 3.1.9, so did not have to use a batch file. To integrate this with git difftool, I had to use it as -solo, since the sh.exe would otherwise interpret that as a pathClematis
C
6

I tried @ScottWegner's answer, but it only works when Beyond Compare is not already running. I found the solution with the help of @SergeyAzarkevich 's answer. This is what I did in my .gitconfig

[diff]
    tool = bc3
[difftool]
    prompt = false
[difftool "bc3"]
    cmd = \"c:/program files (x86)/beyond compare 3/bcompare.exe\" -solo \"$LOCAL\" \"$REMOTE\"

Notice the -solo. This causes Beyond Compare to spawn a new instance of the program.

On windows, we should be using the /solo option, but since git difftool command, spawns sh.exe to process its command-line, the /solo option was getting incorrectly interpreted as a path. So I have to use it as -solo

With this option, I run start git difftool --dir-diff, so this will free up my command prompt, and a new prompt will continue waiting for the new instance of Beyond Compare to exit. This will also make sure that the temp files/folders created by git will continue to live till the diff tool exits.

Clematis answered 4/9, 2018 at 18:15 Comment(0)
A
3

Note that you have another case where git difftool --dir-diff might misbehave.

"git difftool --dir-diff" had a minor regression when started from a subdirectory, which has been fixed with Git 2.12 (Q1 2017).

See commit 853e10c (07 Dec 2016) by David Aguilar (davvid).
(Merged by Junio C Hamano -- gitster -- in commit afe0e2a, 19 Dec 2016)

difftool: fix dir-diff index creation when in a subdirectory

9ec26e7 (difftool: fix argument handling in subdirs, 2016-07-18, Git 2.9.3) corrected how path arguments are handled in a subdirectory, but it introduced a regression in how entries outside of the subdirectory are handled by dir-diff.

When preparing the right-side of the diff we only include the changed paths in the temporary area.
The left side of the diff is constructed from a temporary index that is built from the same set of changed files, but it was being constructed from within the subdirectory.
This is a problem because the indexed paths are toplevel-relative, and thus they were not getting added to the index.

Teach difftool to chdir to the toplevel of the repository before preparing its temporary indexes.
This ensures that all of the toplevel-relative paths are valid.

Ardyth answered 23/12, 2016 at 23:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.