Prevent checkout under an external index lock - #15641
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Pull request overview
This PR adds an early “index lock” preflight to but_core::worktree::safe_checkout_from_head() so a checkout fails immediately if the worktree’s index is already externally locked, preventing libgit2 from partially mutating the worktree before reporting the error. It also adds regression tests covering repository-state preservation and correct index-path handling for linked worktrees.
Changes:
- Add a preflight probe for the worktree’s index lock before invoking libgit2 checkout logic.
- Add tests ensuring an external index lock prevents any checkout side effects (worktree/index/HEAD/ref) and that linked worktrees use their own index path.
- Wire the new test module into the existing worktree test suite.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/but-core/src/worktree/checkout/function.rs |
Adds an early index-lock acquisition attempt to fail before libgit2 performs any worktree mutations. |
crates/but-core/tests/core/worktree/mod.rs |
Registers the new checkout_index_lock test module. |
crates/but-core/tests/core/worktree/checkout_index_lock.rs |
New regression tests for index-lock preflight behavior and linked-worktree index paths. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 569a4873d9
ℹ️ 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".
569a487 to
e35d420
Compare
Context
Trigger: run safe checkout while the repository index is already locked by another process.
Symptom: checkout can change worktree files before returning the index-lock error, leaving a failed operation partially applied.
Change
Probe the exact worktree index lock before checkout starts. A lock held at the probe now fails before worktree, index, HEAD, or ref mutation; uncontended checkout behavior stays on the existing libgit2 path. This is a fail-fast preflight, not full checkout serialization: contention beginning after the probe remains outside this bounded change. Regression coverage includes repository-state preservation and linked-worktree index paths.
Related: #5390