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 <andy.koppe@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Andy Koppe committed Nov 14, 2023 at 21:43 UTC 297be59456f2d27710de01ab88c025241ccb4206
3 files changed +30 -14
Documentation/git-rebase.txt
+1 -1
@@ -592,7 +592,7 @@ See also INCOMPATIBLE OPTIONS below.
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
595 + `rebase`, 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
builtin/rebase.c
+1 -3
@@ -710,10 +710,8 @@ static int run_specific_rebase(struct rebase_options *opts)
710 if (opts->type == REBASE_MERGE) {
711 /* Run sequencer-based rebase */
712 setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1);
713 - if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
713 + if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT))
714 setenv("GIT_SEQUENCE_EDITOR", ":", 1);
715 - opts->autosquash = 0;
716 - }
715 if (opts->gpg_sign_opt) {
716 /* remove the leading "-S" */
717 char *tmp = xstrdup(opts->gpg_sign_opt + 2);
t/t3415-rebase-autosquash.sh
+28 -10
@@ -43,7 +43,7 @@ test_auto_fixup () {
43
44 git tag $1 &&
45 test_tick &&
46 - git rebase $2 -i HEAD^^^ &&
46 + git rebase $2 HEAD^^^ &&
47 git log --oneline >actual &&
48 if test -n "$no_squash"
49 then
@@ -61,15 +61,24 @@ test_auto_fixup () {
61 }
62
63 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"
66 '
67
67 -test_expect_success 'auto fixup (config)' '
68 +test_expect_success 'auto fixup (config true)' '
69 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 &&
72 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)' '
77 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"
82 '
83
84 test_auto_squash () {
@@ -87,7 +96,7 @@ test_auto_squash () {
96 git commit -m "squash! first" -m "extra para for first" &&
97 git tag $1 &&
98 test_tick &&
90 - git rebase $2 -i HEAD^^^ &&
99 + git rebase $2 HEAD^^^ &&
100 git log --oneline >actual &&
101 if test -n "$no_squash"
102 then
@@ -105,15 +114,24 @@ test_auto_squash () {
114 }
115
116 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"
119 '
120
111 -test_expect_success 'auto squash (config)' '
121 +test_expect_success 'auto squash (config true)' '
122 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 &&
125 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)' '
130 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"
135 '
136
137 test_expect_success 'misspelled auto squash' '