fix(git): align git Dir with PWD

This commit is contained in:
Jan De Dobbeleer 2022-08-31 11:55:23 +02:00 committed by Jan De Dobbeleer
parent f04e22a5d1
commit 2a1fdffb73
3 changed files with 7 additions and 4 deletions

View file

@ -726,8 +726,9 @@ func (env *ShellEnvironment) TemplateCache() *TemplateCache {
val := splitted[1:]
tmplCache.Env[key] = strings.Join(val, separator)
}
tmplCache.PWD = env.Pwd()
tmplCache.Folder = Base(env, tmplCache.PWD)
pwd := env.Pwd()
tmplCache.PWD = strings.Replace(pwd, env.Home(), "~", 1)
tmplCache.Folder = Base(env, pwd)
tmplCache.UserName = env.User()
if host, err := env.Host(); err == nil {
tmplCache.HostName = host

View file

@ -160,7 +160,8 @@ func (g *Git) shouldDisplay() bool {
}
// convert the worktree file path to a windows one when in wsl 2 shared folder
g.Dir = strings.TrimSuffix(g.convertToWindowsPath(gitdir.Path), "/.git")
dir := strings.Replace(gitdir.Path, g.env.Home(), "~", 1) // align with template PWD
g.Dir = strings.TrimSuffix(g.convertToWindowsPath(dir), "/.git")
if !gitdir.IsDir {
return g.hasWorktree(gitdir)
@ -168,7 +169,7 @@ func (g *Git) shouldDisplay() bool {
g.workingDir = gitdir.Path
g.rootDir = gitdir.Path
g.realDir = g.Dir
g.realDir = strings.TrimSuffix(g.convertToWindowsPath(gitdir.Path), "/.git")
return true
}

View file

@ -47,6 +47,7 @@ func TestEnabledInWorkingDirectory(t *testing.T) {
env.On("IsWsl").Return(false)
env.On("HasParentFilePath", ".git").Return(fileInfo, nil)
env.On("PathSeparator").Return("/")
env.On("Home").Return("/Users/posh")
g := &Git{
scm: scm{
env: env,