Merge reviewed PR #3584: preserve exact lifecycle worktree paths

This commit is contained in:
haelyra committed 2026-11-16 22:01:04 -05:00
commit d64bf7d2b6
3 files changed
+76 -11

No files matched your search

+6 -6
View File
@@ -60,23 +60,23 @@ function createGitRunner(repoRoot, runImpl = defaultRunImpl) {
return succeeds(['show-ref', '--verify', '--quiet', `refs/heads/${branch}`]);
},
// Porcelain worktree list -> [{ path, branch, head, detached, bare }]
// Git 2.36+ NUL-delimited porcelain preserves whitespace within paths.
listWorktrees() {
const result = run(['worktree', 'list', '--porcelain']);
const result = run(['worktree', 'list', '--porcelain', '-z']);
if (result.status !== 0) {
return [];
const reason = (result.stderr || '').trim() || `git exited with status ${result.status}`;
throw new Error(`Unable to list worktrees safely (Git 2.36+ required): ${reason}`);
}
const worktrees = [];
let current = null;
for (const rawLine of (result.stdout || '').split('\n')) {
const line = rawLine.trim();
for (const line of (result.stdout || '').split('\0')) {
if (line.startsWith('worktree ')) {
if (current) {
worktrees.push(current);
}
current = { path: line.slice('worktree '.length).trim(), branch: null, head: null, detached: false, bare: false };
current = { path: line.slice('worktree '.length), branch: null, head: null, detached: false, bare: false };
} else if (current && line.startsWith('branch ')) {
current.branch = line.slice('branch '.length).replace(/^refs\/heads\//, '').trim();
} else if (current && line.startsWith('HEAD ')) {
+2
View File
@@ -55,6 +55,8 @@ function usage() {
'conflicts without touching the working tree (git merge-tree) and proposes',
'a safe cleanup plan that never removes dirty or unmerged worktrees.',
'',
'Requires Git 2.36+ for NUL-delimited worktree paths.',
'',
'Options:',
' --json Print the full ecc.worktree-lifecycle.v1 report as JSON',
' --conflicts Only show worktrees that would conflict on merge',