@@ -134,7 +134,11 @@ fn apply_diff_in_rebase(
134
134
let rewrit_id = target_commit. amend ( None , None , None , None , None , Some ( & tree) ) ?;
135
135
let rewrit_object = repo. find_object ( rewrit_id, None ) ?;
136
136
let rewrit_commit_id = repo. find_commit ( rewrit_object. id ( ) ) ?. id ( ) ;
137
- branches. retarget_branches ( target_commit. id ( ) , rewrit_commit_id, rebase) ?;
137
+ let retargeted =
138
+ branches. retarget_branches ( target_commit. id ( ) , rewrit_commit_id, rebase) ?;
139
+ for b in retargeted {
140
+ println ! ( "{}" , b) ;
141
+ }
138
142
139
143
repo. reset ( & rewrit_object, git2:: ResetType :: Soft , None ) ?;
140
144
}
@@ -162,7 +166,10 @@ fn do_rebase_inner(
162
166
let message = commit. message ( ) ;
163
167
if message. is_some ( ) && message != fixup_message {
164
168
let new_id = rebase. commit ( None , & sig, None ) ?;
165
- branches. retarget_branches ( commit. id ( ) , new_id, rebase) ?;
169
+ let retargeted = branches. retarget_branches ( commit. id ( ) , new_id, rebase) ?;
170
+ for b in retargeted {
171
+ println ! ( "{}" , b) ;
172
+ }
166
173
}
167
174
}
168
175
Some ( Fixup ) | Some ( Squash ) | Some ( Exec ) | Some ( Edit ) | Some ( Reword ) => {
@@ -178,6 +185,21 @@ fn do_rebase_inner(
178
185
179
186
struct RepoBranches < ' a > ( HashMap < Oid , Vec < Branch < ' a > > > ) ;
180
187
188
+ struct RetargetedBranch {
189
+ name : String ,
190
+ from : Oid ,
191
+ to : Oid ,
192
+ }
193
+
194
+ impl std:: fmt:: Display for RetargetedBranch {
195
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
196
+ let from = & self . from . to_string ( ) [ ..15 ] ;
197
+ let to = & self . to . to_string ( ) [ ..15 ] ;
198
+ let name = & self . name ;
199
+ f. write_fmt ( format_args ! ( "updated branch {name}: {from} -> {to}" ) )
200
+ }
201
+ }
202
+
181
203
impl < ' a > RepoBranches < ' a > {
182
204
fn for_repo ( repo : & ' a Repository ) -> Result < RepoBranches < ' a > , anyhow:: Error > {
183
205
let mut branches: HashMap < Oid , Vec < Branch > > = HashMap :: new ( ) ;
@@ -194,18 +216,28 @@ impl<'a> RepoBranches<'a> {
194
216
original_commit : Oid ,
195
217
target_commit : Oid ,
196
218
rebase : & mut Rebase < ' _ > ,
197
- ) -> Result < ( ) , anyhow:: Error > {
219
+ ) -> Result < Vec < RetargetedBranch > , anyhow:: Error > {
220
+ let mut retargeted = vec ! [ ] ;
198
221
if let Some ( branches) = self . 0 . get_mut ( & original_commit) {
199
222
// Don't retarget the last branch, rebase.finish does that for us
200
223
if rebase. operation_current ( ) != Some ( rebase. len ( ) - 1 ) {
201
224
for branch in branches. iter_mut ( ) {
225
+ retargeted. push ( RetargetedBranch {
226
+ name : branch
227
+ . name ( )
228
+ . context ( "getting a branch name" ) ?
229
+ . ok_or ( anyhow ! ( "branch should have a name" ) ) ?
230
+ . to_owned ( ) ,
231
+ from : original_commit,
232
+ to : target_commit,
233
+ } ) ;
202
234
branch
203
235
. get_mut ( )
204
236
. set_target ( target_commit, "git-instafix retarget historical branch" ) ?;
205
237
}
206
238
}
207
239
}
208
- Ok ( ( ) )
240
+ Ok ( retargeted )
209
241
}
210
242
}
211
243
0 commit comments