Skip to content

feat: add leaf-only tree-editor removal#2654

Merged
Sebastian Thiel (Byron) merged 1 commit into
mainfrom
tree-editor-improvement
Jun 19, 2026
Merged

feat: add leaf-only tree-editor removal#2654
Sebastian Thiel (Byron) merged 1 commit into
mainfrom
tree-editor-improvement

Conversation

@Byron

@Byron Sebastian Thiel (Byron) commented Jun 19, 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-5.

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

Reported issue

Byron asked Codex to take a look at https://github.com/gitbutlerapp/gitbutler/pull/14312/commits and see if this commit-message comment could be resolved by adding such an API:

In order to prevent issues like this from happening in the future,
ideally gix would have an API to delete a leaf entry (returning an
error if the entry to be deleted was a non-leaf - in the example above,
deleting "A" when "A/one" is present would be an error), but looking at
its documentation, I don't think such an API exists.

Motivation: gitbutlerapp/gitbutler#14312

Summary

  • Added remove_leaf() to gix_object::tree::Editor and cursor, preserving existing remove() semantics.
  • Exposed remove_leaf() through the public gix tree editor and cursor wrappers.
  • Added regression coverage for rejecting tree entries, tolerating absent paths, preserving empty-tree no-ops, and validating malformed trailing path components.

Validation

  • cargo fmt --all
  • cargo test -p gix-object --test object from_empty_remove_leaf_rejects_tree_entries
  • cargo test -p gix-object --test object tree::editor
  • cargo test -p gix --test gix repository::object::edit_tree
  • cargo check -p gix-object -p gix --features tree-editor
  • cargo check -p gix --no-default-features --features tree-editor,sha1
  • cargo check -p gix-object -p gix --no-default-features --features tree-editor,sha1
  • git diff --check
  • codex review --commit 829533b5f52ee35e578984a82e092f566b947292

@Byron
Sebastian Thiel (Byron) marked this pull request as ready for review June 19, 2026 04:30
Copilot AI review requested due to automatic review settings June 19, 2026 04:30
Motivation comes from gitbutlerapp/gitbutler#14312,
where callers had to split tree-entry deletions from additions to avoid
accidentally deleting a newly-added subtree after adding A/one and then deleting
A.

Add Editor::remove_leaf() to gix-object and expose it through gix object tree
editors and cursors. The new API keeps remove() behavior unchanged, remains
tolerant of absent paths, but returns an error when the target entry exists and
is a tree.

Co-authored-by: Sebastian Thiel <[email protected]>

Copilot AI 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.

Pull request overview

This PR introduces a “leaf-only” tree-editor removal API to prevent accidental deletion of entire subtrees when a caller intends to remove only a leaf entry. It adds remove_leaf() in the plumbing gix-object editor and wires it through higher-level wrappers, with new regression tests covering the intended semantics.

Changes:

  • Add remove_leaf() to gix_object::tree::Editor and its Cursor, returning an error when the target is a tree.
  • Expose remove_leaf() through the gix tree editor and cursor wrappers.
  • Add tests ensuring leaf-only removal rejects trees, tolerates absent paths, and handles empty/unreachable path segments as intended.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
gix-object/src/tree/editor.rs Adds remove_leaf() and refactors edit operations to support leaf-only vs any removal modes.
gix-object/tests/object/tree/editor.rs Adds regression tests for leaf-only removal behavior and unreachable empty path components.
gix/src/object/tree/editor.rs Exposes remove_leaf() on the public gix tree editor and cursor wrappers.
gix/tests/gix/repository/object.rs Adds an integration test asserting tree entries are rejected by leaf-only removal.
src/object/tree/editor.rs Introduces a tree editor wrapper module (currently appears misplaced/orphaned) and adds remove_leaf() on its cursor/editor API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gix-object/src/tree/editor.rs
@Byron
Sebastian Thiel (Byron) merged commit f051396 into main Jun 19, 2026
32 checks passed
@Byron
Sebastian Thiel (Byron) deleted the tree-editor-improvement branch June 19, 2026 06:12
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.

3 participants