@@ -337,7 +337,7 @@ pub struct Executor {
337
337
branches : Vec < ( git2:: Oid , String ) > ,
338
338
delete_branches : Vec < String > ,
339
339
post_rewrite : Vec < ( git2:: Oid , git2:: Oid ) > ,
340
- head_id : git2:: Oid ,
340
+ head_id : Option < git2:: Oid > ,
341
341
dry_run : bool ,
342
342
detached : bool ,
343
343
}
@@ -349,7 +349,7 @@ impl Executor {
349
349
branches : Default :: default ( ) ,
350
350
delete_branches : Default :: default ( ) ,
351
351
post_rewrite : Default :: default ( ) ,
352
- head_id : git2 :: Oid :: zero ( ) ,
352
+ head_id : None ,
353
353
dry_run,
354
354
detached : false ,
355
355
}
@@ -362,15 +362,15 @@ impl Executor {
362
362
) -> Vec < ( git2:: Error , & ' s str , Vec < & ' s str > ) > {
363
363
let mut failures = Vec :: new ( ) ;
364
364
365
- self . head_id = repo. head_commit ( ) . id ;
365
+ self . head_id . get_or_insert_with ( || repo. head_commit ( ) . id ) ;
366
366
367
367
let onto_id = script. batches [ 0 ] . onto_mark ( ) ;
368
368
let labels = NamedLabels :: new ( ) ;
369
369
labels. register_onto ( onto_id) ;
370
370
for ( i, batch) in script. batches . iter ( ) . enumerate ( ) {
371
371
let branch_name = batch. branch ( ) . unwrap_or ( "detached" ) ;
372
372
if !failures. is_empty ( ) {
373
- log:: trace!( "Ignoring `{}`" , branch_name) ;
373
+ log:: trace!( "Igself.noring `{}`" , branch_name) ;
374
374
log:: trace!( "Script:\n {}" , batch. display( & labels) ) ;
375
375
continue ;
376
376
}
@@ -500,9 +500,9 @@ impl Executor {
500
500
}
501
501
502
502
pub fn update_head ( & mut self , old_id : git2:: Oid , new_id : git2:: Oid ) {
503
- if self . head_id == old_id && old_id != new_id {
503
+ if self . head_id . unwrap_or_else ( git2 :: Oid :: zero ) == old_id && old_id != new_id {
504
504
log:: trace!( "head changed from {} to {}" , old_id, new_id) ;
505
- self . head_id = new_id;
505
+ self . head_id = Some ( new_id) ;
506
506
}
507
507
}
508
508
@@ -604,10 +604,10 @@ impl Executor {
604
604
if !self . dry_run && self . detached {
605
605
repo. switch_branch ( restore_branch) ?;
606
606
}
607
- } else if self . head_id != git2 :: Oid :: zero ( ) {
608
- log:: trace!( "git switch {}" , self . head_id) ;
607
+ } else if let Some ( head_id) = self . head_id {
608
+ log:: trace!( "git switch {}" , head_id) ;
609
609
if !self . dry_run && self . detached {
610
- repo. switch_commit ( self . head_id ) ?;
610
+ repo. switch_commit ( head_id) ?;
611
611
}
612
612
}
613
613
0 commit comments