mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-03 07:17:26 -08:00
fix(git): do not use git.exe on WSL 1
This commit is contained in:
parent
b94e96dd15
commit
e8a4fa19b7
|
@ -81,6 +81,8 @@ type git struct {
|
||||||
gitWorkingFolder string // .git working folder, can be different of root if using worktree
|
gitWorkingFolder string // .git working folder, can be different of root if using worktree
|
||||||
gitRootFolder string // .git root folder
|
gitRootFolder string // .git root folder
|
||||||
gitWorktreeFolder string // .git real worktree path
|
gitWorktreeFolder string // .git real worktree path
|
||||||
|
|
||||||
|
gitCommand string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -284,14 +286,24 @@ func (g *git) setGitStatus() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *git) getGitCommand() string {
|
func (g *git) getGitCommand() string {
|
||||||
inWSLSharedDrive := func(env environmentInfo) bool {
|
if len(g.gitCommand) > 0 {
|
||||||
return env.isWsl() && strings.HasPrefix(env.getcwd(), "/mnt/")
|
return g.gitCommand
|
||||||
}
|
}
|
||||||
gitCommand := "git"
|
inWSL2SharedDrive := func(env environmentInfo) bool {
|
||||||
if g.env.getRuntimeGOOS() == windowsPlatform || inWSLSharedDrive(g.env) {
|
if !env.isWsl() {
|
||||||
gitCommand = "git.exe"
|
return false
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(env.getcwd(), "/mnt/") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
uname, _ := g.env.runCommand("uname", "-r")
|
||||||
|
return strings.Contains(uname, "WSL2")
|
||||||
}
|
}
|
||||||
return gitCommand
|
g.gitCommand = "git"
|
||||||
|
if g.env.getRuntimeGOOS() == windowsPlatform || inWSL2SharedDrive(g.env) {
|
||||||
|
g.gitCommand = "git.exe"
|
||||||
|
}
|
||||||
|
return g.gitCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *git) getGitCommandOutput(args ...string) string {
|
func (g *git) getGitCommandOutput(args ...string) string {
|
||||||
|
|
|
@ -700,13 +700,15 @@ func TestGetGitCommand(t *testing.T) {
|
||||||
Case string
|
Case string
|
||||||
Expected string
|
Expected string
|
||||||
IsWSL bool
|
IsWSL bool
|
||||||
|
IsWSL1 bool
|
||||||
GOOS string
|
GOOS string
|
||||||
CWD string
|
CWD string
|
||||||
}{
|
}{
|
||||||
{Case: "On Windows", Expected: "git.exe", GOOS: windowsPlatform},
|
{Case: "On Windows", Expected: "git.exe", GOOS: windowsPlatform},
|
||||||
{Case: "Non Windows", Expected: "git"},
|
{Case: "Non Windows", Expected: "git"},
|
||||||
{Case: "Iside WSL, non shared", IsWSL: true, Expected: "git"},
|
{Case: "Iside WSL2, non shared", IsWSL: true, Expected: "git"},
|
||||||
{Case: "Iside WSL, shared", Expected: "git.exe", IsWSL: true, CWD: "/mnt/bill"},
|
{Case: "Iside WSL2, shared", Expected: "git.exe", IsWSL: true, CWD: "/mnt/bill"},
|
||||||
|
{Case: "Iside WSL1, shared", Expected: "git", IsWSL: true, IsWSL1: true, CWD: "/mnt/bill"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
|
@ -714,6 +716,11 @@ func TestGetGitCommand(t *testing.T) {
|
||||||
env.On("isWsl", nil).Return(tc.IsWSL)
|
env.On("isWsl", nil).Return(tc.IsWSL)
|
||||||
env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
|
env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
|
||||||
env.On("getcwd", nil).Return(tc.CWD)
|
env.On("getcwd", nil).Return(tc.CWD)
|
||||||
|
wslUname := "5.10.60.1-microsoft-standard-WSL2"
|
||||||
|
if tc.IsWSL1 {
|
||||||
|
wslUname = "4.4.0-19041-Microsoft"
|
||||||
|
}
|
||||||
|
env.On("runCommand", "uname", []string{"-r"}).Return(wslUname, nil)
|
||||||
g := &git{
|
g := &git{
|
||||||
env: env,
|
env: env,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue