oh-my-posh: Git status not working in WSL

Code of Conduct

  • I agree to follow this project’s Code of Conduct

What happened?

Hi,

I was previously running version 7.9.1 and noticed that the Git segment does not render in WSL when targeting a repository folder located on the Windows filesystem.

At first I looked at my custom theme file as it was previously upgraded to v1 format and I already had to correct some migration errors. I then saw that I was on a really old version and then upgraded to version 7.62.3 but the issue is still here.

I made some tests and noticed that:

  • it only happen when the git folder is on the Windows filesystem in /mnt/c/XXX
  • it work as intended if the git folder is in the WSL filesystem

I can see in the debug output that it try to call git.exe with the Windows format path and result in a “not such file or directory” error. The same command using the linux path (/mnt/c/Work/Git/IaC/Ansible/roles/ here) work correctly.

image

Theme

Custom theme file, here is the Git segment configuration

        {
          "background": "#256C9D",
          "foreground": "#ffffff",
          "leading_diamond": "\ue0ba",
          "properties": {
            "fetch_status": true,
            "fetch_stash_count": true,
            "fetch_upstream_icon": true,
            "fetch_worktree_count": true
          },
          "style": "diamond",
          "template": " {{ .UpstreamIcon }}{{ .HEAD }}{{ .BranchStatus }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uF046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \uF692 {{ .StashCount }}{{ end }} ",
          "trailing_diamond": "\ue0bc",
          "type": "git"
        }

What OS are you seeing the problem on?

Linux

Which shell are you using?

bash

Log output

Version: 7.62.3

Segments:

ConsoleTitle(false)  -   0 ms -
os(true)             -   0 ms -  +
session(true)        -   0 ms -  gentoo@JACKSON
time(true)           -   0 ms -   16/04/22  09:55:18
path(true)           -   1 ms -   ›Work›Git›IaC›Ansible›roles 
git(true)            -   7 ms -   ≢ 
kubectl(false)       -  26 ms -
aws(false)           -   0 ms -
dotnet(false)        -  10 ms -
shell(true)          -   0 ms -   bash
exit(true)           -   0 ms -    
root(false)          -   0 ms -
executiontime(false) -   0 ms -

Run duration: 49.492179ms

Cache path: /home/gentoo/.cache/oh-my-posh

Logs:

2022/04/16 09:55:18 Flags duration: 110ns, args:
2022/04/16 09:55:18 Flags duration: 190ns, args:
2022/04/16 09:55:18 debug: Getenv

2022/04/16 09:55:18 Getenv duration: 5.49µs, args: OMP_CACHE_DISABLED
2022/04/16 09:55:18 Root duration: 390ns, args:
2022/04/16 09:55:18 Shell duration: 462.688µs, args:
2022/04/16 09:55:18 ErrorCode duration: 40ns, args:
2022/04/16 09:55:18 debug: Getenv
Gentoo
2022/04/16 09:55:18 Getenv duration: 1.52µs, args: WSL_DISTRO_NAME
2022/04/16 09:55:18 IsWsl duration: 3.05µs, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 246.689µs, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 PathSeparator duration: 20ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 PathSeparator duration: 20ns, args:
2022/04/16 09:55:18 PathSeparator duration: 20ns, args:
2022/04/16 09:55:18 PathSeparator duration: 20ns, args:
2022/04/16 09:55:18 PathSeparator duration: 20ns, args:
2022/04/16 09:55:18 debug: User
gentoo
2022/04/16 09:55:18 User duration: 880ns, args:
2022/04/16 09:55:18 debug: Host
JACKSON
2022/04/16 09:55:18 Host duration: 1.48µs, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 TemplateCache duration: 749.296µs, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 800ns, args:
2022/04/16 09:55:18 GOOS duration: 20ns, args:
2022/04/16 09:55:18 GOOS duration: 20ns, args:
2022/04/16 09:55:18 TemplateCache duration: 130ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 1.08µs, args:
2022/04/16 09:55:18 GOOS duration: 40ns, args:
2022/04/16 09:55:18 debug: Getenv

2022/04/16 09:55:18 Getenv duration: 790ns, args: SSH_CONNECTION
2022/04/16 09:55:18 debug: Getenv

