(don't review) delete branch fix - #15280
Open
jonathantanmy2 wants to merge 1 commit into
Open
Conversation
jonathantanmy2
requested review from
Caleb-T-Owens,
estib-vega and
krlvi
as code owners
August 10, 2026 23:08
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts how branch/reference deletion is handled during workspace transactions to avoid leaving the workspace commit in a bad state, and adds/updates tests to validate post-delete repository topology.
Changes:
- Update
but-transaction::Transaction::remove_referenceto sometimes disconnect edges instead of replacing the reference node withStep::None. - Reorder discard operations so commit discards happen before branch ref removals.
- Add rebase-editor helpers (
target_selectorvisibility,Editor::step) and extend CLI tests withgit_log()assertions.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/but/tests/but/command/clean.rs | Adds git_log() assertion after but clean deletes an empty branch |
| crates/but/tests/but/command/branch/delete.rs | Adds git_log() assertions for multiple but branch delete scenarios |
| crates/but/src/command/legacy/discard.rs | Reorders commit discard vs branch ref removal for discard-branches flow |
| crates/but-transaction/src/lib.rs | Updates remove_reference to optionally remove edges from workspace commit instead of replacing the ref step |
| crates/but-transaction/Cargo.toml | Adds but-graph dependency needed by new remove-reference logic |
| crates/but-rebase/src/graph_rebase/workspace.rs | Makes target_selector public for cross-crate use |
| crates/but-rebase/src/graph_rebase/mutate.rs | Adds Editor::step helper |
| Cargo.lock | Records dependency graph update for but-graph |
Suppressed comments (3)
crates/but/tests/but/command/branch/delete.rs:101
- This test asserts exact commit SHAs in
git_log(), which is brittle. Prefer checking that C and B remain and that A is gone, without pinning hashes.
snapbox::assert_data_eq!(
env.git_log(),
snapbox::str![[r#"
* c4a9f43 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
* ec33a86 (C) add C
crates/but/tests/but/command/branch/delete.rs:148
- This test asserts exact commit SHAs in
git_log(), which is brittle. Prefer checking that C and A remain and that B is gone, without pinning hashes.
snapbox::assert_data_eq!(
env.git_log(),
snapbox::str![[r#"
* ea6cfac (HEAD -> gitbutler/workspace) GitButler Workspace Commit
* 983f317 (C) add C
crates/but/tests/but/command/branch/delete.rs:195
- This test asserts exact commit SHAs in
git_log(), which is brittle. Prefer checking that A and B remain and that C is gone, without pinning hashes.
snapbox::assert_data_eq!(
env.git_log(),
snapbox::str![[r#"
* 5299ad0 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
* 582f37b (B) add B
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+281
to
+284
| /// Get the step | ||
| pub fn step(&self, target: impl ToSelector) -> Result<Step> { | ||
| Ok(self.graph[target.to_selector(self)?.id].clone()) | ||
| } |
Comment on lines
+380
to
+384
| let step = editor.step(ancestor_selector)?; | ||
| if matches!(step, Step::None) | ||
| || matches!(step, Step::Reference{refname, ..} | ||
| if refname.as_bstr() == b"refs/heads/main") | ||
| { |
Comment on lines
+37
to
+47
| snapbox::assert_data_eq!( | ||
| env.git_log(), | ||
| snapbox::str![[r#" | ||
| * 0e97f4a (HEAD -> gitbutler/workspace) GitButler Workspace Commit | ||
| |/ | ||
| | * 9477ae7 (A) add A | ||
| |/ | ||
| * 0dc3733 (origin/main, origin/HEAD, main, gitbutler/target) add M | ||
|
|
||
| "#]] | ||
| ); |
Comment on lines
+51
to
+59
| snapbox::assert_data_eq!( | ||
| env.git_log(), | ||
| snapbox::str![[r#" | ||
| * 082c0c2 (HEAD -> gitbutler/workspace) GitButler Workspace Commit | ||
| * d3e2ba3 (B) add B | ||
| * 0dc3733 (origin/main, origin/HEAD, main, gitbutler/target, A) add M | ||
|
|
||
| "#]] | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.