Skip to content

fix(repo): guard undo, sparse set and sparse disable against untracked files - #192

Merged
tonibergholm-codento merged 1 commit into
mainfrom
guard-undo-sparse
Oct 19, 2026
Merged

tonibergholm-codento merged 1 commit into
mainfrom
guard-undo-sparse

Conversation

@tonibergholm

@tonibergholm tonibergholm commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Problem

#191 guarded merge, switch, cherry-pick and rebase against laying a file onto an untracked or ignored one, and documented undo, sparse set and sparse disable as the remaining unguarded materialize paths. Each re-lays tracked files onto disk and silently replaced a user's file at the same path (undo restoring a deleted file over a new one; widening or disabling a sparse view over a file made where an out-of-view tracked path lives).

Change

  • undo runs refuse_untracked_overwrite("undo", head_root, restored_root) before any ref moves.
  • sparse set / sparse disable run the new refuse_untracked_for_view_change (the tree HEAD tracks, the old view's laid-out paths as the tracked set, the new view as the target) before the spec is stored or the removal pass runs, so a refusal leaves the spec, refs and files untouched. refuse_untracked_paths_in takes the view explicitly because the persisted spec is not the one in force while it changes.
  • ADR-0049 and CLAUDE.md updated; only merging into an unborn branch and the private-branch merge conflict stop remain unguarded.

Verification

  • New tests: undo refuses over an untracked file and moves no ref; sparse set and disable refuse over an untracked file at an out-of-view tracked path and leave the spec unchanged.
  • cargo fmt, cargo clippy --workspace --all-targets -D warnings, cargo test --workspace and demo/run_lazy_fetch_demo.sh pass.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Undo and sparse-view changes now stop when they would overwrite untracked files, preserving the files and leaving the operation unapplied.

…d files

They re-lay tracked files onto disk and silently replaced an untracked or
ignored file at the same path, like merge and switch did before #191. They
now refuse before any ref, spec or file write.

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

chatgpt-codex-connector Bot commented Oct 19, 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-19T08:02:08.430283Z 5a490bd PR opened
🔒 Security Review ✅ Completed 2026-10-19T08:03:26.193964Z 5a490bd PR opened
ℹ️ 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 19, 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: 71431862-4dcf-4c14-b0a9-72fc65c9deb4
📥 Commits

Reviewing files that changed from the base of the PR and between a71e1ac and 5a490bd.

📒 Files selected for processing: 6
  • CLAUDE.md
  • crates/repo/src/oplog.rs
  • crates/repo/src/replay.rs
  • crates/repo/src/repo.rs
  • crates/repo/src/sparse.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; 7 remain after this review.

📝 Walkthrough

Undo and sparse-view changes now refuse to overwrite untracked files. The checks run before undo restores refs or sparse operations change the stored specification. Tests verify that refusals preserve the branch tip, user files, and sparse specification.

Changes: Untracked overwrite guards

Layer / File(s) Summary
Sparse-view collision checks
crates/repo/src/repo.rs
Repo compares paths covered by the old and new sparse views, then checks target paths for on-disk untracked blockers using the new view.
Undo overwrite check
crates/repo/src/oplog.rs, crates/repo/src/replay.rs
Undo checks for untracked-file collisions before restoring refs. A test verifies that refusal leaves the branch tip and user file unchanged.
Sparse-view transition checks
crates/repo/src/sparse.rs, crates/repo/src/replay.rs, CLAUDE.md, docs/adr/0049-merge-on-partial-clones.md
Sparse set and disable check for collisions before changing the sparse specification. Tests verify that refusal preserves the specification and user file. The documentation lists undo and sparse-spec changes among guarded operations.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 5a490

The guarded operations have no identified merge-blocking risk. Normal checks remain appropriate before merging.

Security architecture risk: ⚪ Minimal · up to 5a490

The changes strengthen protection against overwriting user-owned files without adding privileges or new write capabilities. No material security regression was identified. Existing limitations around concurrent filesystem changes and interrupted operations remain.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed enforcement scope is the selected repository’s worktree paths that undo or a sparse-view transition would materialize. The PR adds refusal checks to existing write paths rather than introducing a new privileged sink or expanding their authority.

Trust Boundaries and Controls

  • observed — The newly guarded operations inherit checks against symlink redirection: symlink parents and symlink targets block the operation even when their names are tracked. Occupied untracked targets and target directories also block writes. Case aliases count as tracked only under the existing filesystem and file-identity checks.

Resilience and Maintainability Implications

  • inferred — The ownership check remains a point-in-time observation, not a filesystem reservation. The repository-lifetime lock prevents separately opened writers but does not establish serialization of same-handle operations or external filesystem edits between checking and writing. This limitation and post-mutation I/O failure exposure predate the PR; neither is retained as an introduced concern.
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 identifies the main change: adding untracked-file guards to undo, sparse set, and sparse disable.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 4 files. (2 skipped: 2…
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 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 4 files. (2 skipped: 2 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.

@tonibergholm-codento
tonibergholm-codento merged commit ada64b0 into main Oct 19, 2026
8 checks passed
@tonibergholm
tonibergholm deleted the guard-undo-sparse branch October 19, 2026 08:37
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