JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.38k stars 2.38k forks source link

Git segment does not work within WSL shared folder #1396

Closed mmalolepszy closed 2 years ago

mmalolepszy commented 2 years ago

Code of Conduct

What happened?

When working in WSL shared folder git command executed is:

git.exe -C /mnt/c/<my_repo_folder>/ --no-optional-locks -c core.quotepath=false -c color.status=false status -unormal --branch --porcelain=2

this command fails with

fatal: cannot change to '/mnt/c/<my_repo_folder>/': No such file or directory

The issue is that when git segment falls back to using git.exe instead of linux git it should also translate the path to Windows style path.

This command runs perfectly fine even when it is run in WSL bash:

git.exe -C c:/<my_repo_folder>/ --no-optional-locks -c core.quotepath=false -c color.status=false status -unormal --branch --porcelain=2

Theme

This can be reproduced on a default jandedobbeleer.omp.json theme

What OS are you seeing the problem on?

Windows

Which shell are you using?

bash

Log output

Version: 6.28.2

Segments:

ConsoleTitle(true)   -   1 ms - uni in <my_repo_folder>
session(true)        -   0 ms -  <my_username> 
path(true)           -   0 ms -    <my_repo_folder> 
git(true)            -  78 ms -   ≢ 
node(false)          -   4 ms -
go(false)            -   1 ms -
julia(false)         -   0 ms -
python(false)        -   2 ms -
ruby(false)          -   1 ms -
azfunc(false)        -   0 ms -
aws(false)           -   1 ms -
root(false)          -   0 ms -
executiontime(true)  -   0 ms -  ﮫ0ms⠀
exit(true)           -   0 ms -   
shell(true)          -   0 ms -   uni 
ytm(false)           -   0 ms -
battery(true)        -   0 ms -   100 
time(true)           -   0 ms -  10:06:08 

Run duration: 97.4984ms

Logs:

2021/12/09 10:06:08 debug: getenv

2021/12/09 10:06:08 getenv duration: 21.5µs, args: XDG_CACHE_HOME
2021/12/09 10:06:08 getCachePath duration: 34.6µs, args:
2021/12/09 10:06:08 getArgs duration: 100ns, args:
2021/12/09 10:06:08 getArgs duration: 100ns, args:
2021/12/09 10:06:08 getShellName duration: 500ns, args:
2021/12/09 10:06:08 debug: getenv

2021/12/09 10:06:08 getenv duration: 2.3µs, args: OMP_CACHE_DISABLED
2021/12/09 10:06:08 isRunningAsRoot duration: 1.5µs, args:
2021/12/09 10:06:08 getcwd duration: 1.0329ms, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getShellName duration: 200ns, args:
2021/12/09 10:06:08 getCurrentUser duration: 400ns, args:
2021/12/09 10:06:08 getHostName duration: 2.9µs, args:
2021/12/09 10:06:08 getcwd duration: 600ns, args:
2021/12/09 10:06:08 debug: getenv

2021/12/09 10:06:08 getenv duration: 3.9µs, args: SSH_CONNECTION
2021/12/09 10:06:08 debug: getenv

2021/12/09 10:06:08 getenv duration: 4.8µs, args: SSH_CLIENT
2021/12/09 10:06:08 getCurrentUser duration: 700ns, args:
2021/12/09 10:06:08 getRuntimeGOOS duration: 100ns, args:
2021/12/09 10:06:08 getHostName duration: 4µs, args:
2021/12/09 10:06:08 isRunningAsRoot duration: 1.5µs, args:
2021/12/09 10:06:08 getcwd duration: 600ns, args:
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getArgs duration: 100ns, args:
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getRuntimeGOOS duration: 400ns, args:
2021/12/09 10:06:08 getRuntimeGOOS duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 300ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 200ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 getRuntimeGOOS duration: 0s, args:
2021/12/09 10:06:08 getcwd duration: 300ns, args:
2021/12/09 10:06:08 getRuntimeGOOS duration: 200ns, args:
2021/12/09 10:06:08 debug: getenv
Ubuntu
2021/12/09 10:06:08 getenv duration: 5.7µs, args: WSL_DISTRO_NAME
2021/12/09 10:06:08 isWsl duration: 26.7µs, args:
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 debug: runCommand
5.10.16.3-microsoft-standard-WSL2
2021/12/09 10:06:08 runCommand duration: 1.9986ms, args: uname -r
2021/12/09 10:06:08 hasCommand duration: 28.0041ms, args: git.exe
2021/12/09 10:06:08 getcwd duration: 200ns, args:
2021/12/09 10:06:08 hasParentFilePath duration: 892.8µs, args: .git
2021/12/09 10:06:08 error: runCommand
exit status 128
2021/12/09 10:06:08 runCommand duration: 41.975ms, args: git.exe -C /mnt/c/<my_repo_folder>/ --no-optional-locks -c core.quotepath=false -c color.status=false status -unormal --branch --porcelain=2
2021/12/09 10:06:08 hasFolder duration: 870.5µs, args: /mnt/c/<my_repo_folder>/.git/rebase-merge
2021/12/09 10:06:08 hasFolder duration: 600.2µs, args: /mnt/c/<my_repo_folder>/.git/rebase-apply
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFilesInDir duration: 594.8µs, args: MERGE_MSG
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFilesInDir duration: 532.8µs, args: CHERRY_PICK_HEAD
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFilesInDir duration: 524.1µs, args: REVERT_HEAD
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFilesInDir duration: 513.4µs, args: sequencer/todo
2021/12/09 10:06:08 error: getFileContent
open /mnt/c/<my_repo_folder>/.git/logs/refs/stash: no such file or directory
2021/12/09 10:06:08 getFileContent duration: 2.7641ms, args: /mnt/c/<my_repo_folder>/.git/logs/refs/stash
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 200ns, args:
2021/12/09 10:06:08 hasFiles duration: 1.7825ms, args: *.js
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFiles duration: 1.276ms, args: *.ts
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 199.5µs, args: package.json
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 151.1µs, args: .nvmrc
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFiles duration: 145.7µs, args: pnpm-workspace.yaml
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFiles duration: 142.8µs, args: .pnpmfile.cjs
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 143.2µs, args: .npmrc
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 927.5µs, args: *.go
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFiles duration: 168.2µs, args: go.mod
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFiles duration: 876.1µs, args: *.jl
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFiles duration: 931.6µs, args: *.py
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 868.8µs, args: *.ipynb
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFiles duration: 147.2µs, args: pyproject.toml
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFiles duration: 138.9µs, args: venv.bak
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 133.1µs, args: venv
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 137.1µs, args: .venv
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 100ns, args:
2021/12/09 10:06:08 hasFiles duration: 881.4µs, args: *.rb
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 136.2µs, args: Rakefile
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 134.1µs, args: Gemfile
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 132.4µs, args: host.json
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 136.2µs, args: local.settings.json
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getPathSeperator duration: 0s, args:
2021/12/09 10:06:08 hasFiles duration: 136.2µs, args: function.json
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 debug: getenv

2021/12/09 10:06:08 getenv duration: 1.1µs, args: AWS_VAULT
2021/12/09 10:06:08 debug: getenv

2021/12/09 10:06:08 getenv duration: 600ns, args: AWS_PROFILE
2021/12/09 10:06:08 debug: getenv

2021/12/09 10:06:08 getenv duration: 600ns, args: AWS_REGION
2021/12/09 10:06:08 debug: getenv

2021/12/09 10:06:08 getenv duration: 600ns, args: AWS_DEFAULT_REGION
2021/12/09 10:06:08 debug: getenv

2021/12/09 10:06:08 getenv duration: 600ns, args: AWS_CONFIG_FILE
2021/12/09 10:06:08 error: getFileContent
open /home/<my_user_name>/.aws/config: no such file or directory
2021/12/09 10:06:08 getFileContent duration: 1.5349ms, args: /home/<my_user_name>/.aws/config
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 isRunningAsRoot duration: 1.2µs, args:
2021/12/09 10:06:08 getcwd duration: 0s, args:
2021/12/09 10:06:08 executionTime duration: 200ns, args:
2021/12/09 10:06:08 getcwd duration: 200ns, args:
2021/12/09 10:06:08 lastErrorCode duration: 100ns, args:
2021/12/09 10:06:08 getcwd duration: 200ns, args:
2021/12/09 10:06:08 getShellName duration: 200ns, args:
2021/12/09 10:06:08 getcwd duration: 200ns, args:
2021/12/09 10:06:08 error: doGet
Get "http://127.0.0.1:9863/query": dial tcp 127.0.0.1:9863: connect: connection refused
2021/12/09 10:06:08 doGet duration: 275.3µs, args: http://127.0.0.1:9863/query
2021/12/09 10:06:08 getcwd duration: 100ns, args:
2021/12/09 10:06:08 getBatteryInfo duration: 682.5µs, args:
2021/12/09 10:06:08 getcwd duration: 200ns, args:
mmalolepszy commented 2 years ago

I suppose this is a regression caused by this commit: https://github.com/JanDeDobbeleer/oh-my-posh/commit/2733865edf050e4e47f899cdb0bec45916a242ff

lnu commented 2 years ago

It's related to the recent refactor of the git segment. Let's check where it comes from.

JanDeDobbeleer commented 2 years ago

@lnu I didn't adjust that part though.

lnu commented 2 years ago

If i build this commit 4f921dbb0f94cd68757360a94b15cc51b205b305 it works as expected and worktree Folder is empty. With the latest version worktree is set.

So it comes from here: https://github.com/JanDeDobbeleer/oh-my-posh/blob/adb49d1cd0b15de9adc5415809cec0611868ae1d/src/segment_git.go#L146 g.gitWorktreeFolder is always initialized event when not in a worktree. It was not the case before: image

lnu commented 2 years ago

https://github.com/JanDeDobbeleer/oh-my-posh/pull/1398

JanDeDobbeleer commented 2 years ago

@lnu aha! That's because doing this I didn't have a status when referencing another directory than the one I'm in. But I'll approve :-)

lnu commented 2 years ago

you're right, let's see how to fix this

lnu commented 2 years ago

If I remember well, we did that to speed up things but in the end, it should be clear that no one should use git in wsl2 and windows mounted folders. The rule should be:

this way it will be fast everywhere except when using mounted folder in wsl2.

I don't think it's up to omp to try to solve that, can of worms ahead.

What do you think @JanDeDobbeleer ?

JanDeDobbeleer commented 2 years ago

@lnu I agree. We can't solve problems outside of our control.

github-actions[bot] commented 7 months ago

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.