fix(git): 兼容旧版 Git 的 worktree 列表

This commit is contained in:
Kunping Wang authored and Menghuan1918 committed 2026-08-29 15:31:08 +08:00
1 parent 2088ef6891
commit 5d8c33832c
2 files changed
+66 -2

No files matched your search

+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)
}