Skip to content

(don't review) delete branch fix - #15280

Open
jonathantanmy2 wants to merge 1 commit into
masterfrom
jt/deletebranch
Open

(don't review) delete branch fix#15280
jonathantanmy2 wants to merge 1 commit into
masterfrom
jt/deletebranch

Conversation

@jonathantanmy2

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI lite review requested due to automatic review settings August 10, 2026 23:08
@github-actions github-actions Bot added rust Pull requests that update Rust code CLI The command-line program `but` labels Aug 10, 2026

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

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_reference to sometimes disconnect edges instead of replacing the reference node with Step::None.
  • Reorder discard operations so commit discards happen before branch ref removals.
  • Add rebase-editor helpers (target_selector visibility, Editor::step) and extend CLI tests with git_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

"#]]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI The command-line program `but` rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants