fix(hindsight): share tags for bare worktrees

Bare-repository worktrees resolve their git common dir to the bare repo
itself (for example /repos/foo.git), not to a directory literally named
.git. The first fix only collapsed non-bare linked worktrees, so bare
worktree layouts still fell back to each individual worktree root.

Return the shared commonDir for bare repositories from both
repo.primaryRoot and repo.primaryRootSync, update project-label docs,
and cover two worktrees attached to one bare repository in the
hindsight bank regression test.

Fixes #2232
This commit is contained in:
roboomp
2026-06-10 08:26:01 +02:00
committed by can1357
parent 29b2b51203
commit 901fa4c013
4 changed files with 31 additions and 8 deletions
+6 -5
View File
@@ -1445,12 +1445,12 @@ export const repo = {
return result.stdout.trim() || null;
},
/** Resolve the primary repository root (not a worktree — the main checkout). */
/** Resolve the primary checkout root, or the shared common dir for bare-repo worktrees. */
async primaryRoot(cwd: string, signal?: AbortSignal): Promise<string | null> {
const repository = await resolveRepository(cwd);
if (repository) {
if (path.basename(repository.commonDir) === ".git") return path.dirname(repository.commonDir);
return repository.repoRoot;
return repository.commonDir;
}
const repoRoot = await repo.root(cwd, signal);
if (!repoRoot) return null;
@@ -1459,20 +1459,21 @@ export const repo = {
signal,
});
if (path.basename(commonDir.trim()) === ".git") return path.dirname(commonDir.trim());
return repoRoot;
return commonDir.trim();
},
/**
* Sync sibling of {@link primaryRoot}. Resolves only via on-disk `.git`/
* `commondir` walking — no subprocess fallback — so it stays usable from
* paths where async I/O is impractical (e.g. `computeBankScope`). Returns
* `null` when `cwd` is outside a repository.
* `null` when `cwd` is outside a repository. Bare-repo worktrees resolve to
* the shared common dir (`foo.git`) because they have no primary checkout.
*/
primaryRootSync(cwd: string): string | null {
const repository = resolveRepositorySync(cwd);
if (!repository) return null;
if (path.basename(repository.commonDir) === ".git") return path.dirname(repository.commonDir);
return repository.repoRoot;
return repository.commonDir;
},
/** Full GitRepository metadata (sync). */