@@ -12,6 +12,9 @@ use std::io::Write;
1212pub struct Config < ' a > {
1313 pub dry_run : bool ,
1414 pub force_author : bool ,
15+ pub force_detach : bool ,
16+ // force should only be used to enable oher force_* values when unifiying the config.
17+ // Do not access when disabling individual safety checks.
1518 pub force : bool ,
1619 pub base : Option < & ' a str > ,
1720 pub and_rebase : bool ,
@@ -30,7 +33,13 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository
3033 let config = config:: unify ( & config, repo) ;
3134 // have force flag enable all force* flags
3235
33- let stack = stack:: working_stack ( repo, config. base , config. force_author , config. force , logger) ?;
36+ let stack = stack:: working_stack (
37+ repo,
38+ config. base ,
39+ config. force_author ,
40+ config. force_detach ,
41+ logger,
42+ ) ?;
3443 if stack. is_empty ( ) {
3544 crit ! ( logger, "No commits available to fix up, exiting" ) ;
3645 return Ok ( ( ) ) ;
@@ -614,7 +623,7 @@ mod tests {
614623 let result = run_with_repo ( & logger, & DEFAULT_CONFIG , & ctx. repo ) ;
615624 assert_eq ! (
616625 result. err( ) . unwrap( ) . to_string( ) ,
617- "HEAD is not a branch, use --force to override"
626+ "HEAD is not a branch, use --force-detach to override"
618627 ) ;
619628
620629 let mut revwalk = ctx. repo . revwalk ( ) . unwrap ( ) ;
@@ -645,6 +654,27 @@ mod tests {
645654 assert ! ( is_something_in_index) ;
646655 }
647656
657+ #[ test]
658+ fn detached_head_with_force_detach_flag ( ) {
659+ let ctx = repo_utils:: prepare_and_stage ( ) ;
660+ repo_utils:: detach_head ( & ctx) ;
661+ repo_utils:: delete_branch ( & ctx. repo , "master" ) ;
662+
663+ // run 'git-absorb'
664+ let drain = slog:: Discard ;
665+ let logger = slog:: Logger :: root ( drain, o ! ( ) ) ;
666+ let config = Config {
667+ force_detach : true ,
668+ ..DEFAULT_CONFIG
669+ } ;
670+ run_with_repo ( & logger, & config, & ctx. repo ) . unwrap ( ) ;
671+ let mut revwalk = ctx. repo . revwalk ( ) . unwrap ( ) ;
672+ revwalk. push_head ( ) . unwrap ( ) ;
673+
674+ assert_eq ! ( revwalk. count( ) , 3 ) ;
675+ assert ! ( nothing_left_in_index( & ctx. repo) . unwrap( ) ) ;
676+ }
677+
648678 #[ test]
649679 fn detached_head_with_force_flag ( ) {
650680 let ctx = repo_utils:: prepare_and_stage ( ) ;
@@ -805,6 +835,7 @@ mod tests {
805835 const DEFAULT_CONFIG : Config = Config {
806836 dry_run : false ,
807837 force_author : false ,
838+ force_detach : false ,
808839 force : false ,
809840 base : None ,
810841 and_rebase : false ,
0 commit comments