Skip to content

Commit e34aa02

Browse files
committed
save_and_return_to_workspace now uses rebase engine
1 parent c9f9fc7 commit e34aa02

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/gitbutler-edit-mode/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ gitbutler-diff.workspace = true
2424
gitbutler-stack.workspace = true
2525
gitbutler-cherry-pick.workspace = true
2626
gitbutler-workspace.workspace = true
27+
but-workspace.workspace = true
28+
but-rebase.workspace = true
2729
serde.workspace = true
2830
tracing.workspace = true
2931

crates/gitbutler-edit-mode/src/lib.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::str::FromStr;
44

55
use anyhow::{bail, Context, Result};
66
use bstr::ByteSlice;
7+
use but_workspace::stack_ext::StackExt;
78
use git2::build::CheckoutBuilder;
89
use gitbutler_branch_actions::internal::list_virtual_branches;
910
use gitbutler_branch_actions::{update_workspace_commit, RemoteBranchFile};
@@ -19,12 +20,13 @@ use gitbutler_operating_modes::{
1920
OperatingMode, EDIT_BRANCH_REF, WORKSPACE_BRANCH_REF,
2021
};
2122
use gitbutler_oxidize::{
22-
git2_to_gix_object_id, gix_to_git2_index, GixRepositoryExt, OidExt, RepoExt,
23+
git2_to_gix_object_id, gix_to_git2_index, GixRepositoryExt, ObjectIdExt, OidExt, RepoExt,
2324
};
2425
use gitbutler_project::access::{WorktreeReadPermission, WorktreeWritePermission};
2526
use gitbutler_reference::{ReferenceName, Refname};
26-
use gitbutler_repo::{rebase::cherry_rebase, RepositoryExt};
27+
use gitbutler_repo::RepositoryExt;
2728
use gitbutler_repo::{signature, SignaturePurpose};
29+
use gitbutler_stack::stack_context::CommandContextExt;
2830
use gitbutler_stack::{Stack, VirtualBranchesHandle};
2931
use gitbutler_workspace::branch_trees::{update_uncommited_changes_with_tree, WorkspaceState};
3032
#[allow(deprecated)]
@@ -301,10 +303,23 @@ pub(crate) fn save_and_return_to_workspace(
301303
.context("Failed to commit new commit")?;
302304

303305
let gix_repo = repository.to_gix()?;
304-
// Rebase all all commits on top of the new commit and update reference
305-
let new_branch_head = cherry_rebase(ctx, new_commit_oid, commit.id(), stack.head(&gix_repo)?)
306-
.context("Failed to rebase commits onto new commit")?
307-
.unwrap_or(new_commit_oid);
306+
307+
let mut steps = stack.as_rebase_steps(ctx, &gix_repo)?;
308+
// swap out the old commit with the new, updated one
309+
steps.iter_mut().for_each(|step| {
310+
if let but_rebase::RebaseStep::Pick { commit_id, .. } = step {
311+
if commit.id() == commit_id.to_git2() {
312+
*commit_id = new_commit_oid.to_gix();
313+
}
314+
}
315+
});
316+
let stack_ctx = ctx.to_stack_context()?;
317+
let merge_base = stack.merge_base(&stack_ctx)?;
318+
let mut rebase = but_rebase::Rebase::new(&gix_repo, Some(merge_base.to_gix()), None)?;
319+
rebase.rebase_noops(false);
320+
rebase.steps(steps)?;
321+
let output = rebase.rebase()?;
322+
let new_branch_head = output.top_commit.to_git2();
308323

309324
// Update virtual_branch
310325
let (new_branch_head, new_branch_tree) = if ctx.app_settings().feature_flags.v3 {
@@ -316,6 +331,7 @@ pub(crate) fn save_and_return_to_workspace(
316331
};
317332

318333
stack.set_stack_head(&vb_state, &gix_repo, new_branch_head, new_branch_tree)?;
334+
stack.set_heads_from_rebase_output(ctx, output.references)?;
319335

320336
// Switch branch to gitbutler/workspace
321337
repository

0 commit comments

Comments
 (0)