mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
fix(git): submodules support
This commit is contained in:
parent
541e8e95aa
commit
393f99da93
|
@ -134,14 +134,28 @@ func (g *git) enabled() bool {
|
||||||
// if we open a worktree file in a shared wsl2 folder, we have to convert it back
|
// if we open a worktree file in a shared wsl2 folder, we have to convert it back
|
||||||
// to the mounted path
|
// to the mounted path
|
||||||
g.gitWorkingFolder = g.convertToLinuxPath(matches["dir"])
|
g.gitWorkingFolder = g.convertToLinuxPath(matches["dir"])
|
||||||
|
|
||||||
// in worktrees, the path looks like this: gitdir: path/.git/worktrees/branch
|
// in worktrees, the path looks like this: gitdir: path/.git/worktrees/branch
|
||||||
// strips the last .git/worktrees part
|
// strips the last .git/worktrees part
|
||||||
// :ind+5 = index + /.git
|
// :ind+5 = index + /.git
|
||||||
ind := strings.LastIndex(g.gitWorkingFolder, "/.git/worktrees")
|
ind := strings.LastIndex(g.gitWorkingFolder, "/.git/worktrees")
|
||||||
g.gitRootFolder = g.gitWorkingFolder[:ind+5]
|
if ind > -1 {
|
||||||
g.gitRealFolder = strings.TrimSuffix(g.env.getFileContent(g.gitWorkingFolder+"/gitdir"), ".git\n")
|
g.gitRootFolder = g.gitWorkingFolder[:ind+5]
|
||||||
g.IsWorkTree = true
|
g.gitRealFolder = strings.TrimSuffix(g.env.getFileContent(g.gitWorkingFolder+"/gitdir"), ".git\n")
|
||||||
return true
|
g.IsWorkTree = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// in submodules, the path looks like this: gitdir: ../.git/modules/test-submodule
|
||||||
|
// we need the parent folder to detect where the real .git folder is
|
||||||
|
ind = strings.LastIndex(g.gitWorkingFolder, "/.git/modules")
|
||||||
|
if ind > -1 {
|
||||||
|
g.gitRootFolder = gitdir.parentFolder + "/" + g.gitWorkingFolder
|
||||||
|
g.gitRealFolder = g.gitRootFolder
|
||||||
|
g.gitWorkingFolder = g.gitRootFolder
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,31 @@ func TestEnabledInWorkingTree(t *testing.T) {
|
||||||
assert.Equal(t, "/dev/folder_worktree", g.gitRealFolder)
|
assert.Equal(t, "/dev/folder_worktree", g.gitRealFolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEnabledInSubmodule(t *testing.T) {
|
||||||
|
env := new(MockedEnvironment)
|
||||||
|
env.On("inWSLSharedDrive", nil).Return(false)
|
||||||
|
env.On("hasCommand", "git").Return(true)
|
||||||
|
env.On("getRuntimeGOOS", nil).Return("")
|
||||||
|
env.On("isWsl", nil).Return(false)
|
||||||
|
fileInfo := &fileInfo{
|
||||||
|
path: "/dev/parent/test-submodule/.git",
|
||||||
|
parentFolder: "/dev/parent/test-submodule",
|
||||||
|
isDir: false,
|
||||||
|
}
|
||||||
|
env.On("hasParentFilePath", ".git").Return(fileInfo, nil)
|
||||||
|
env.On("getFileContent", "/dev/parent/test-submodule/.git").Return("gitdir: ../.git/modules/test-submodule")
|
||||||
|
env.On("getFileContent", "/dev/parent/.git/modules/test-submodule").Return("/dev/folder_worktree.git\n")
|
||||||
|
g := &git{
|
||||||
|
scm: scm{
|
||||||
|
env: env,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.True(t, g.enabled())
|
||||||
|
assert.Equal(t, "/dev/parent/test-submodule/../.git/modules/test-submodule", g.gitWorkingFolder)
|
||||||
|
assert.Equal(t, "/dev/parent/test-submodule/../.git/modules/test-submodule", g.gitRealFolder)
|
||||||
|
assert.Equal(t, "/dev/parent/test-submodule/../.git/modules/test-submodule", g.gitRootFolder)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetGitOutputForCommand(t *testing.T) {
|
func TestGetGitOutputForCommand(t *testing.T) {
|
||||||
args := []string{"-C", "", "--no-optional-locks", "-c", "core.quotepath=false", "-c", "color.status=false"}
|
args := []string{"-C", "", "--no-optional-locks", "-c", "core.quotepath=false", "-c", "color.status=false"}
|
||||||
commandArgs := []string{"symbolic-ref", "--short", "HEAD"}
|
commandArgs := []string{"symbolic-ref", "--short", "HEAD"}
|
||||||
|
|
Loading…
Reference in a new issue