2022/04/16 09:55:18 Getenv duration: 590ns, args: SSH_CLIENT
2022/04/16 09:55:18 TemplateCache duration: 170ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 1.61µs, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 TemplateCache duration: 110ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 1µs, args:
2022/04/16 09:55:18 GOOS duration: 40ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 580ns, args:
2022/04/16 09:55:18 Flags duration: 30ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 550ns, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 GOOS duration: 20ns, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 GOOS duration: 20ns, args:
2022/04/16 09:55:18 GOOS duration: 20ns, args:
2022/04/16 09:55:18 GOOS duration: 20ns, args:
2022/04/16 09:55:18 GOOS duration: 20ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 PathSeparator duration: 20ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 PathSeparator duration: 20ns, args:
2022/04/16 09:55:18 GOOS duration: 20ns, args:
2022/04/16 09:55:18 debug: Getenv
Gentoo
2022/04/16 09:55:18 Getenv duration: 760ns, args: WSL_DISTRO_NAME
2022/04/16 09:55:18 IsWsl duration: 1.97µs, args:
2022/04/16 09:55:18 debug: RunCommand
C:/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 RunCommand duration: 1.635421ms, args: wslpath -m /mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 StackCount duration: 50ns, args:
2022/04/16 09:55:18 TemplateCache duration: 170ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 1.09µs, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 debug: Getenv
Gentoo
2022/04/16 09:55:18 Getenv duration: 950ns, args: WSL_DISTRO_NAME
2022/04/16 09:55:18 IsWsl duration: 2.17µs, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 560ns, args:
2022/04/16 09:55:18 GOOS duration: 20ns, args:
2022/04/16 09:55:18 HasCommand duration: 16.54µs, args: git.exe
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 600ns, args:
2022/04/16 09:55:18 HasParentFilePath duration: 538.975µs, args: .git
2022/04/16 09:55:18 debug: RunCommand
C:\Work\Git\IaC\Ansible\roles\.git
2022/04/16 09:55:18 RunCommand duration: 1.73074ms, args: wslpath -w /mnt/c/Work/Git/IaC/Ansible/roles/.git
2022/04/16 09:55:18 error: RunCommand
cmd.Start() failed with 'fatal: cannot change to 'C:\Work\Git\IaC\Ansible\roles\': No such file or directory
'
2022/04/16 09:55:18 RunCommand duration: 883.275µs, args: git.exe -C C:\Work\Git\IaC\Ansible\roles\ --no-optional-locks -c core.quotepath=false -c color.status=false status -unormal --branch --porcelain=2
2022/04/16 09:55:18 debug: HasFolder
false
2022/04/16 09:55:18 HasFolder duration: 480.957µs, args: /mnt/c/Work/Git/IaC/Ansible/roles/.git/rebase-merge
2022/04/16 09:55:18 debug: HasFolder
false
2022/04/16 09:55:18 HasFolder duration: 468.808µs, args: /mnt/c/Work/Git/IaC/Ansible/roles/.git/rebase-apply
2022/04/16 09:55:18 PathSeparator duration: 70ns, args:
2022/04/16 09:55:18 debug: HasFilesInDir
false
2022/04/16 09:55:18 HasFilesInDir duration: 484.467µs, args: MERGE_MSG
2022/04/16 09:55:18 PathSeparator duration: 40ns, args:
2022/04/16 09:55:18 debug: HasFilesInDir
false
2022/04/16 09:55:18 HasFilesInDir duration: 472.337µs, args: CHERRY_PICK_HEAD
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 debug: HasFilesInDir
false
2022/04/16 09:55:18 HasFilesInDir duration: 447.837µs, args: REVERT_HEAD
2022/04/16 09:55:18 PathSeparator duration: 40ns, args:
2022/04/16 09:55:18 debug: HasFilesInDir
false
2022/04/16 09:55:18 HasFilesInDir duration: 456.887µs, args: sequencer/todo
2022/04/16 09:55:18 error: FileContent
open /mnt/c/Work/Git/IaC/Ansible/roles/.git/logs/refs/stash: no such file or directory
2022/04/16 09:55:18 FileContent duration: 1.115482ms, args: /mnt/c/Work/Git/IaC/Ansible/roles/.git/logs/refs/stash
2022/04/16 09:55:18 debug: HasFolder
false
2022/04/16 09:55:18 HasFolder duration: 500.257µs, args: /mnt/c/Work/Git/IaC/Ansible/roles/.git/worktrees
2022/04/16 09:55:18 TemplateCache duration: 210ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 1.16µs, args:
2022/04/16 09:55:18 GOOS duration: 40ns, args:
2022/04/16 09:55:18 HasCommand duration: 7.96µs, args: kubectl
2022/04/16 09:55:18 error: RunCommand
cmd.Start() failed with 'error: current-context must exist in order to minify
'
2022/04/16 09:55:18 RunCommand duration: 26.528989ms, args: kubectl config view --output yaml --minify
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 1µs, args:
2022/04/16 09:55:18 GOOS duration: 40ns, args:
2022/04/16 09:55:18 debug: Getenv

2022/04/16 09:55:18 Getenv duration: 1.1µs, args: AWS_VAULT
2022/04/16 09:55:18 debug: Getenv

2022/04/16 09:55:18 Getenv duration: 860ns, args: AWS_PROFILE
2022/04/16 09:55:18 debug: Getenv

2022/04/16 09:55:18 Getenv duration: 750ns, args: AWS_REGION
2022/04/16 09:55:18 debug: Getenv

