Skip to content

Commit f8f87e0

Browse files
committed
Merge branch 'ak/rebase-autosquash'
"git rebase --autosquash" is now enabled for non-interactive rebase, but it is still incompatible with the apply backend. * ak/rebase-autosquash: rebase: rewrite --(no-)autosquash documentation rebase: support --autosquash without -i rebase: fully ignore rebase.autoSquash without -i
2 parents 98d0a1f + cb00f52 commit f8f87e0

File tree

5 files changed

+58
-47
lines changed

5 files changed

+58
-47
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

Documentation/git-rebase.txt

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -589,21 +589,27 @@ See also INCOMPATIBLE OPTIONS below.
589589

590590
--autosquash::
591591
--no-autosquash::
592-
When the commit log message begins with "squash! ..." or "fixup! ..."
593-
or "amend! ...", and there is already a commit in the todo list that
594-
matches the same `...`, automatically modify the todo list of
595-
`rebase -i`, so that the commit marked for squashing comes right after
596-
the commit to be modified, and change the action of the moved commit
597-
from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
598-
matches the `...` if the commit subject matches, or if the `...` refers
599-
to the commit's hash. As a fall-back, partial matches of the commit
600-
subject work, too. The recommended way to create fixup/amend/squash
601-
commits is by using the `--fixup`, `--fixup=amend:` or `--fixup=reword:`
602-
and `--squash` options respectively of linkgit:git-commit[1].
592+
Automatically squash commits with specially formatted messages into
593+
previous commits being rebased. If a commit message starts with
594+
"squash! ", "fixup! " or "amend! ", the remainder of the subject line
595+
is taken as a commit specifier, which matches a previous commit if it
596+
matches the subject line or the hash of that commit. If no commit
597+
matches fully, matches of the specifier with the start of commit
598+
subjects are considered.
603599
+
604-
If the `--autosquash` option is enabled by default using the
605-
configuration variable `rebase.autoSquash`, this option can be
606-
used to override and disable this setting.
600+
In the rebase todo list, the actions of squash, fixup and amend commits are
601+
changed from `pick` to `squash`, `fixup` or `fixup -C`, respectively, and they
602+
are moved right after the commit they modify. The `--interactive` option can
603+
be used to review and edit the todo list before proceeding.
604+
+
605+
The recommended way to create commits with squash markers is by using the
606+
`--squash`, `--fixup`, `--fixup=amend:` or `--fixup=reword:` options of
607+
linkgit:git-commit[1], which take the target commit as an argument and
608+
automatically fill in the subject line of the new commit from that.
609+
+
610+
Settting configuration variable `rebase.autoSquash` to true enables
611+
auto-squashing by default for interactive rebase. The `--no-autosquash`
612+
option can be used to override that setting.
607613
+
608614
See also INCOMPATIBLE OPTIONS below.
609615

builtin/rebase.c

Lines changed: 7 additions & 10 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, \
@@ -711,10 +710,8 @@ static int run_specific_rebase(struct rebase_options *opts)
711710
if (opts->type == REBASE_MERGE) {
712711
/* Run sequencer-based rebase */
713712
setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1);
714-
if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
713+
if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT))
715714
setenv("GIT_SEQUENCE_EDITOR", ":", 1);
716-
opts->autosquash = 0;
717-
}
718715
if (opts->gpg_sign_opt) {
719716
/* remove the leading "-S" */
720717
char *tmp = xstrdup(opts->gpg_sign_opt + 2);
@@ -1405,7 +1402,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14051402
if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
14061403
(options.action != ACTION_NONE) ||
14071404
(options.exec.nr > 0) ||
1408-
(options.autosquash == -1 && options.config_autosquash == 1) ||
14091405
options.autosquash == 1) {
14101406
allow_preemptive_ff = 0;
14111407
}
@@ -1508,8 +1504,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15081504
if (is_merge(&options))
15091505
die(_("apply options and merge options "
15101506
"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"));
15131507
else if (options.rebase_merges == -1 && options.config_rebase_merges == 1)
15141508
die(_("apply options are incompatible with rebase.rebaseMerges. Consider adding --no-rebase-merges"));
15151509
else if (options.update_refs == -1 && options.config_update_refs == 1)
@@ -1529,10 +1523,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15291523
options.rebase_merges = (options.rebase_merges >= 0) ? options.rebase_merges :
15301524
((options.config_rebase_merges >= 0) ? options.config_rebase_merges : 0);
15311525

