|
1 | | -#![expect( |
2 | | - deprecated, |
3 | | - reason = "VirtualBranchesHandle should be replaced with ctx.workspace_* helpers" |
4 | | -)] |
5 | | - |
6 | 1 | use anyhow::{Result, bail}; |
7 | | -use but_core::{DiffSpec, TreeChange, ref_metadata::StackId, sync::RepoExclusive}; |
| 2 | +use but_core::{DiffSpec, TreeChange, sync::RepoExclusive}; |
8 | 3 | use but_ctx::Context; |
9 | | -use but_rebase::{Rebase, replace_commit_tree}; |
10 | | -use gitbutler_stack::VirtualBranchesHandle; |
| 4 | +use but_rebase::replace_commit_tree; |
11 | 5 | use gix::ObjectId; |
12 | 6 |
|
13 | | -use super::MoveChangesResult; |
14 | | -use crate::legacy::{ |
15 | | - stack_ext::StackExt, |
16 | | - tree_manipulation::utils::{ |
17 | | - ChangesSource, create_tree_without_diff, rebase_mapping_with_overrides, |
18 | | - replace_pick_with_commit, |
19 | | - }, |
20 | | -}; |
21 | | - |
22 | | -/// Removes the specified changes from a given commit. |
23 | | -/// |
24 | | -/// This only updates the specified stack. After calling you may want to call |
25 | | -/// `update_workspace_commit` such that the workspace commit now contains the |
26 | | -/// updated head of the stack. |
27 | | -/// |
28 | | -/// You may want to make use of `update_uncommitted_changes`. Using it will |
29 | | -/// cause the specified change to be dropped from the working directory. Not |
30 | | -/// using it will result in the change showing up as an uncommitted change. |
31 | | -/// |
32 | | -/// ## Assumptions |
33 | | -/// |
34 | | -/// Currently this function does not take into consideration the possibility |
35 | | -/// that the commit _might_ be part of two different stacks. As such, the |
36 | | -/// other stacks may end up referring to stale commits and potentially cause |
37 | | -/// a merge conflict when combining them in the workspace. |
38 | | -pub fn remove_changes_from_commit_in_stack( |
39 | | - ctx: &mut Context, |
40 | | - source_stack_id: StackId, |
41 | | - source_commit_id: gix::ObjectId, |
42 | | - changes: impl IntoIterator<Item = DiffSpec>, |
43 | | - perm: &mut RepoExclusive, |
44 | | -) -> Result<MoveChangesResult> { |
45 | | - let vb_state = VirtualBranchesHandle::new(ctx.project_data_dir()); |
46 | | - let source_stack = vb_state.get_stack(source_stack_id)?; |
47 | | - |
48 | | - let rewritten_source_commit = remove_changes_from_commit(ctx, source_commit_id, changes, perm)?; |
49 | | - |
50 | | - let mut steps = source_stack.as_rebase_steps(ctx)?; |
51 | | - replace_pick_with_commit(&mut steps, source_commit_id, rewritten_source_commit)?; |
52 | | - let base = source_stack.merge_base(ctx)?; |
53 | | - |
54 | | - let result = { |
55 | | - let repo = ctx.repo.get()?; |
56 | | - let mut rebase = Rebase::new(&repo, base, None)?; |
57 | | - rebase.steps(steps)?; |
58 | | - rebase.rebase_noops(false); |
59 | | - rebase.rebase()? |
60 | | - }; |
61 | | - let commit_mapping = |
62 | | - rebase_mapping_with_overrides(&result, [(source_commit_id, rewritten_source_commit)]); |
63 | | - |
64 | | - let mut source_stack = source_stack; |
65 | | - source_stack.set_heads_from_rebase_output(ctx, result.references)?; |
66 | | - |
67 | | - let meta = ctx.meta()?; |
68 | | - let (repo, mut ws, _) = ctx.workspace_mut_and_db_with_perm(perm)?; |
69 | | - ws.refresh_from_head(&repo, &meta)?; |
70 | | - |
71 | | - Ok(MoveChangesResult { |
72 | | - replaced_commits: commit_mapping.into_iter().collect(), |
73 | | - }) |
74 | | -} |
| 7 | +use crate::legacy::tree_manipulation::utils::{ChangesSource, create_tree_without_diff}; |
75 | 8 |
|
76 | 9 | /// Removes the specified changes from a commit. |
77 | 10 | /// |
|
0 commit comments