Skip to content

Commit 297be59

Browse files
ak2gitster
authored andcommitted
rebase: support --autosquash without -i
The rebase --autosquash option is quietly ignored when used without --interactive (apart from preventing preemptive fast-forwarding and triggering conflicts with apply backend options). Change that to support --autosquash without --interactive, by dropping its restriction to REBASE_INTERACTIVE_EXCPLICIT mode. When used this way, auto-squashing is done without opening the todo list editor. Drop the -i requirement from the --autosquash description, and amend t3415-rebase-autosquash.sh to test the option and the rebase.autoSquash config variable with and without -i. Signed-off-by: Andy Koppe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75cf39b commit 297be59

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

Documentation/git-rebase.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ See also INCOMPATIBLE OPTIONS below.
592592
When the commit log message begins with "squash! ..." or "fixup! ..."
593593
or "amend! ...", and there is already a commit in the todo list that
594594
matches the same `...`, automatically modify the todo list of
595-
`rebase -i`, so that the commit marked for squashing comes right after
595+
`rebase`, so that the commit marked for squashing comes right after
596596
the commit to be modified, and change the action of the moved commit
597597
from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
598598
matches the `...` if the commit subject matches, or if the `...` refers

builtin/rebase.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,8 @@ static int run_specific_rebase(struct rebase_options *opts)
710710
if (opts->type == REBASE_MERGE) {
711711
/* Run sequencer-based rebase */
712712
setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1);
713-
if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
713+
if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT))
714714
setenv("GIT_SEQUENCE_EDITOR", ":", 1);
715-
opts->autosquash = 0;
716-
}
717715
if (opts->gpg_sign_opt) {
718716
/* remove the leading "-S" */
719717
char *tmp = xstrdup(opts->gpg_sign_opt + 2);

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' '

0 commit comments

Comments
 (0)