@@ -7,24 +7,26 @@ use gitbutler_repo::{
7
7
rebase:: cherry_rebase_group,
8
8
} ;
9
9
use gitbutler_stack:: { OwnershipClaim , Stack , StackId } ;
10
+ use tracing:: instrument;
10
11
11
12
use crate :: VirtualBranchesExt as _;
12
13
13
14
/// Removes a commit from a branch by rebasing all commits _except_ for it
14
15
/// onto it's parent.
15
16
///
16
- /// if successful, it will update the branch head to the new head commit.
17
+ /// If successful, it will update the branch head to the new head commit.
17
18
///
18
19
/// It intentionally does **not** update the branch tree. It is a feature
19
20
/// of the operation that the branch tree will not be updated as it allows
20
21
/// the user to then re-commit the changes if they wish.
21
22
///
22
23
/// This may create conflicted commits above the commit that is getting
23
24
/// undone.
25
+ #[ instrument( level = tracing:: Level :: DEBUG , skip( ctx) ) ]
24
26
pub ( crate ) fn undo_commit (
25
27
ctx : & CommandContext ,
26
28
stack_id : StackId ,
27
- commit_oid : git2:: Oid ,
29
+ commit_to_remove : git2:: Oid ,
28
30
) -> Result < Stack > {
29
31
let vb_state = ctx. project ( ) . virtual_branches ( ) ;
30
32
@@ -33,15 +35,15 @@ pub(crate) fn undo_commit(
33
35
let UndoResult {
34
36
new_head : new_head_commit,
35
37
ownership_update,
36
- } = inner_undo_commit ( ctx. repo ( ) , stack. head ( ) , commit_oid ) ?;
38
+ } = rebase_all_but_last ( ctx. repo ( ) , stack. head ( ) , commit_to_remove ) ?;
37
39
38
40
for ownership in ownership_update {
39
41
stack. ownership . put ( ownership) ;
40
42
}
41
43
42
44
stack. set_stack_head ( ctx, new_head_commit, None ) ?;
43
45
44
- let removed_commit = ctx. repo ( ) . find_commit ( commit_oid ) ?;
46
+ let removed_commit = ctx. repo ( ) . find_commit ( commit_to_remove ) ?;
45
47
stack. replace_head ( ctx, & removed_commit, & removed_commit. parent ( 0 ) ?) ?;
46
48
47
49
crate :: integration:: update_workspace_commit ( & vb_state, ctx)
@@ -55,7 +57,8 @@ struct UndoResult {
55
57
ownership_update : Vec < OwnershipClaim > ,
56
58
}
57
59
58
- fn inner_undo_commit (
60
+ #[ instrument( level = tracing:: Level :: DEBUG , skip( repository) ) ]
61
+ fn rebase_all_but_last (
59
62
repository : & git2:: Repository ,
60
63
branch_head_commit : git2:: Oid ,
61
64
commit_to_remove : git2:: Oid ,
@@ -82,14 +85,13 @@ fn inner_undo_commit(
82
85
. hunks
83
86
. iter ( )
84
87
. map ( Into :: into)
85
- . filter ( |hunk : & Hunk | hunk . start != 0 && hunk. end != 0 )
88
+ . filter ( |hunk : & Hunk | ! hunk. is_null ( ) )
86
89
. collect :: < Vec < _ > > ( ) ;
87
90
if hunks. is_empty ( ) {
88
91
return None ;
89
92
}
90
- Some ( ( file_path, hunks) )
93
+ Some ( OwnershipClaim { file_path, hunks } )
91
94
} )
92
- . map ( |( file_path, hunks) | OwnershipClaim { file_path, hunks } )
93
95
. collect :: < Vec < _ > > ( ) ;
94
96
95
97
// if commit is the head, just set head to the parent
@@ -131,7 +133,7 @@ mod test {
131
133
assert_commit_tree_matches, TestingRepository ,
132
134
} ;
133
135
134
- use crate :: undo_commit:: { inner_undo_commit , UndoResult } ;
136
+ use crate :: undo_commit:: { rebase_all_but_last , UndoResult } ;
135
137
136
138
#[ test]
137
139
fn undoing_conflicted_commit_errors ( ) {
@@ -146,7 +148,7 @@ mod test {
146
148
147
149
// Branch looks like "A -> ConflictedCommit"
148
150
149
- let result = inner_undo_commit (
151
+ let result = rebase_all_but_last (
150
152
& test_repository. repository ,
151
153
conflicted_commit. id ( ) ,
152
154
conflicted_commit. id ( ) ,
@@ -169,7 +171,7 @@ mod test {
169
171
let UndoResult {
170
172
new_head,
171
173
ownership_update,
172
- } = inner_undo_commit ( & test_repository. repository , c. id ( ) , c. id ( ) ) . unwrap ( ) ;
174
+ } = rebase_all_but_last ( & test_repository. repository , c. id ( ) , c. id ( ) ) . unwrap ( ) ;
173
175
174
176
assert_eq ! ( new_head, b. id( ) , "The new head should be C's parent" ) ;
175
177
assert_eq ! (
@@ -208,7 +210,7 @@ mod test {
208
210
let UndoResult {
209
211
new_head,
210
212
ownership_update,
211
- } = inner_undo_commit ( & test_repository. repository , c. id ( ) , b. id ( ) ) . unwrap ( ) ;
213
+ } = rebase_all_but_last ( & test_repository. repository , c. id ( ) , b. id ( ) ) . unwrap ( ) ;
212
214
213
215
let new_head_commit: git2:: Commit =
214
216
test_repository. repository . find_commit ( new_head) . unwrap ( ) ;
0 commit comments