@@ -124,6 +124,7 @@ struct rebase_options {
124
124
int fork_point ;
125
125
int update_refs ;
126
126
int config_autosquash ;
127
+ int config_rebase_merges ;
127
128
int config_update_refs ;
128
129
};
129
130
@@ -141,6 +142,8 @@ struct rebase_options {
141
142
.allow_empty_message = 1, \
142
143
.autosquash = -1, \
143
144
.config_autosquash = -1, \
145
+ .rebase_merges = -1, \
146
+ .config_rebase_merges = -1, \
144
147
.update_refs = -1, \
145
148
.config_update_refs = -1, \
146
149
}
@@ -772,6 +775,16 @@ static int run_specific_rebase(struct rebase_options *opts)
772
775
return status ? -1 : 0 ;
773
776
}
774
777
778
+ static void parse_rebase_merges_value (struct rebase_options * options , const char * value )
779
+ {
780
+ if (!strcmp ("no-rebase-cousins" , value ))
781
+ options -> rebase_cousins = 0 ;
782
+ else if (!strcmp ("rebase-cousins" , value ))
783
+ options -> rebase_cousins = 1 ;
784
+ else
785
+ die (_ ("Unknown rebase-merges mode: %s" ), value );
786
+ }
787
+
775
788
static int rebase_config (const char * var , const char * value , void * data )
776
789
{
777
790
struct rebase_options * opts = data ;
@@ -801,6 +814,17 @@ static int rebase_config(const char *var, const char *value, void *data)
801
814
return 0 ;
802
815
}
803
816
817
+ if (!strcmp (var , "rebase.rebasemerges" )) {
818
+ opts -> config_rebase_merges = git_parse_maybe_bool (value );
819
+ if (opts -> config_rebase_merges < 0 ) {
820
+ opts -> config_rebase_merges = 1 ;
821
+ parse_rebase_merges_value (opts , value );
822
+ } else {
823
+ opts -> rebase_cousins = 0 ;
824
+ }
825
+ return 0 ;
826
+ }
827
+
804
828
if (!strcmp (var , "rebase.updaterefs" )) {
805
829
opts -> config_update_refs = git_config_bool (var , value );
806
830
return 0 ;
@@ -981,6 +1005,28 @@ static int parse_opt_empty(const struct option *opt, const char *arg, int unset)
981
1005
return 0 ;
982
1006
}
983
1007
1008
+ static int parse_opt_rebase_merges (const struct option * opt , const char * arg , int unset )
1009
+ {
1010
+ struct rebase_options * options = opt -> value ;
1011
+
1012
+ options -> rebase_merges = !unset ;
1013
+ options -> rebase_cousins = 0 ;
1014
+
1015
+ if (arg ) {
1016
+ if (!* arg ) {
1017
+ warning (_ ("--rebase-merges with an empty string "
1018
+ "argument is deprecated and will stop "
1019
+ "working in a future version of Git. Use "
1020
+ "--rebase-merges without an argument "
1021
+ "instead, which does the same thing." ));
1022
+ return 0 ;
1023
+ }
1024
+ parse_rebase_merges_value (options , arg );
1025
+ }
1026
+
1027
+ return 0 ;
1028
+ }
1029
+
984
1030
static void NORETURN error_on_missing_default_upstream (void )
985
1031
{
986
1032
struct branch * current_branch = branch_get (NULL );
@@ -1036,7 +1082,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1036
1082
struct object_id branch_base ;
1037
1083
int ignore_whitespace = 0 ;
1038
1084
const char * gpg_sign = NULL ;
1039
- const char * rebase_merges = NULL ;
1040
1085
struct string_list strategy_options = STRING_LIST_INIT_NODUP ;
1041
1086
struct object_id squash_onto ;
1042
1087
char * squash_onto_name = NULL ;
@@ -1138,10 +1183,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1138
1183
& options .allow_empty_message ,
1139
1184
N_ ("allow rebasing commits with empty messages" ),
1140
1185
PARSE_OPT_HIDDEN ),
1141
- {OPTION_STRING , 'r' , "rebase-merges" , & rebase_merges ,
1142
- N_ ("mode" ),
1186
+ OPT_CALLBACK_F ('r' , "rebase-merges" , & options , N_ ("mode" ),
1143
1187
N_ ("try to rebase merges instead of skipping them" ),
1144
- PARSE_OPT_OPTARG , NULL , ( intptr_t ) "" } ,
1188
+ PARSE_OPT_OPTARG , parse_opt_rebase_merges ) ,
1145
1189
OPT_BOOL (0 , "fork-point" , & options .fork_point ,
1146
1190
N_ ("use 'merge-base --fork-point' to refine upstream" )),
1147
1191
OPT_STRING ('s' , "strategy" , & options .strategy ,
@@ -1437,17 +1481,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1437
1481
if (options .exec .nr )
1438
1482
imply_merge (& options , "--exec" );
1439
1483
1440
- if (rebase_merges ) {
1441
- if (!* rebase_merges )
1442
- ; /* default mode; do nothing */
1443
- else if (!strcmp ("rebase-cousins" , rebase_merges ))
1444
- options .rebase_cousins = 1 ;
1445
- else if (strcmp ("no-rebase-cousins" , rebase_merges ))
1446
- die (_ ("Unknown mode: %s" ), rebase_merges );
1447
- options .rebase_merges = 1 ;
1448
- imply_merge (& options , "--rebase-merges" );
1449
- }
1450
-
1451
1484
if (options .type == REBASE_APPLY ) {
1452
1485
if (ignore_whitespace )
1453
1486
strvec_push (& options .git_am_opts ,
@@ -1515,6 +1548,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1515
1548
"cannot be used together" ));
1516
1549
else if (options .autosquash == -1 && options .config_autosquash == 1 )
1517
1550
die (_ ("apply options are incompatible with rebase.autoSquash. Consider adding --no-autosquash" ));
1551
+ else if (options .rebase_merges == -1 && options .config_rebase_merges == 1 )
1552
+ die (_ ("apply options are incompatible with rebase.rebaseMerges. Consider adding --no-rebase-merges" ));
1518
1553
else if (options .update_refs == -1 && options .config_update_refs == 1 )
1519
1554
die (_ ("apply options are incompatible with rebase.updateRefs. Consider adding --no-update-refs" ));
1520
1555
else
@@ -1527,6 +1562,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1527
1562
options .update_refs = (options .update_refs >= 0 ) ? options .update_refs :
1528
1563
((options .config_update_refs >= 0 ) ? options .config_update_refs : 0 );
1529
1564
1565
+ if (options .rebase_merges == 1 )
1566
+ imply_merge (& options , "--rebase-merges" );
1567
+ options .rebase_merges = (options .rebase_merges >= 0 ) ? options .rebase_merges :
1568
+ ((options .config_rebase_merges >= 0 ) ? options .config_rebase_merges : 0 );
1569
+
1530
1570
if (options .autosquash == 1 )
1531
1571
imply_merge (& options , "--autosquash" );
1532
1572
options .autosquash = (options .autosquash >= 0 ) ? options .autosquash :
0 commit comments