martinvonz / jj

A Git-compatible VCS that is both simple and powerful
https://martinvonz.github.io/jj/
Apache License 2.0
9.4k stars 323 forks source link

jj describe uses invalid path when called from git bash on windows #3474

Open andreasWallner opened 7 months ago

andreasWallner commented 7 months ago

Description

When calling jj describe on a windows machine from git bash it tries to use an invalid path containing a '?'. It seems to mix up windows/unix paths.

Steps to Reproduce the Problem

  1. Open git bash, navigate to a path of your choice (in my case /c/work/git/test which corresponds to C:\work\git\test)
  2. jj git init
  3. jj config set --repo ui.editor vim
  4. jj describe

Note that the path passed to vim is /c/?C:workgittest.jjrepoeditor-IurIAZ.jjdescription instead of the expected /c/work/git/test/.jj/repo/editor....jjdescription. With the editor set to notepad everything works as expected.

Expected Behavior

vim should be opened with the correct path, git bash seems to do some conversion so /c/work/git/... and C:\work\git\... both work from the terminal - I don't know whether they work when using e.g. std::process::Command.

Actual Behavior

vim is called with a mixed unix/windows path with what seems like encoding issues.

Specifications

yuja commented 7 months ago

From discord comment:

I solved my problem by giving vim.exe an option(--literal) to suppress wildcard expansion like ui.editor = [ "C:/Users/hymkor/scoop/apps/vim/current/gvim.exe" , "--literal" ].

Maybe this is the problem you faced? Not all Windows tools can process \\? path. https://doc.rust-lang.org/std/fs/fn.canonicalize.html

andreasWallner commented 7 months ago

I tried this and it does not help. What you posted (\\?) does look like a UNC path (even though I've never seen it with a question mark before), which does not seem to be the issue here. If you look at the path that vim is being called with it starts with /c/ in unix style (maybe due to being called in the git mingw shell), and then continues with ?C:workgit... which seems to be a messed up version of the windows path C:/work/git...

To check if vim is the issue here, I changed my config to call echo:

ui.editor = ["echo", "--literal"]

Then calling jj describe prints:

$ jj describe
--literal \?C:workgittest.jjrepoeditor-m5ehy4.jjdescription

Slightly different, but also messed up.

yuja commented 7 months ago

I don't know which version of echo is used, and if cmd.exe's echo supports escape syntax, but looks like \ is translated somewhere. If echo and vim are installed as MSYS binaries, MSYS might be the root cause.

mlcui-corp commented 5 months ago

This is due to Git Bash (MSYS?). I've personally encountered this too when running commands like less from a Git Bash installation from outside of it.

The issue with UNC paths in general is indeed an issue with some other programs - see #3986 - but specifically for this issue, I would personally recommend using a non-Git Bash shell / program for jj usage.