@@ -122,6 +122,8 @@ struct rebase_options {
122
122
int reapply_cherry_picks ;
123
123
int fork_point ;
124
124
int update_refs ;
125
+ int config_autosquash ;
126
+ int config_update_refs ;
125
127
};
126
128
127
129
#define REBASE_OPTIONS_INIT { \
@@ -134,6 +136,12 @@ struct rebase_options {
134
136
.exec = STRING_LIST_INIT_NODUP, \
135
137
.git_format_patch_opt = STRBUF_INIT, \
136
138
.fork_point = -1, \
139
+ .reapply_cherry_picks = -1, \
140
+ .allow_empty_message = 1, \
141
+ .autosquash = -1, \
142
+ .config_autosquash = -1, \
143
+ .update_refs = -1, \
144
+ .config_update_refs = -1, \
137
145
}
138
146
139
147
static struct replay_opts get_replay_opts (const struct rebase_options * opts )
@@ -776,7 +784,7 @@ static int rebase_config(const char *var, const char *value, void *data)
776
784
}
777
785
778
786
if (!strcmp (var , "rebase.autosquash" )) {
779
- opts -> autosquash = git_config_bool (var , value );
787
+ opts -> config_autosquash = git_config_bool (var , value );
780
788
return 0 ;
781
789
}
782
790
@@ -793,7 +801,7 @@ static int rebase_config(const char *var, const char *value, void *data)
793
801
}
794
802
795
803
if (!strcmp (var , "rebase.updaterefs" )) {
796
- opts -> update_refs = git_config_bool (var , value );
804
+ opts -> config_update_refs = git_config_bool (var , value );
797
805
return 0 ;
798
806
}
799
807
@@ -907,6 +915,9 @@ static int parse_opt_am(const struct option *opt, const char *arg, int unset)
907
915
BUG_ON_OPT_NEG (unset );
908
916
BUG_ON_OPT_ARG (arg );
909
917
918
+ if (opts -> type != REBASE_UNSPECIFIED && opts -> type != REBASE_APPLY )
919
+ die (_ ("apply options and merge options cannot be used together" ));
920
+
910
921
opts -> type = REBASE_APPLY ;
911
922
912
923
return 0 ;
@@ -920,8 +931,10 @@ static int parse_opt_merge(const struct option *opt, const char *arg, int unset)
920
931
BUG_ON_OPT_NEG (unset );
921
932
BUG_ON_OPT_ARG (arg );
922
933
923
- if (!is_merge (opts ))
924
- opts -> type = REBASE_MERGE ;
934
+ if (opts -> type != REBASE_UNSPECIFIED && opts -> type != REBASE_MERGE )
935
+ die (_ ("apply options and merge options cannot be used together" ));
936
+
937
+ opts -> type = REBASE_MERGE ;
925
938
926
939
return 0 ;
927
940
}
@@ -935,6 +948,9 @@ static int parse_opt_interactive(const struct option *opt, const char *arg,
935
948
BUG_ON_OPT_NEG (unset );
936
949
BUG_ON_OPT_ARG (arg );
937
950
951
+ if (opts -> type != REBASE_UNSPECIFIED && opts -> type != REBASE_MERGE )
952
+ die (_ ("apply options and merge options cannot be used together" ));
953
+
938
954
opts -> type = REBASE_MERGE ;
939
955
opts -> flags |= REBASE_INTERACTIVE_EXPLICIT ;
940
956
@@ -1150,8 +1166,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1150
1166
prepare_repo_settings (the_repository );
1151
1167
the_repository -> settings .command_requires_full_index = 0 ;
1152
1168
1153
- options .reapply_cherry_picks = -1 ;
1154
- options .allow_empty_message = 1 ;
1155
1169
git_config (rebase_config , & options );
1156
1170
/* options.gpg_sign_opt will be either "-S" or NULL */
1157
1171
gpg_sign = options .gpg_sign_opt ? "" : NULL ;
@@ -1216,13 +1230,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1216
1230
if (options .fork_point < 0 )
1217
1231
options .fork_point = 0 ;
1218
1232
}
1219
- /*
1220
- * --keep-base defaults to --reapply-cherry-picks to avoid losing
1221
- * commits when using this option.
1222
- */
1223
- if (options .reapply_cherry_picks < 0 )
1224
- options .reapply_cherry_picks = keep_base ;
1225
-
1226
1233
if (options .root && options .fork_point > 0 )
1227
1234
die (_ ("options '%s' and '%s' cannot be used together" ), "--root" , "--fork-point" );
1228
1235
@@ -1365,7 +1372,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1365
1372
if ((options .flags & REBASE_INTERACTIVE_EXPLICIT ) ||
1366
1373
(options .action != ACTION_NONE ) ||
1367
1374
(options .exec .nr > 0 ) ||
1368
- options .autosquash ) {
1375
+ (options .autosquash == -1 && options .config_autosquash == 1 ) ||
1376
+ options .autosquash == 1 ) {
1369
1377
allow_preemptive_ff = 0 ;
1370
1378
}
1371
1379
if (options .committer_date_is_author_date || options .ignore_date )
@@ -1398,12 +1406,27 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1398
1406
if (options .empty != EMPTY_UNSPECIFIED )
1399
1407
imply_merge (& options , "--empty" );
1400
1408
1401
- /*
1402
- * --keep-base implements --reapply-cherry-picks by altering upstream so
1403
- * it works with both backends.
1404
- */
1405
- if (options .reapply_cherry_picks && !keep_base )
1406
- imply_merge (& options , "--reapply-cherry-picks" );
1409
+ if (options .reapply_cherry_picks < 0 )
1410
+ /*
1411
+ * We default to --no-reapply-cherry-picks unless
1412
+ * --keep-base is given; when --keep-base is given, we want
1413
+ * to default to --reapply-cherry-picks.
1414
+ */
1415
+ options .reapply_cherry_picks = keep_base ;
1416
+ else if (!keep_base )
1417
+ /*
1418
+ * The apply backend always searches for and drops cherry
1419
+ * picks. This is often not wanted with --keep-base, so
1420
+ * --keep-base allows --reapply-cherry-picks to be
1421
+ * simulated by altering the upstream such that
1422
+ * cherry-picks cannot be detected and thus all commits are
1423
+ * reapplied. Thus, --[no-]reapply-cherry-picks is
1424
+ * supported when --keep-base is specified, but not when
1425
+ * --keep-base is left out.
1426
+ */
1427
+ imply_merge (& options , options .reapply_cherry_picks ?
1428
+ "--reapply-cherry-picks" :
1429
+ "--no-reapply-cherry-picks" );
1407
1430
1408
1431
if (gpg_sign )
1409
1432
options .gpg_sign_opt = xstrfmt ("-S%s" , gpg_sign );
@@ -1483,15 +1506,29 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1483
1506
if (strcmp (options .git_am_opts .v [i ], "-q" ))
1484
1507
break ;
1485
1508
1486
- if (i >= 0 ) {
1509
+ if (i >= 0 || options . type == REBASE_APPLY ) {
1487
1510
if (is_merge (& options ))
1488
1511
die (_ ("apply options and merge options "
1489
1512
"cannot be used together" ));
1513
+ else if (options .autosquash == -1 && options .config_autosquash == 1 )
1514
+ die (_ ("apply options are incompatible with rebase.autosquash. Consider adding --no-autosquash" ));
1515
+ else if (options .update_refs == -1 && options .config_update_refs == 1 )
1516
+ die (_ ("apply options are incompatible with rebase.updateRefs. Consider adding --no-update-refs" ));
1490
1517
else
1491
1518
options .type = REBASE_APPLY ;
1492
1519
}
1493
1520
}
1494
1521
1522
+ if (options .update_refs == 1 )
1523
+ imply_merge (& options , "--update-refs" );
1524
+ options .update_refs = (options .update_refs >= 0 ) ? options .update_refs :
1525
+ ((options .config_update_refs >= 0 ) ? options .config_update_refs : 0 );
1526
+
1527
+ if (options .autosquash == 1 )
1528
+ imply_merge (& options , "--autosquash" );
1529
+ options .autosquash = (options .autosquash >= 0 ) ? options .autosquash :
1530
+ ((options .config_autosquash >= 0 ) ? options .config_autosquash : 0 );
1531
+
1495
1532
if (options .type == REBASE_UNSPECIFIED ) {
1496
1533
if (!strcmp (options .default_backend , "merge" ))
1497
1534
imply_merge (& options , "--merge" );
0 commit comments