Skip to content

fix(repo): refuse a conflict stop that would overwrite an untracked file - #187

Merged
tonibergholm-codento merged 4 commits into
mainfrom
stop-overwrite
Oct 19, 2026
Merged

tonibergholm-codento merged 4 commits into
mainfrom
stop-overwrite

Conversation

@tonibergholm

@tonibergholm tonibergholm commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes ADR-0049 q21. A stopped merge, pick or rebase writes protected conflict text and binary-conflict sidecars with plain writes, outside materialize. If the user kept an ignored or untracked copy at that path (the usual "stop tracking, keep it ignored" move), the write replaced it, and since #186 abort then deletes the path.

materialize_conflict_state now refuses before any write when a plaintext or sidecar path exists on disk and the tree the working tree reflects does not track it. The message asks the user to move the file and retry.

Not changed: a clean merge, pick or rebase still overwrites an untracked file that a materialized added file lands on. That is materialize's behaviour and a wider decision (git refuses; here it has always overwritten).

Tests

  • a_conflict_stop_refuses_to_overwrite_an_untracked_local_copy: the pick is refused, nothing in progress, tip unmoved, the local copy untouched. Fails with the guard disabled.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Merge, cherry-pick, and rebase now stop before writing conflict files if an untracked or ignored local file would be overwritten, or a file blocks a required directory.
    • Existing local files are preserved, and the operation is not recorded as started when a conflict write is blocked.

The stop writes plaintext and sidecars with plain writes outside
materialize. A file already on disk at one of those paths that the
working tree's tree does not track is the user's own, typically an
ignored local copy, and abort then deleted it. Refuse before any write.

Resolves ADR-0049 q21.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T15:24:40.789309Z e3da68b New commits
🔒 Security Review ✅ Completed 2026-10-18T15:24:25.455936Z e3da68b New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 717cbb78-9f3c-4188-b599-2ef69b081f1f
📥 Commits

Reviewing files that changed from the base of the PR and between d4846d4 and e3da68b.

📒 Files selected for processing: 3
  • crates/repo/src/replay.rs
  • crates/repo/src/repo.rs
  • docs/adr/0049-merge-on-partial-clones.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

Conflict-state materialization now checks plaintext and sidecar destinations before writing. It refuses when untracked content occupies a destination or blocks a required parent directory. New unit and replay tests cover these conditions, and the ADR records the guard's scope.

Changes: Conflict-stop write protection

Layer / File(s) Summary
Write-target checks and blocker classification
crates/repo/src/repo.rs, docs/adr/0049-merge-on-partial-clones.md
stop_write_blocker classifies occupied targets and blocking parent files. materialize_conflict_state checks plaintext and sidecar destinations before writing. Unit tests cover tracked and untracked targets, parent files, directories, and missing paths. The ADR records the guard's scope.
Replay conflict-stop regression coverage
crates/repo/src/replay.rs
Cherry-pick and merge tests cover ignored local copies, an untracked .theirs sidecar, and a file blocking a required parent directory. The tests check that operations return InvalidArgument and preserve local files without recording conflict state.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e3da6

Stopped merges, cherry-picks, and rebases now refuse before writing conflict files over untracked local copies, sidecars, or blocking parent files, which protects user data. No new risk was found, and the change looks ready to merge.

Security architecture risk: 🔵 Low · up to e3da6

The change prevents ordinary conflict stops from overwriting ignored or untracked files without expanding operation privileges or entrypoints. Existing non-atomic writes remain vulnerable to concurrent filesystem replacement, but that exposure predates this change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A path-replacement attack requires an actor able to mutate a checked worktree path or ancestor while the victim executes a conflict stop. A replacement symlink can redirect a later write outside the worktree to a destination writable by the victim process. Repository content alone was not established as sufficient for this race.

Security Findings and Attack Paths

  • observed — The retained security finding concerns separate path inspection and filesystem use. The new guard does not atomically reserve checked paths. Base-to-head comparison shows that symlink-following direct writes and their existing callers predate this PR; the change reduces ordinary collision exposure without establishing a new attack path or increasing authority.

Trust Boundaries and Controls

  • observed — The guard uses symlink_metadata to classify existing occupants without following their final symlink. Untracked symlinks and non-directory parent obstructions are refused, but this is an ownership preflight rather than a race-resistant filesystem containment boundary.

Resilience and Maintainability Implications

  • inferred — Preflight improves failure containment for predictable obstructions but does not make conflict materialization transactional. Interruption or a later write failure can leave plaintext ownership metadata and partially written files before operation state exists. That recovery gap also exists in the base and is not an active PR-introduced concern.

Hardening Proposals

  • proposed — If protection against concurrent untrusted worktree mutation is required, define that ownership contract explicitly and use race-resistant, no-follow filesystem operations rather than treating preflight as a reservation. Validate path replacement and interrupted-write recovery separately from ordinary collision refusal.
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing conflict-stop operations from overwriting untracked files.
Docstring Coverage Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f1c54286b

ℹ️ 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".

Comment thread crates/repo/src/repo.rs Resolved
tonibergholm and others added 2 commits October 18, 2026 18:11
…uard

A full clone with a sparse view can track a path the view never
materialized. A file there is the user's own, so the conflict-stop guard
no longer counts it as tracked.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A failed lookup now counts as untracked, a file standing where a parent
directory must be is refused before any write, a directory at the path is
named, and the message hints at a leftover sidecar. ADR-0049 q21 scopes
the guard to merge, pick and rebase; the private-branch merge stop has
none. Adds sidecar and blocked-parent tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 860adda4b0

ℹ️ 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".

Comment thread crates/repo/src/repo.rs Resolved
Comment thread crates/repo/src/repo.rs Resolved
…ry target

The conflict-stop guard rejected a tracked file standing where the result
puts a directory, though materialize removes it first. It also accepted a
directory at a path the old tree tracks as a file. The decision is now a
small function with unit tests for both transitions.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tonibergholm-codento
tonibergholm-codento merged commit fc60d64 into main Oct 19, 2026
8 checks passed
@tonibergholm
tonibergholm deleted the stop-overwrite branch October 19, 2026 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants