Merge pull request #454 from wang-kaopu/fix/issue-440-old-git-worktree

fix(git): support worktree listing on older Git versions
This commit is contained in:
Atlas Zeng
2026-09-02 23:10:37 +08:00
committed by GitHub
2 changed files with 66 additions and 2 deletions
+17 -1
View File
@@ -323,11 +323,27 @@ function pathIdentity(path: string): string {
return process.platform === 'win32' ? absolute.toLowerCase() : absolute
}
/** Whether the current Git binary supports NUL-framed `worktree list` output.
* Git < 2.36 rejects `-z`; cache the capability after the first attempt so
* the SCM panel's polling does not repeatedly spawn a command known to fail. */
let worktreeListSupportsZ: boolean | undefined
/** Raw usable checkout records, shared by inventory and target validation.
* Prunable records point at missing paths and are deliberately excluded from
* both the selector and the command-target allowlist. */
async function listedWorktrees(cwd: string): Promise<GitWorktreeRecord[]> {
const raw = await runGit(cwd, ['worktree', 'list', '--porcelain', '-z'])
let raw: string
if (worktreeListSupportsZ === false) {
raw = await runGit(cwd, ['worktree', 'list', '--porcelain'])
} else {
try {
raw = await runGit(cwd, ['worktree', 'list', '--porcelain', '-z'])
worktreeListSupportsZ = true
} catch {
worktreeListSupportsZ = false
raw = await runGit(cwd, ['worktree', 'list', '--porcelain'])
}
}
return parseWorktreeList(raw).filter(entry => !entry.prunable)
}