mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
fix(git): show original worktree as repo name
This commit is contained in:
parent
b86bd04574
commit
bb5e1b1a2e
|
@ -167,7 +167,7 @@ func (g *Git) Enabled() bool {
|
||||||
g.setUser()
|
g.setUser()
|
||||||
}
|
}
|
||||||
|
|
||||||
g.RepoName = platform.Base(g.env, g.convertToLinuxPath(g.realDir))
|
g.RepoName = g.repoName()
|
||||||
|
|
||||||
g.Working = &GitStatus{}
|
g.Working = &GitStatus{}
|
||||||
g.Staging = &GitStatus{}
|
g.Staging = &GitStatus{}
|
||||||
|
@ -268,6 +268,10 @@ func (g *Git) Kraken() string {
|
||||||
return fmt.Sprintf("gitkraken://repolink/%s/commit/%s?url=%s", root, g.Hash, url2.QueryEscape(g.RawUpstreamURL))
|
return fmt.Sprintf("gitkraken://repolink/%s/commit/%s?url=%s", root, g.Hash, url2.QueryEscape(g.RawUpstreamURL))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Git) LatestTag() string {
|
||||||
|
return g.getGitCommandOutput("describe", "--tags", "--abbrev=0")
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Git) shouldDisplay() bool {
|
func (g *Git) shouldDisplay() bool {
|
||||||
if !g.hasCommand(GITCOMMAND) {
|
if !g.hasCommand(GITCOMMAND) {
|
||||||
return false
|
return false
|
||||||
|
@ -850,6 +854,15 @@ func (g *Git) getSwitchMode(property properties.Property, gitSwitch, mode string
|
||||||
return fmt.Sprintf("%s%s", gitSwitch, mode)
|
return fmt.Sprintf("%s%s", gitSwitch, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Git) LatestTag() string {
|
func (g *Git) repoName() string {
|
||||||
return g.getGitCommandOutput("describe", "--tags", "--abbrev=0")
|
if !g.IsWorkTree {
|
||||||
|
return platform.Base(g.env, g.convertToLinuxPath(g.realDir))
|
||||||
|
}
|
||||||
|
|
||||||
|
ind := strings.LastIndex(g.workingDir, ".git/worktrees")
|
||||||
|
if ind > -1 {
|
||||||
|
return platform.Base(g.env, g.workingDir[:ind])
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -1108,3 +1108,51 @@ func TestGitRemotes(t *testing.T) {
|
||||||
assert.Equal(t, tc.Expected, len(got), tc.Case)
|
assert.Equal(t, tc.Expected, len(got), tc.Case)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGitRepoName(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
Expected string
|
||||||
|
WorkingDir string
|
||||||
|
RealDir string
|
||||||
|
IsWorkTree bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Case: "In worktree",
|
||||||
|
Expected: "oh-my-posh",
|
||||||
|
IsWorkTree: true,
|
||||||
|
WorkingDir: "/Users/jan/Code/oh-my-posh/.git/worktrees/oh-my-posh2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "Not in worktree",
|
||||||
|
Expected: "oh-my-posh",
|
||||||
|
IsWorkTree: false,
|
||||||
|
RealDir: "/Users/jan/Code/oh-my-posh",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "In worktree, unexpected dir",
|
||||||
|
Expected: "",
|
||||||
|
IsWorkTree: true,
|
||||||
|
WorkingDir: "/Users/jan/Code/oh-my-posh2",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
env := new(mock.MockedEnvironment)
|
||||||
|
env.On("PathSeparator").Return("/")
|
||||||
|
env.On("GOOS").Return(platform.LINUX)
|
||||||
|
|
||||||
|
g := &Git{
|
||||||
|
scm: scm{
|
||||||
|
props: properties.Map{},
|
||||||
|
env: env,
|
||||||
|
realDir: tc.RealDir,
|
||||||
|
workingDir: tc.WorkingDir,
|
||||||
|
},
|
||||||
|
IsWorkTree: tc.IsWorkTree,
|
||||||
|
}
|
||||||
|
|
||||||
|
got := g.repoName()
|
||||||
|
assert.Equal(t, tc.Expected, got, tc.Case)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue