refuse to run when repo root is inside .worktrees - #160
Conversation
Reviewer's GuideThe PR prevents the command from running against Git worktree checkouts, where sync-created absolute links would become dangling after worktree removal. It validates the resolved repository root early in context loading and adds tests covering direct and symlinked worktree paths. Flow diagram for rejecting Git worktree repository rootsflowchart TD
A[loadContext] --> B[resolve repository root]
B --> C[refuseWorktreeRoot]
C -->|root contains .worktrees| D[Return error]
C -->|canonical checkout| E[loadConfig]
D --> F[Command stops before sync]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cmd/dotagents/config.go" line_range="24-26" />
<code_context>
return "", "", config{}, nil, err
}
repoRoot := filepath.Dir(configPath)
+ if err := refuseWorktreeRoot(repoRoot); err != nil {
+ return "", "", config{}, nil, err
+ }
cfg, err := loadConfig(repoRoot, home, configPath)
</code_context>
<issue_to_address>
**issue (broader_impact):** The new guard is only applied by `loadContext`, so `setup` still performs worktree mutations before its final `runSync` call reaches the guard: it can apply memory-tier changes, import native content, write `dotagents.yaml`, create hook executables, and patch agent configuration before returning the refusal error.
**Triggers:** When `setup` is run with its config under `.worktrees/`.
**Suggested fix:** Call `refuseWorktreeRoot(repoRoot)` immediately after `runSetup` resolves `repoRoot`, before any setup mutation; audit other command paths that resolve repository roots without `loadContext`.
</issue_to_address>
### Comment 2
<location path="cmd/dotagents/config.go" line_range="373-375" />
<code_context>
+ if real, err := filepath.EvalSymlinks(repoRoot); err == nil {
+ resolved = real
+ }
+ for _, seg := range strings.Split(filepath.ToSlash(resolved), "/") {
+ if seg == ".worktrees" {
+ return fmt.Errorf("refusing to run with repo root %s: it lives inside a git worktree (.worktrees/); materialized links would dangle when the worktree is removed — run from the canonical checkout", repoRoot)
+ }
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** The function refuses any path containing a segment named `.worktrees`, regardless of whether that directory is a Git worktree container. A valid canonical checkout located at a path such as `/srv/.worktrees/project` is rejected even when `.worktrees` is an ordinary directory name.
**Triggers:** When a canonical repository is stored beneath a directory literally named `.worktrees`.
**Suggested fix:** Determine whether the root is actually a linked Git worktree, or restrict the check to the repository's intended worktree layout instead of rejecting every matching path segment.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: cmd/dotagents/config.go:26, cmd/dotagents/config.go:375
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cbb1be90c9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0694396191
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if fi, err := os.Stat(filepath.Join(resolved, ".git")); err == nil && fi.Mode().IsRegular() { | ||
| return refuse() |
There was a problem hiding this comment.
Check linked-worktree metadata above nested config roots
When an explicit config is in a subdirectory of an arbitrarily named linked worktree (for example, --config /tmp/agents-test/config/dotagents.yaml), the linked worktree's .git file is at /tmp/agents-test/.git, but this check probes only /tmp/agents-test/config/.git; because the path also lacks a .worktrees segment, the guard permits sync and recreates the dangling-link failure it is intended to prevent. Walk ancestors or query Git for the resolved root rather than checking only the config directory.
AGENTS.md reference: AGENTS.md:L5-L9
Useful? React with 👍 / 👎.
Summary by Sourcery
Refuse setup and configuration loading when the repository root is a linked Git worktree.
Bug Fixes:
Enhancements:
Tests: