fix(worktree): only dedupe a linked worktree against a git main checkout

Review follow-up: the repos:add guard matched any tracked repo on the main
checkout path, including a folder-kind record. A folder repo does not
project onto the same project as the git worktree, so matching it would
suppress a legitimate add without deduping anything.
This commit is contained in:
Neil
2026-07-25 15:19:15 -07:00
parent 72c99c8bf3
commit 8f4c3daca8
2 changed files with 17 additions and 1 deletions
@@ -167,6 +167,18 @@ describe('repos:add with git worktrees', () => {
expect(mockStore.addRepo).not.toHaveBeenCalled()
})
it('does not match a folder record sitting on the main-checkout path', async () => {
mockStore.getRepos.mockReturnValue([
{ ...trackedMainRepo(), id: 'folder-repo-id', kind: 'folder' } as Repo
])
getLinkedWorktreeMainRepoRootMock.mockReturnValue(MAIN_CHECKOUT)
const result = await callAdd({ path: LINKED_WORKTREE })
expect(mockStore.addRepo).toHaveBeenCalledTimes(1)
expect(result).toEqual({ repo: expect.objectContaining({ path: LINKED_WORKTREE }) })
})
it('does not match a tracked SSH repo that shares the local main-checkout path', async () => {
mockStore.getRepos.mockReturnValue([
{ ...trackedMainRepo(), id: 'ssh-repo-id', connectionId: 'builder' } as Repo
+5 -1
View File
@@ -203,11 +203,15 @@ async function addLocalRepoFromPath(
const mainRepoRoot = getLinkedWorktreeMainRepoRoot(resolvedPath)
if (mainRepoRoot) {
const mainRepoKey = normalizeRuntimePathForComparison(mainRepoRoot)
// Why !isFolderRepo: only a git-kind main checkout projects onto the same project as its
// worktree, so matching a folder record would suppress the add without deduping anything.
const trackedMainRepo = store
.getRepos()
.find(
(repo) =>
!repo.connectionId && normalizeRuntimePathForComparison(repo.path) === mainRepoKey
!repo.connectionId &&
!isFolderRepo(repo) &&
normalizeRuntimePathForComparison(repo.path) === mainRepoKey
)
if (trackedMainRepo) {
return { repo: trackedMainRepo, alreadyExisted: true }