-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: prevent worktree reuse across different local clones #1186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
halindrome
wants to merge
5
commits into
coleam00:dev
from
halindrome:fix/worktree-reuse-cross-checkout
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f9d54ac
fix: prevent worktree reuse across different local clones (#1183)
shanemccarron-maker 9f38502
fix(cli): address QA round 1 — add tests and warn on null root
shanemccarron-maker e92ee2d
test(cli): address QA round 2 — test null-root warning path
shanemccarron-maker e2af7a2
fix(cli): use getCanonicalRepoPath for worktree-stable comparison
shanemccarron-maker 14c57f1
fix(cli): address CodeRabbit — resolve subdir before canonicalize, lo…
shanemccarron-maker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: coleam00/Archon
Length of output: 6635
Resolve the repo root before canonicalizing it.
Line 434 calls
getCanonicalRepoPath(cwd)directly, but that function returns non-worktree paths unchanged. If the command runs from a subdirectory like/repo/subdir, it returns/repo/subdiras-is, causing same-clone comparisons to fail across different directory invocations. This unstable value is then persisted intometadata.source_repo_rootat line 535. Additionally, the emptycatchblock swallows all exceptions—including real worktree metadata failures—and silently falls back to reuse-allowed behavior.Call
findRepoRoot(cwd)first to resolve any subdirectory to the actual repo top-level (returning null only for non-repo cases), then canonicalize that root. Log and throw on real errors rather than silencing them.🛠️ Proposed fix
let currentRepoRoot: string | null = null; try { - currentRepoRoot = await git.getCanonicalRepoPath(cwd); - } catch { - // Non-fatal: cwd may not be a git repo (handled later) or git unavailable + const repoRoot = await git.findRepoRoot(cwd); + currentRepoRoot = repoRoot ? await git.getCanonicalRepoPath(repoRoot) : null; + } catch (error) { + const err = error as Error; + getLog().error({ err, cwd }, 'worktree.reuse_root_detection_failed'); + throw new Error(`Failed to resolve repository root for ${cwd}: ${err.message}`); }Violates: "Never silently swallow errors related to unsupported or unsafe states — throw early with clear error messages."
Also applies to: 535
🤖 Prompt for AI Agents