1532-
if (options.autosquash == 1)
1526+
if (options.autosquash == 1) {
15331527
imply_merge(&options, "--autosquash");
1534-
options.autosquash = (options.autosquash >= 0) ? options.autosquash :
1535-
((options.config_autosquash >= 0) ? options.config_autosquash : 0);
1528+
} else if (options.autosquash == -1) {
1529+
options.autosquash =
1530+
options.config_autosquash &&
1531+
(options.flags & REBASE_INTERACTIVE_EXPLICIT);
1532+
}
15361533

15371534
if (options.type == REBASE_UNSPECIFIED) {
15381535
if (!strcmp(options.default_backend, "merge"))

t/t3415-rebase-autosquash.sh

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test_auto_fixup () {
4343

4444
git tag $1 &&
4545
test_tick &&
46-
git rebase $2 -i HEAD^^^ &&
46+
git rebase $2 HEAD^^^ &&
4747
git log --oneline >actual &&
4848
if test -n "$no_squash"
4949
then
@@ -61,15 +61,24 @@ test_auto_fixup () {
6161
}
6262

6363
test_expect_success 'auto fixup (option)' '
64-
test_auto_fixup final-fixup-option --autosquash
64+
test_auto_fixup fixup-option --autosquash &&
65+
test_auto_fixup fixup-option-i "--autosquash -i"
6566
'
6667

67-
test_expect_success 'auto fixup (config)' '
68+
test_expect_success 'auto fixup (config true)' '
6869
git config rebase.autosquash true &&
69-
test_auto_fixup final-fixup-config-true &&
70+
test_auto_fixup ! fixup-config-true &&
71+
test_auto_fixup fixup-config-true-i -i &&
7072
test_auto_fixup ! fixup-config-true-no --no-autosquash &&
73+
test_auto_fixup ! fixup-config-true-i-no "-i --no-autosquash"
74+
'
75+
76+
test_expect_success 'auto fixup (config false)' '
7177
git config rebase.autosquash false &&
72-
test_auto_fixup ! final-fixup-config-false
78+
test_auto_fixup ! fixup-config-false &&
79+
test_auto_fixup ! fixup-config-false-i -i &&
80+
test_auto_fixup fixup-config-false-yes --autosquash &&
81+
test_auto_fixup fixup-config-false-i-yes "-i --autosquash"
7382
'
7483

7584
test_auto_squash () {
@@ -87,7 +96,7 @@ test_auto_squash () {
8796
git commit -m "squash! first" -m "extra para for first" &&
8897
git tag $1 &&
8998
test_tick &&
90-
git rebase $2 -i HEAD^^^ &&
99+
git rebase $2 HEAD^^^ &&
91100
git log --oneline >actual &&
92101
if test -n "$no_squash"
93102
then
@@ -105,15 +114,24 @@ test_auto_squash () {
105114
}
106115

107116
test_expect_success 'auto squash (option)' '
108-
test_auto_squash final-squash --autosquash
117+
test_auto_squash squash-option --autosquash &&
118+
test_auto_squash squash-option-i "--autosquash -i"
109119
'
110120

111-
test_expect_success 'auto squash (config)' '
121+
test_expect_success 'auto squash (config true)' '
112122
git config rebase.autosquash true &&
113-
test_auto_squash final-squash-config-true &&
123+
test_auto_squash ! squash-config-true &&
124+
test_auto_squash squash-config-true-i -i &&
114125
test_auto_squash ! squash-config-true-no --no-autosquash &&
126+
test_auto_squash ! squash-config-true-i-no "-i --no-autosquash"
127+
'
128+
129+
test_expect_success 'auto squash (config false)' '
115130
git config rebase.autosquash false &&
116-
test_auto_squash ! final-squash-config-false
131+
test_auto_squash ! squash-config-false &&
132+
test_auto_squash ! squash-config-false-i -i &&
133+
test_auto_squash squash-config-false-yes --autosquash &&
134+
test_auto_squash squash-config-false-i-yes "-i --autosquash"
117135
'
118136

119137
test_expect_success 'misspelled auto squash' '

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)