Skip to content

feat(worktree): never overwrite edits when checking out - #102

Open
PiquelChips wants to merge 1 commit into
feat/workspaces-durable-checkoutsfrom
feat/workspaces-safe-checkouts
Open

PiquelChips wants to merge 1 commit into
feat/workspaces-durable-checkoutsfrom
feat/workspaces-safe-checkouts

Conversation

@PiquelChips

Copy link
Copy Markdown
Member

A command that moves the working copy, such as edit, abandon, converge or following a landing, checked out over whatever was on disk. An edit made after its snapshot, while the command ran, was lost.

Given the stat cache of the snapshot it starts from, a checkout now:

  • first checks that no file it changes was edited since, by metadata or, for files the cache doesn't vouch for, by content, and changes nothing if one was.
  • checks each file again just before it replaces it, and stops at one edited in between.
  • never turns into a file a directory that still holds untracked files, such as a .git, a FIFO or a file created since.

A command that moves the working copy writes the new revision only once its checkout is done. A refused or failed checkout writes nothing, and takes back the files it changed with Worktree::restore, leaving edited ones as they are, so the working copy and its change stay where they were and the command can run again.

Review fix: any failed checkout takes its files back, not only one refused by an edit. Proved with a_move_that_fails_takes_its_files_back, which fails without the fix.

Note

Written by Claude Opus 5.5 in Claude Code (via T3 Code)

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3cae880a-0756-4da0-ac9c-20653908c590
Commits

Reviewing files that changed from the base of the PR and between ab12a78 and bf79111.

Files selected for processing: 5

  • apps/origin-src/benches/workspace.rs
  • apps/origin-src/src/workspace/land.rs
  • apps/origin-src/src/workspace/mod.rs
  • apps/origin-src/src/worktree.rs
  • apps/origin-src/tests/cli.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@PiquelChips
PiquelChips added this pull request to stack #165 November 22, 2026 14:59
@PiquelChips
PiquelChips force-pushed the feat/workspaces-safe-checkouts branch 2 times, most recently from 5f0d631 to 8ba2b01 Compare November 22, 2026 18:54
A command that moves the working copy, such as `edit`, `abandon`,
`converge` or following a landing, checked out over whatever was there:
an edit made after its snapshot, while the command ran, was lost.

With the stat cache of the snapshot, a checkout now first checks that
no file it changes was edited since, by metadata or, for files the cache
doesn't vouch for, by content, and changes nothing if one was. It checks
each file again just before it replaces it. A directory that still holds
untracked files, such as a `.git`, is never turned into a file.

A command moving the working copy writes the new revision only once its
checkout is done: a refused checkout writes nothing, and takes back the
files it changed with `Worktree::restore`, leaving edited ones as they
are, so the working copy and its change stay where they were.
@PiquelChips
PiquelChips force-pushed the feat/workspaces-safe-checkouts branch from 8ba2b01 to bf79111 Compare November 22, 2026 19:20
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.

1 participant