Route worktree creation into the configured parent directory #322
Labels
No labels
batch
bug
chore
documentation
enhancement
pi-loop
ready
resume
No milestone
No project
No assignees
1 participant
Notifications
Due date
Dependencies
No dependencies set
Reference
david/pi-loop#322
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Make
resolveWorkDircreate new worktrees under a configured parent directory (worktree.dir), and enable worktree creation for normal clones when that directory is in effect — while the worktree registry keeps priority and a clone without a configured dir keeps running in place.Background
src/shared/git/services/resolveWorktree.tsexportsresolveWorkDir({ originalCwd, runGit, issueKey, issueSummary, provider, ensureWorktreeFn?, findExistingWorktreeFn?, registerWorktreeFn?, fsStat? })(tests inresolveWorktree.test.ts). Current flow:isInsideWorktreefast path → returnoriginalCwd(a run started inside a worktree reuses that tree).originalCwdunchanged (normal clones run in place).parentDir = dirname(originalCwd),worktreeName = buildBranchFolderName(issueKey, issueSummary, provider), registry lookupfindExistingWorktreeFn({ bareRepoPath, issueKey })(registry lives at<launchRoot>/.pi-loop/worktrees/<issueKey>viagitWorktree.ts); if found → return the existing path; elseresolveDefaultBranch+ensureWorktreeFn({ runGit, bareRepoPath, parentDir, worktreeName, branchRef })+registerWorktreeFnon creation.ensureWorktreealready joinsparentDir/worktreeNameand runsgit worktree add --detachfrombareRepoPath— no change needed there:--detachmeans no branch is checked out at creation, so a linked worktree created from a normal clone behaves the same as one created from a bare repo.ADR-022 decisions this step implements:
ensureWorktree, so a configured dir only affects new worktree creation; a resume must never move a work-in-progress tree.bareRepoPathmust be set tooriginalCwdbecause the registry lives at the launch root.Depends on: #320 — the value this input carries is parsed there.
Implementation Details
Files:
src/shared/git/services/resolveWorktree.ts,src/shared/git/services/resolveWorktree.test.ts.worktreeDir: string | undefinedtoResolveWorkDirInput.originalCwd(unchanged);worktreeDir === undefined→ returnoriginalCwdunchanged (regression guard);worktreeDirdefined → continue (create a linked worktree);const parentDir = worktreeDir ?? dirname(originalCwd)— computed after the registry lookup.bareRepoPath = originalCwdfor both repo kinds that continue (the registry lives at the launch root), andresolveDefaultBranchruns against it.resolveDefaultBranch,ensureWorktree,registerWorktree) is unchanged.ResolvedWorkDir/resolveWorkDirdoc comments:bareRepoPathis the path to the repo holding the worktree registry (the bare repo, or the launch root for a normal clone in worktree mode); the "non-bare repo → original cwd" paragraph must reflect the new gate.Acceptance Criteria
resolveWorktree.test.tstests pass unchanged whenworktreeDiris undefined.worktreeDir: '/srv/wt'→ensureWorktreeFnis called withparentDir: '/srv/wt'.worktreeDirdefined → a worktree is created (today it returnsoriginalCwd), and the registry entry is written underoriginalCwd/.pi-loop/worktrees/<key>.worktreeDirundefined → returnsoriginalCwd,isWorktree: false(regression guard).ensureWorktreeFnis never called, regardless ofworktreeDir; the registered path is returned.npm run lintandnpm testpass.Test Plan
Extend
resolveWorktree.test.tswith the cases above (existing tests use injectableensureWorktreeFn/findExistingWorktreeFn/registerWorktreeFndoubles — follow that style). Runnpm test.pi-loop opened and merged a pull request for this issue: #328