Files
orca/src/main/folder-upgrade-worktree-path.ts
T
Neil dd85e5fc81 fix: keep OMP terminals when folder workspaces become Git repos (#20653)
Preserve the original folder locator through Git upgrade and subsequent listing, persistence, and removal decisions after proving it still names the same checkout.

Independently reviewed with 60 focused persistence/listing/removal tests and six native Windows real-Git/NTFS cases covering case/slashes, junction retention and retargeting, remote-host isolation and unrelated checkout preservation. Prior source-connected native OMP proof confirms process survival. Full PR CI passed; no rebuilt full-app after-proof claimed.
2026-09-14 14:54:53 -07:00

42 lines
1.3 KiB
TypeScript

import { realpathSync } from 'node:fs'
import type { Repo } from '../shared/repo-types'
import type { GitWorktreeInfo } from '../shared/worktree/types'
import { getRepoExecutionHostId, LOCAL_EXECUTION_HOST_ID } from '../shared/execution-host'
import { areWorktreePathsEqual, dedupeWorktreesByPath } from './ipc/worktree-path-comparison'
function stillNamesRegisteredCheckout(repo: Repo, gitRoot: string): boolean {
if (areWorktreePathsEqual(repo.path, gitRoot)) {
return true
}
if (getRepoExecutionHostId(repo) !== LOCAL_EXECUTION_HOST_ID) {
return false
}
try {
// A symlink may have been retargeted since the upgrade.
return areWorktreePathsEqual(realpathSync(repo.path), realpathSync(gitRoot))
} catch {
return false
}
}
export function preserveFolderUpgradeWorktreePath(
repo: Repo,
worktrees: GitWorktreeInfo[]
): GitWorktreeInfo[] {
const gitRoot = repo.folderUpgradeGitRootPath
if (
repo.kind !== 'git' ||
typeof gitRoot !== 'string' ||
!gitRoot ||
!stillNamesRegisteredCheckout(repo, gitRoot)
) {
return worktrees
}
// Apply after raw Git caches: this repo's locator must not leak into another registration.
return dedupeWorktreesByPath(
worktrees.map((worktree) =>
areWorktreePathsEqual(worktree.path, gitRoot) ? { ...worktree, path: repo.path } : worktree
)
)
}