Using visual studio code as the default git difftool

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
thenewlinuxmint

Using visual studio code as the default git difftool

Post by thenewlinuxmint »

https://stackoverflow.com/a/36644561

on linux mint, when following this solution and using `git difftool` in a git repository, only $LOCAL is shown correctly. both $LOCAL and $REMOTE are opened in tabs in a new visual studio code window. the $REMOTE tab doesn't have any content.

Any ideas on how to get the answer's correct behavior on linux mint?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
gm10

Re: Using visual studio code as the default git difftool

Post by gm10 »

I'd put the variables in double quotes.
thenewlinuxmint

Re: Using visual studio code as the default git difftool

Post by thenewlinuxmint »

gm10 wrote: Sat Jul 14, 2018 8:34 pm I'd put the variables in double quotes.
Unfortunately that did not work :(
gm10

Re: Using visual studio code as the default git difftool

Post by gm10 »

did you install Code as a flatpak? might have to adjust the command line then.
thenewlinuxmint

Re: Using visual studio code as the default git difftool

Post by thenewlinuxmint »

gm10 wrote: Sat Jul 14, 2018 9:37 pm did you install Code as a flatpak? might have to adjust the command line then.
Yes it's a flatpak, how do you suggest it should change?
gm10

Re: Using visual studio code as the default git difftool

Post by gm10 »

thenewlinuxmint wrote: Sun Jul 15, 2018 2:22 pm
gm10 wrote: Sat Jul 14, 2018 9:37 pm did you install Code as a flatpak? might have to adjust the command line then.
Yes it's a flatpak, how do you suggest it should change?
I don't know, I don't have the flatpak version, I use the normal one. I don't have a single flatpak application installed actually so I'm not sure how they get launched. See how your menu entry does it. Or just try first if you can execute this from the command line (with $LOCAL and $REMOTE replaced by two text files to diff):

Code: Select all

code --wait --diff $LOCAL $REMOTE
thenewlinuxmint

Re: Using visual studio code as the default git difftool

Post by thenewlinuxmint »

gm10 wrote: Sun Jul 15, 2018 2:32 pm
thenewlinuxmint wrote: Sun Jul 15, 2018 2:22 pm
gm10 wrote: Sat Jul 14, 2018 9:37 pm did you install Code as a flatpak? might have to adjust the command line then.
Yes it's a flatpak, how do you suggest it should change?
I don't know, I don't have the flatpak version, I use the normal one. I don't have a single flatpak application installed actually so I'm not sure how they get launched. See how your menu entry does it. Or just try first if you can execute this from the command line (with $LOCAL and $REMOTE replaced by two text files to diff):

Code: Select all

code --wait --diff $LOCAL $REMOTE
thanks for the debugging tip. this is what the command would look like

flatpak run com.visualstudio.code --wait --diff file1 file2

It seems to run perfectly when run from the command line!
gm10

Re: Using visual studio code as the default git difftool

Post by gm10 »

Great, so instead of

Code: Select all

[difftool "default-difftool"]
    cmd=code --wait --diff $LOCAL $REMOTE
it will have to be

Code: Select all

[difftool "default-difftool"]
    cmd=flatpak run com.visualstudio.code --wait --diff $LOCAL $REMOTE
then and it should work. You may want to add --new-window to the parameters as well to open the diff in a window of its own, depending on your preference.
thenewlinuxmint

Re: Using visual studio code as the default git difftool

Post by thenewlinuxmint »

gm10 wrote: Sun Jul 15, 2018 3:16 pm Great, so instead of

Code: Select all

[difftool "default-difftool"]
    cmd=code --wait --diff $LOCAL $REMOTE
it will have to be

Code: Select all

[difftool "default-difftool"]
    cmd=flatpak run com.visualstudio.code --wait --diff $LOCAL $REMOTE
then and it should work. You may want to add --new-window to the parameters as well to open the diff in a window of its own, depending on your preference.
Sorry, I should have mentioned that is what my gitconfig was set to originally.

It seems like $LOCAL opens fine, but $REMOTE opens a file "/tmp/******_filename", where the 6 stars seem to be a random combination of characters and numbers
gm10

Re: Using visual studio code as the default git difftool

Post by gm10 »

thenewlinuxmint wrote: Sun Jul 15, 2018 3:23 pm Sorry, I should have mentioned that is what my gitconfig was set to originally.

It seems like $LOCAL opens fine, but $REMOTE opens a file "/tmp/******_filename", where the 6 stars seem to be a random combination of characters and numbers
You should. Nevermind. The file naming is normal, it's how git works, the random letters are to distinguish the commits. Actually both $LOCAL and $REMOTE will look like this is. In VS Code you should see something like this:
gitdiff.png
And you're saying that $REMOTE ends up being empty or? Maybe check your /tmp folder in a file browser to see what gets written there. Note that files only exist while VS Code remains open, they get removed again afterwards.
thenewlinuxmint

Re: Using visual studio code as the default git difftool

Post by thenewlinuxmint »

gm10 wrote: Sun Jul 15, 2018 3:35 pm
thenewlinuxmint wrote: Sun Jul 15, 2018 3:23 pm Sorry, I should have mentioned that is what my gitconfig was set to originally.

It seems like $LOCAL opens fine, but $REMOTE opens a file "/tmp/******_filename", where the 6 stars seem to be a random combination of characters and numbers
You should. Nevermind. The file naming is normal, it's how git works, the random letters are to distinguish the commits. Actually both $LOCAL and $REMOTE will look like this is. In VS Code you should see something like this:
gitdiff.png
And you're saying that $REMOTE ends up being empty or? Maybe check your /tmp folder in a file browser to see what gets written there. Note that files only exist while VS Code remains open, they get removed again afterwards.
Yes $REMOTE ends up being empty when I view it in visual studio code.

However when I view the file with cat, it outputs correctly
gm10

Re: Using visual studio code as the default git difftool

Post by gm10 »

That's weird. Is the filename shown in Code identical to the one on disk then? Usually an empty document in Code means the file couldn't be found.
You could also try opening code for the diff directly while the original failed diff is still open (i.e. while the /tmp/ files are still in place) and see if that works or if there's something else wrong with the files.

I don't really know. It's working flawlessly on my end, only difference is no flatpak. If the repo isn't too big I could clone it myself and test on my end, post the link and the failing git difftool command you're using then.
Locked

Return to “Software & Applications”