Skip to content

Commit 75cf39b

Browse files
ak2gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0939be commit 75cf39b

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

Documentation/config/rebase.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ rebase.stat::
99
rebase. False by default.
1010

1111
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.
1315

1416
rebase.autoStash::
1517
When set to true, automatically create a temporary stash entry

builtin/rebase.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ struct rebase_options {
149149
.reapply_cherry_picks = -1, \
150150
.allow_empty_message = 1, \
151151
.autosquash = -1, \
152-
.config_autosquash = -1, \
153152
.rebase_merges = -1, \
154153
.config_rebase_merges = -1, \
155154
.update_refs = -1, \
@@ -1405,7 +1404,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14051404
if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
14061405
(options.action != ACTION_NONE) ||
14071406
(options.exec.nr > 0) ||
1408-
(options.autosquash == -1 && options.config_autosquash == 1) ||
14091407
options.autosquash == 1) {
14101408
allow_preemptive_ff = 0;
14111409
}
@@ -1508,8 +1506,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15081506
if (is_merge(&options))
15091507
die(_("apply options and merge options "
15101508
"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"));
15131509
else if (options.rebase_merges == -1 && options.config_rebase_merges == 1)
15141510
die(_("apply options are incompatible with rebase.rebaseMerges. Consider adding --no-rebase-merges"));
15151511
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)
15291525
options.rebase_merges = (options.rebase_merges >= 0) ? options.rebase_merges :
15301526
((options.config_rebase_merges >= 0) ? options.config_rebase_merges : 0);
15311527

1532-
if (options.autosquash == 1)
1528+
if (options.autosquash == 1) {
15331529
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+
}
15361535

15371536
if (options.type == REBASE_UNSPECIFIED) {
15381537
if (!strcmp(options.default_backend, "merge"))

t/t3422-rebase-incompatible-options.sh

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ test_rebase_am_only () {
100100
test_must_fail git rebase $opt --root A
101101
"
102102

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-
109103
test_expect_success "$opt incompatible with rebase.rebaseMerges" "
110104
git checkout B^0 &&
111105
test_must_fail git -c rebase.rebaseMerges=true rebase $opt A 2>err &&
@@ -118,12 +112,6 @@ test_rebase_am_only () {
118112
grep -e --no-update-refs err
119113
"
120114

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-
127115
test_expect_success "$opt okay with overridden rebase.rebaseMerges" "
128116
test_when_finished \"git reset --hard B^0\" &&
129117
git checkout B^0 &&

0 commit comments

Comments
 (0)