@@ -58,7 +58,7 @@ fn do_squash_commits(
58
58
ctx : & CommandContext ,
59
59
stack_id : StackId ,
60
60
mut source_ids : Vec < git2:: Oid > ,
61
- desitnation_id : git2:: Oid ,
61
+ destination_id : git2:: Oid ,
62
62
perm : & mut WorktreeWritePermission ,
63
63
) -> Result < git2:: Oid > {
64
64
let old_workspace = WorkspaceState :: create ( ctx, perm. read_permission ( ) ) ?;
@@ -87,7 +87,7 @@ fn do_squash_commits(
87
87
source_ids_in_order. push ( * id) ;
88
88
false
89
89
}
90
- id if * id == desitnation_id => {
90
+ id if * id == destination_id => {
91
91
// Add the destination id to the source ids in order
92
92
source_ids_in_order. push ( * id) ;
93
93
true
@@ -105,7 +105,7 @@ fn do_squash_commits(
105
105
if let Some ( pos) = branch
106
106
. commit_ids
107
107
. iter ( )
108
- . position ( |& id| id == desitnation_id )
108
+ . position ( |& id| id == destination_id )
109
109
{
110
110
branch. commit_ids . splice ( pos..=pos, source_ids. clone ( ) ) ;
111
111
}
@@ -117,6 +117,8 @@ fn do_squash_commits(
117
117
None
118
118
} ;
119
119
120
+ let mut destination_id = destination_id;
121
+
120
122
// update source ids from the mapping if present
121
123
if let Some ( mapping) = mapping {
122
124
for ( _, old, new) in mapping. iter ( ) {
@@ -128,6 +130,11 @@ fn do_squash_commits(
128
130
. unwrap ( ) ;
129
131
source_ids[ index] = new. to_git2 ( ) ;
130
132
}
133
+
134
+ // if destination_id is old, replace it with new
135
+ if destination_id == old. to_git2 ( ) {
136
+ destination_id = new. to_git2 ( ) ;
137
+ }
131
138
}
132
139
} ;
133
140
@@ -147,24 +154,16 @@ fn do_squash_commits(
147
154
. collect_vec ( ) ;
148
155
149
156
// Find the new destination commit using the change id, error if not found
150
- let destination_change_id = ctx. repo ( ) . find_commit ( desitnation_id) ?. change_id ( ) ;
151
157
let destination_commit = branch_commits
152
158
. iter ( )
153
- . find ( |c| c. change_id ( ) == destination_change_id )
159
+ . find ( |c| c. id ( ) == destination_id )
154
160
. context ( "Destination commit not found in the stack" ) ?;
155
161
156
162
// Find the new source commits using the change ids, error if not found
157
163
let source_commits = source_ids
158
164
. iter ( )
159
165
. filter_map ( |id| ctx. repo ( ) . find_commit ( * id) . ok ( ) )
160
- . map ( |c| {
161
- branch_commits
162
- . iter ( )
163
- . find ( |b| b. change_id ( ) == c. change_id ( ) )
164
- . cloned ( )
165
- . context ( "Source commit not found in the stack" )
166
- } )
167
- . collect :: < Result < Vec < _ > > > ( ) ?;
166
+ . collect :: < Vec < _ > > ( ) ;
168
167
169
168
validate (
170
169
ctx,
0 commit comments