rebase: fully ignore rebase.autoSquash without -i

Setting the rebase.autoSquash config variable to true implies a couple of restrictions: it prevents preemptive fast-forwarding and it triggers conflicts with apply backend options. However, it only actually results in auto-squashing when combined with the --interactive (or -i) option, due to code in run_specific_rebase() that disables auto-squashing unless the REBASE_INTERACTIVE_EXPLICIT flag is set. Doing autosquashing for rebase.autoSquash without --interactive would be problematic in terms of backward compatibility, but conversely, there is no need for the aforementioned restrictions without --interactive. So drop the options.config_autosquash check from the conditions for clearing allow_preemptive_ff, as the case where it is combined with --interactive is already covered by the REBASE_INTERACTIVE_EXPLICIT flag check above it. Also drop the "apply options are incompatible with rebase.autoSquash" error, because it is unreachable if it is restricted to --interactive, as apply options already cause an error when used with --interactive. Drop the tests for the error from t3422-rebase-incompatible-options.sh, which has separate tests for the conflicts of --interactive with apply options. When neither --autosquash nor --no-autosquash are given, only set options.autosquash to true if rebase.autosquash is combined with --interactive. Don't initialize options.config_autosquash to -1, as there is no need to distinguish between rebase.autoSquash being unset or explicitly set to false. Finally, amend the rebase.autoSquash documentation to say it only affects interactive mode. Signed-off-by: Andy Koppe <andy.koppe@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Andy Koppe committed Nov 14, 2023 at 21:43 UTC 75cf39b1178f5e6c2830bf3e81521828bb0171ff
3 files changed +9 -20
Documentation/config/rebase.txt
+3 -1
@@ -9,7 +9,9 @@ rebase.stat::
9 rebase. False by default.
10
11 rebase.autoSquash::
12 - If set to true enable `--autosquash` option by default.
12 + If set to true, enable the `--autosquash` option of
13 + linkgit:git-rebase[1] by default for interactive mode.
14 + This can be overridden with the `--no-autosquash` option.
15
16 rebase.autoStash::
17 When set to true, automatically create a temporary stash entry
builtin/rebase.c
+6 -7
@@ -149,7 +149,6 @@ struct rebase_options {
149 .reapply_cherry_picks = -1, \
150 .allow_empty_message = 1, \
151 .autosquash = -1, \
152 - .config_autosquash = -1, \
152 .rebase_merges = -1, \
153 .config_rebase_merges = -1, \
154 .update_refs = -1, \
@@ -1405,7 +1404,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1404 if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
1405 (options.action != ACTION_NONE) ||
1406 (options.exec.nr > 0) ||
1408 - (options.autosquash == -1 && options.config_autosquash == 1) ||
1407 options.autosquash == 1) {
1408 allow_preemptive_ff = 0;
1409 }
@@ -1508,8 +1506,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1506 if (is_merge(&options))
1507 die(_("apply options and merge options "
1508 "cannot be used together"));
1511 - else if (options.autosquash == -1 && options.config_autosquash == 1)
1512 - die(_("apply options are incompatible with rebase.autoSquash. Consider adding --no-autosquash"));
1509 else if (options.rebase_merges == -1 && options.config_rebase_merges == 1)
1510 die(_("apply options are incompatible with rebase.rebaseMerges. Consider adding --no-rebase-merges"));
1511 else if (options.update_refs == -1 && options.config_update_refs == 1)
@@ -1529,10 +1525,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1525 options.rebase_merges = (options.rebase_merges >= 0) ? options.rebase_merges :
1526 ((options.config_rebase_merges >= 0) ? options.config_rebase_merges : 0);
1527
1532 - if (options.autosquash == 1)
1528 + if (options.autosquash == 1) {
1529 imply_merge(&options, "--autosquash");
1534 - options.autosquash = (options.autosquash >= 0) ? options.autosquash :
1535 - ((options.config_autosquash >= 0) ? options.config_autosquash : 0);
1530 + } else if (options.autosquash == -1) {
1531 + options.autosquash =
1532 + options.config_autosquash &&
1533 + (options.flags & REBASE_INTERACTIVE_EXPLICIT);
1534 + }
1535
1536 if (options.type == REBASE_UNSPECIFIED) {
1537 if (!strcmp(options.default_backend, "merge"))
t/t3422-rebase-incompatible-options.sh
-12
@@ -100,12 +100,6 @@ test_rebase_am_only () {
100 test_must_fail git rebase $opt --root A
101 "
102
103 - test_expect_success "$opt incompatible with rebase.autosquash" "
104 - git checkout B^0 &&
105 - test_must_fail git -c rebase.autosquash=true rebase $opt A 2>err &&
106 - grep -e --no-autosquash err
107 - "
108 -
103 test_expect_success "$opt incompatible with rebase.rebaseMerges" "
104 git checkout B^0 &&
105 test_must_fail git -c rebase.rebaseMerges=true rebase $opt A 2>err &&
@@ -118,12 +112,6 @@ test_rebase_am_only () {
112 grep -e --no-update-refs err
113 "
114
121 - test_expect_success "$opt okay with overridden rebase.autosquash" "
122 - test_when_finished \"git reset --hard B^0\" &&
123 - git checkout B^0 &&
124 - git -c rebase.autosquash=true rebase --no-autosquash $opt A
125 - "
126 -
115 test_expect_success "$opt okay with overridden rebase.rebaseMerges" "
116 test_when_finished \"git reset --hard B^0\" &&
117 git checkout B^0 &&