Skip to content

feat(gix)!: add worktree locking and a lock override that preserves changes - #3058

Merged
Sebastian Thiel (Byron) merged 1 commit into
mainfrom
worktree-improvements
Oct 13, 2026
Merged

Sebastian Thiel (Byron) merged 1 commit into
mainfrom
worktree-improvements

Conversation

@Byron

@Byron Byron commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Tasks

This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.

  • refackiew

Everything below this line was generated by Codex GPT-6.

Created by Codex on behalf of Byron. Byron will review before this is ready to merge.

Linked worktrees can now be locked, have their reason updated, or be unlocked through Worktree::set_lock(Option<&BStr>) and worktree::Proxy::set_lock(). The shared implementation is gix_worktree::set_lock(), with Git-compatible byte-oriented reasons, idempotent unlocking, and protection against writing through lock-file symlinks. The proxy also supports offline checkouts; the porcelain rejects main-worktree locking.

Force::OverrideLockKeepChanges removes clean locked worktrees while rejecting staged, unstaged, untracked, or initialized-submodule state. Existing OverrideLock and CLI force levels retain their destructive behavior. Adding the enum variant requires downstream exhaustive-match updates; this PR includes the Tix adaptation.

Reported issue

Add a way to lock and unlock a worktree, probably with something set_lock(Option<Reason>). Also add a variant to Force::OverrideLock that overrides locks, but doesn't discard changes.
Be sure to work plumbing-up where it makes sense.

Validation

  • Regression tests failed for the missing APIs before implementation.
  • 60 gix worktree tests and 47 gix-worktree integration tests pass, including interoperability with Git and preservation of local changes.
  • Commit review reproduced a blocked write when locked was a FIFO. Existing non-regular files are now rejected before opening, with a bounded isolated regression that failed on the original implementation.
  • Clippy passes with warnings denied for all targets of gix, gix-worktree, and gix-tix.
  • Minimal-feature checks pass for gix with and without worktree mutation, and for gix-worktree.
  • Formatting and rustdoc pass with gix's blocking-network-client feature. Default-feature-only docs expose an existing unrelated with_fetch_options link failure in clone documentation.

Git reference: v2.56.0-116-g6de20f6092 (6de20f6092dcf9bdb1c8efe03db4b70c82b423dd), builtin/worktree.c, wrapper.c, and t/t2403-worktree-move.sh. Git's worktree remove -ff bypasses both lock and cleanliness checks; the new enum variant allows bypassing only the lock. Concurrent updates to a worktree's lock must be serialized by the caller, as documented.

…hanges

<!-- agent -->
Expose `Worktree::set_lock(Option<&BStr>)` and `worktree::Proxy::set_lock()`
so callers can protect linked worktrees from pruning, moving, or removal,
including when their checkout is offline. Implement file handling in
`gix_worktree::set_lock()`: preserve byte-oriented reasons, append Git's
trailing newline when needed, and make unlocking idempotent. Reject the
main worktree in the porcelain and avoid writing through lock-file symlinks.

Previously `Force::OverrideLock` also discarded local changes and initialized
submodules. Add `Force::OverrideLockKeepChanges` to bypass just the lock check,
retaining status and submodule validation. This expands an exhaustive public
enum, so adapt the Tix caller in the same commit; existing CLI force levels
retain their behavior.

Git reference: `v2.56.0-116-g6de20f6092`
(`6de20f6092dcf9bdb1c8efe03db4b70c82b423dd`), `builtin/worktree.c`
lock/unlock/removal, `wrapper.c` newline encoding, and
`t/t2403-worktree-move.sh`. Git's `worktree remove -ff` bypasses both lock and
cleanliness checks; the new mode deliberately permits bypassing only the lock.
exposes a pre-existing unresolved `with_fetch_options` link in clone docs.

Assisted-by: GPT 6.1 Sol
Co-authored-by: GPT 6.1 Sol <codex@openai.com>
@Byron
Sebastian Thiel (Byron) marked this pull request as ready for review October 13, 2026 07:00
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Contributor

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-13T07:04:17.558438Z 862e9c3 Draft marked ready
ℹ️ About Codex in GitHub

Your 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.

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

Copy link
Copy Markdown
Contributor

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: 862e9c3b8c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread gix/src/worktree/remove.rs
@Byron
Sebastian Thiel (Byron) merged commit 79f3880 into main Oct 13, 2026
33 checks passed
@Byron
Sebastian Thiel (Byron) deleted the worktree-improvements branch October 13, 2026 09:39
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