fix(windows): use git show-prefix for nested worktree detection

This commit is contained in:
Tom Boucher
2026-05-17 01:33:32 -04:00
parent af54a4ffe6
commit 4d81532b74

View File

@@ -100,31 +100,32 @@ function getInitGitState(cwd) {
let inNestedSubdir = false; let inNestedSubdir = false;
if (info.inside) { if (info.inside) {
const rootNorm = normalizeForCompare(worktreeRoot); let resolvedByGitPrefix = false;
const cwdNorm = normalizeForCompare(cwd); try {
if (rootNorm && cwdNorm) { const prefixResult = execGit(['rev-parse', '--show-prefix'], { cwd, timeout: 5000 });
if (rootNorm === cwdNorm) { if (prefixResult.exitCode === 0) {
inNestedSubdir = false; const prefix = String(prefixResult.stdout || '').trim().replace(/\\/g, '/');
} else { inNestedSubdir = prefix.length > 0 && prefix !== '.' && prefix !== './';
const rel = path.relative(rootNorm, cwdNorm); resolvedByGitPrefix = true;
const relNorm = process.platform === 'win32' ? rel.replace(/\//g, '\\') : rel;
inNestedSubdir =
relNorm !== '' &&
relNorm !== '.' &&
!relNorm.startsWith('..') &&
!path.isAbsolute(relNorm);
} }
} else { } catch {}
// Fallback only when root/cwd normalization fails.
try { if (!resolvedByGitPrefix) {
const cdupResult = execGit(['rev-parse', '--show-cdup'], { cwd, timeout: 5000 }); const rootNorm = normalizeForCompare(worktreeRoot);
if (cdupResult.exitCode === 0) { const cwdNorm = normalizeForCompare(cwd);
const cdup = String(cdupResult.stdout || '').trim().replace(/\\/g, '/'); if (rootNorm && cwdNorm) {
inNestedSubdir = cdup.length > 0 && cdup !== '.' && cdup !== './'; if (rootNorm === cwdNorm) {
inNestedSubdir = false;
} else { } else {
inNestedSubdir = worktreeRoot !== null; const rel = path.relative(rootNorm, cwdNorm);
const relNorm = process.platform === 'win32' ? rel.replace(/\//g, '\\') : rel;
inNestedSubdir =
relNorm !== '' &&
relNorm !== '.' &&
!relNorm.startsWith('..') &&
!path.isAbsolute(relNorm);
} }
} catch { } else {
inNestedSubdir = worktreeRoot !== null; inNestedSubdir = worktreeRoot !== null;
} }
} }