@@ -19,6 +19,7 @@ pub struct Config<'a> {
1919 pub rebase_options : & ' a Vec < & ' a str > ,
2020 pub whole_file : bool ,
2121 pub one_fixup_per_commit : bool ,
22+ pub message : Option < & ' a str > ,
2223}
2324
2425pub fn run ( logger : & slog:: Logger , config : & Config ) -> Result < ( ) > {
@@ -319,11 +320,17 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository
319320 . stats ( ) ?;
320321 if !config. dry_run {
321322 head_tree = new_head_tree;
323+ let mut message = format ! ( "fixup! {}\n " , dest_commit_locator) ;
324+ if let Some ( m) = config. message . filter ( |m| !m. is_empty ( ) ) {
325+ message. push ( '\n' ) ;
326+ message. push_str ( m) ;
327+ message. push ( '\n' ) ;
328+ } ;
322329 head_commit = repo. find_commit ( repo. commit (
323330 Some ( "HEAD" ) ,
324331 & signature,
325332 & signature,
326- & format ! ( "fixup! {} \n " , dest_commit_locator ) ,
333+ & message ,
327334 & head_tree,
328335 & [ & head_commit] ,
329336 ) ?) ?;
@@ -978,6 +985,59 @@ mod tests {
978985 assert_eq ! ( actual_msg, expected_msg) ;
979986 }
980987
988+ #[ test]
989+ fn fixup_message_option_left_out_sets_only_summary ( ) {
990+ let ctx = repo_utils:: prepare_and_stage ( ) ;
991+
992+ // run 'git-absorb'
993+ let drain = slog:: Discard ;
994+ let logger = slog:: Logger :: root ( drain, o ! ( ) ) ;
995+ run_with_repo ( & logger, & DEFAULT_CONFIG , & ctx. repo ) . unwrap ( ) ;
996+ assert ! ( nothing_left_in_index( & ctx. repo) . unwrap( ) ) ;
997+
998+ let mut revwalk = ctx. repo . revwalk ( ) . unwrap ( ) ;
999+ revwalk. push_head ( ) . unwrap ( ) ;
1000+
1001+ let oids: Vec < git2:: Oid > = revwalk. by_ref ( ) . collect :: < Result < Vec < _ > , _ > > ( ) . unwrap ( ) ;
1002+ assert_eq ! ( oids. len( ) , 3 ) ;
1003+
1004+ let fixup_commit = ctx. repo . find_commit ( oids[ 0 ] ) . unwrap ( ) ;
1005+ let fixed_up_commit = ctx. repo . find_commit ( * oids. last ( ) . unwrap ( ) ) . unwrap ( ) ;
1006+ let actual_msg = fixup_commit. message ( ) . unwrap ( ) ;
1007+ let expected_msg = fixed_up_commit. message ( ) . unwrap ( ) ;
1008+ let expected_msg = format ! ( "fixup! {}\n " , expected_msg) ;
1009+ assert_eq ! ( actual_msg, expected_msg) ;
1010+ }
1011+
1012+ #[ test]
1013+ fn fixup_message_option_provided_sets_message ( ) {
1014+ let ctx = repo_utils:: prepare_and_stage ( ) ;
1015+
1016+ // run 'git-absorb'
1017+ let drain = slog:: Discard ;
1018+ let logger = slog:: Logger :: root ( drain, o ! ( ) ) ;
1019+ let fixup_message_body = "git-absorb is my favorite git tool!" ;
1020+ let config = Config {
1021+ message : Some ( fixup_message_body) ,
1022+ ..DEFAULT_CONFIG
1023+ } ;
1024+ run_with_repo ( & logger, & config, & ctx. repo ) . unwrap ( ) ;
1025+ assert ! ( nothing_left_in_index( & ctx. repo) . unwrap( ) ) ;
1026+
1027+ let mut revwalk = ctx. repo . revwalk ( ) . unwrap ( ) ;
1028+ revwalk. push_head ( ) . unwrap ( ) ;
1029+
1030+ let oids: Vec < git2:: Oid > = revwalk. by_ref ( ) . collect :: < Result < Vec < _ > , _ > > ( ) . unwrap ( ) ;
1031+ assert_eq ! ( oids. len( ) , 3 ) ;
1032+
1033+ let fixup_commit = ctx. repo . find_commit ( oids[ 0 ] ) . unwrap ( ) ;
1034+ let fixed_up_commit = ctx. repo . find_commit ( * oids. last ( ) . unwrap ( ) ) . unwrap ( ) ;
1035+ let actual_msg = fixup_commit. message ( ) . unwrap ( ) ;
1036+ let expected_msg = fixed_up_commit. message ( ) . unwrap ( ) ;
1037+ let expected_msg = format ! ( "fixup! {}\n \n {}\n " , expected_msg, fixup_message_body) ;
1038+ assert_eq ! ( actual_msg, expected_msg) ;
1039+ }
1040+
9811041 const DEFAULT_CONFIG : Config = Config {
9821042 dry_run : false ,
9831043 force_author : false ,
@@ -987,5 +1047,6 @@ mod tests {
9871047 rebase_options : & Vec :: new ( ) ,
9881048 whole_file : false ,
9891049 one_fixup_per_commit : false ,
1050+ message : None ,
9901051 } ;
9911052}
0 commit comments