2022/04/16 09:55:18 Getenv duration: 700ns, args: AWS_DEFAULT_REGION
2022/04/16 09:55:18 debug: Getenv

2022/04/16 09:55:18 Getenv duration: 720ns, args: AWS_CONFIG_FILE
2022/04/16 09:55:18 error: FileContent
open /home/gentoo/.aws/config: no such file or directory
2022/04/16 09:55:18 FileContent duration: 695.365µs, args: /home/gentoo/.aws/config
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 1.41µs, args:
2022/04/16 09:55:18 GOOS duration: 50ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 860ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 700ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 debug: HasFiles
false
2022/04/16 09:55:18 HasFiles duration: 1.312163ms, args: *.cs
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 850ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 debug: HasFiles
false
2022/04/16 09:55:18 HasFiles duration: 1.058803ms, args: *.csx
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 790ns, args:
2022/04/16 09:55:18 PathSeparator duration: 40ns, args:
2022/04/16 09:55:18 debug: HasFiles
false
2022/04/16 09:55:18 HasFiles duration: 1.025323ms, args: *.vb
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 790ns, args:
2022/04/16 09:55:18 PathSeparator duration: 40ns, args:
2022/04/16 09:55:18 debug: HasFiles
false
2022/04/16 09:55:18 HasFiles duration: 1.024599ms, args: *.sln
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 920ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 debug: HasFiles
false
2022/04/16 09:55:18 HasFiles duration: 966.58µs, args: *.csproj
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 730ns, args:
2022/04/16 09:55:18 PathSeparator duration: 40ns, args:
2022/04/16 09:55:18 debug: HasFiles
false
2022/04/16 09:55:18 HasFiles duration: 1.126102ms, args: *.vbproj
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 800ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 debug: HasFiles
false
2022/04/16 09:55:18 HasFiles duration: 1.162504ms, args: *.fs
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 790ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 debug: HasFiles
false
2022/04/16 09:55:18 HasFiles duration: 1.030573ms, args: *.fsx
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 750ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 debug: HasFiles
false
2022/04/16 09:55:18 HasFiles duration: 1.148213ms, args: *.fsproj
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 760ns, args:
2022/04/16 09:55:18 PathSeparator duration: 30ns, args:
2022/04/16 09:55:18 debug: HasFiles
false
2022/04/16 09:55:18 HasFiles duration: 157.199µs, args: global.json
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 1.21µs, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 Shell duration: 150ns, args:
2022/04/16 09:55:18 TemplateCache duration: 130ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 1.02µs, args:
2022/04/16 09:55:18 GOOS duration: 40ns, args:
2022/04/16 09:55:18 ErrorCode duration: 30ns, args:
2022/04/16 09:55:18 TemplateCache duration: 150ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 1.13µs, args:
2022/04/16 09:55:18 GOOS duration: 40ns, args:
2022/04/16 09:55:18 Root duration: 400ns, args:
2022/04/16 09:55:18 debug: Pwd
/mnt/c/Work/Git/IaC/Ansible/roles
2022/04/16 09:55:18 Pwd duration: 970ns, args:
2022/04/16 09:55:18 GOOS duration: 30ns, args:
2022/04/16 09:55:18 ExecutionTime duration: 40ns, args:
2022/04/16 09:55:18 debug: Getenv

2022/04/16 09:55:18 Getenv duration: 10.66µs, args: XDG_CACHE_HOME
2022/04/16 09:55:18 CachePath duration: 18.33µs, args:

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I’m using WSL2

  NAME                   STATE           VERSION
* Gentoo                 Running         2

I’ve tried with a fresh Ubuntu distro and it worked. After trying to figure out what is different between both disto, I remembered that the Gentoo distrib did not get the Windows’s PATH appended and there is a symbolic link for git.exe on /usr/bin/git made a long long time ago. So the git.exe command point to the linux version, not the Windows one so it can’t handle Windows paths …

I’ll try to correct that as it is on my side and not an OMP issue !

Sorry for that 😦

Ah, thanks, @JanDeDobbeleer, works fine so far!

@amzon-ex you can now use .CommandMissing to know if this is the case AND set "native_fallback": true to force it to use the native git executable when in a shared drive in WSL2 when git.exe isn’t available (.CommandMissing will also be true in that case).

@amzon-ex using any executable in WSL2 in the Windows mount is painfully. That’s not something we can fix. The two environments best stay separated.

@JanDeDobbeleer I understand. Is it not possible to include limited support - like atleast indicate that we’re in a git folder or the branch? One of the great things about such a powerful prompt is knowing stuff about where you are and in which environment without running a bunch of commands yourself. That’s why I ask.

@arizon-dread could be you were impacted by #2727, if not, please share the output of oh-my-posh debug in that folder

@GrinGrin this isn’t a bug but by design. Doing git calls from WSL2 on Windows folders doesn’t work correctly so we need to fallback to git for Windows.