git with Beyond Compare (4) on WSL2 Windows 11 not opening the repo version
Asked Answered
Z

3

8

Trying to get git and Beyond Compare to place nicely together on WSL. Here is the output from git config --list:

diff.tool=bc3
difftool.prompt=false
difftool.bc3.path=/mnt/c/Program Files/Beyond Compare 4/BComp.exe
merge.tool=bc3
mergetool.prompt=false
mergetool.bc3.trustexitcode=true
mergetool.bc3.path=/mnt/c/Program Files/Beyond Compare 4/BComp.exe

Here is my ~/.gitconfig:

[diff]
    tool = bc3
[difftool]
    prompt = false
[difftool "bc3"]
    path = /mnt/c/Program Files/Beyond Compare 4/BComp.exe
[merge]
    tool = bc3
[mergetool]
    prompt = false
[mergetool "bc3"]
    trustExitCode = true
    path = /mnt/c/Program Files/Beyond Compare 4/BComp.exe

my git --version is:

git version 2.25.1

When I try git difftool file_in_git_repo Beyond Compare opens with the current version in the left pane, but nothing in the right pane (I have confirmed the file exists in the git repo.)

.git/config has no entries referencing diff or merge

Any suggestions would be most welcome

========================================================================

Similar to VonC's suggestion, I was able to get it working with this in my .gitconfig file (disclaimer - I have not used the mergetool with this new method):

[diff]
    tool = bc3
[difftool]
    prompt = false
[difftool "bc3"]
    cmd = '/mnt/c/Program Files/Beyond Compare 4/BComp.exe'   \"$(wslpath -aw $LOCAL)\" \"$(wslpath -aw $REMOTE)\"
[merge]
    tool = bc3
[mergetool]
    prompt = false
[mergetool "bc3"]
    trustExitCode = true
    cmd = '/mnt/c/Program Files/Beyond Compare 4/BComp.exe'   \"$(wslpath -aw $LOCAL)\" \"$(wslpath -aw $REMOTE)\"
Zoo answered 12/2, 2022 at 16:39 Comment(0)
H
10

Check if this configuration might work in your case:

I managed to get it working using the built-in wslpath command which comes with new WSL versions!

My git config on WSL linux side:

difftool.bc3.cmd=BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)"
mergetool.bc3.cmd=BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)" "$(wslpath -aw $BASE)" "$(wslpath -aw $MERGED)"

BComp.exe is in my $PATH.
I'm using WSL2 on Windows version 2004 (build 19041), and this works both inside the WSL filesystem and also for the mounted Windows filesystem.

The new wslpath -aw converts the Linux paths like this:

$ wslpath -aw /home/
\\wsl$\Debian\home

And Windows paths like this:

$ wslpath -aw /mnt/c/Users/
C:\Users

This makes them both work perfectly with the Windows version of BC when launched from Linux.

Hysteric answered 12/2, 2022 at 22:58 Comment(0)
C
7

Using the accepted answer here and this article as references I was able to arrive at a working solution for Windows 11 + WSL2 + Ubuntu with Beyond Compare 4.

From a WSL prompt I edit the Git global config like this:

git config --global --edit

I then make sure the config has lines that look like this:

[diff]
    tool = bc
    guitool = bc
[difftool "bc"]
    path = /mnt/c/Program\\ Files/Beyond\\ Compare\\ 4/bcomp.exe
    cmd = /mnt/c/Program\\ Files/Beyond\\ Compare\\ 4/bcomp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)"
    trustExitCode = true
[difftool]
    prompt = false
[merge]
    tool = bc
    guitool = bc
[mergetool "bc"]
    path = /mnt/c/Program\\ Files/Beyond\\ Compare\\ 4/bcomp.exe
    cmd = /mnt/c/Program\\ Files/Beyond\\ Compare\\ 4/bcomp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)" "$(wslpath -aw $BASE)" "$(wslpath -aw $MERGED)"
    trustExitCode = true
[mergetool]
    prompt = false

Adjust flags such as "prompt" to your taste.

Cageling answered 27/1 at 19:48 Comment(0)
R
3

VonC's solution got me most of the way there, but didn't seem to work with dir-diff i.e. git difftool -d. For that to work I needed to add the following to the .gitconfig on the WSL2 side.

[core]
    symlinks = false

Alternately you can run git difftool -d --no-symlinks

Reger answered 4/3, 2023 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.