fix(path): support gitdir_format in linked worktrees

This commit is contained in:
Gravifer
2026-07-28 08:32:19 +02:00
committed by Jan De Dobbeleer
parent 79eda3d8c7
commit 224eb9a865
4 changed files with 29 additions and 2 deletions
+2 -1
View File
@@ -993,7 +993,8 @@ func (pt *Path) makeFolderFormatMap() map[string]string {
if gitDirFormat := pt.options.String(GitDirFormat, ""); len(gitDirFormat) != 0 {
dir, err := pt.env.HasParentFilePath(".git", false)
if err == nil && dir.IsDir {
if err == nil {
// Linked worktrees use a .git file instead of a directory.
// Make it consistent with the modified parent.
parent := pt.join(pt.replaceMappedLocations(dir.ParentFolder))
folderFormatMap[parent] = gitDirFormat
+12
View File
@@ -698,6 +698,18 @@ var testSplitPathCases = []testSplitPathCase{
{Name: "d", Path: "~/c/d"},
},
},
{
Case: "Home directory - linked git worktree",
Root: "~",
Relative: "c/d",
GOOS: runtime.DARWIN,
GitDir: &runtime.FileInfo{ParentFolder: "/a/b/c"},
GitDirFormat: "<b>%s</b>",
Expected: Folders{
{Name: "<b>c</b>", Path: "~/c", Display: true},
{Name: "d", Path: "~/c/d"},
},
},
}
var testNormalizePathCases = []testNormalizePathCase{
+14
View File
@@ -498,6 +498,20 @@ var testSplitPathCases = []testSplitPathCase{
{Name: "d", Path: "C:/a/b/c/d"},
},
},
{
Case: "Home directory - linked git worktree on Windows",
Root: "C:",
Relative: "a/b/c/d",
GOOS: runtime.WINDOWS,
GitDir: &runtime.FileInfo{ParentFolder: "C:/a/b/c"},
GitDirFormat: "<b>%s</b>",
Expected: Folders{
{Name: "a", Path: "C:/a"},
{Name: "b", Path: "C:/a/b"},
{Name: "<b>c</b>", Path: "C:/a/b/c", Display: true},
{Name: "d", Path: "C:/a/b/c/d"},
},
},
}
var testNormalizePathCases = []testNormalizePathCase{
+1 -1
View File
@@ -48,7 +48,7 @@ import Config from "@site/src/components/Config.js";
| `edge_format` | `string` | `%s` | format to use on the first and last folder of the path |
| `left_format` | `string` | `%s` | format to use on the first folder of the path - defaults to `edge_format` |
| `right_format` | `string` | `%s` | format to use on the last folder of the path - defaults to `edge_format` |
| `gitdir_format` | `string` | | format to use for a git root directory |
| `gitdir_format` | `string` | | format to use for a Git root directory, including linked worktrees |
| `display_cygpath` | `boolean` | `false` | display the Cygwin style path using `cygpath -u $PWD` |
| `display_root` | `boolean` | `false` | display the root `/` on Unix systems |
| `dir_length` | `number` | `1` | the length of the directory name to display when using `fish` |