Skip to content

Commit a621859

Browse files
committed
Merge branch 'hv/autosquash-config'
* hv/autosquash-config: add configuration variable for --autosquash option of interactive rebase
2 parents e24058f + dd1e5b3 commit a621859

4 files changed

Lines changed: 47 additions & 8 deletions

File tree

Documentation/config.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,9 @@ rebase.stat::
15491549
Whether to show a diffstat of what changed upstream since the last
15501550
rebase. False by default.
15511551

1552+
rebase.autosquash::
1553+
If set to true enable '--autosquash' option by default.
1554+
15521555
receive.autogc::
15531556
By default, git-receive-pack will run "git-gc --auto" after
15541557
receiving data from git-push and updating refs. You can stop

Documentation/git-rebase.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ rebase.stat::
199199
Whether to show a diffstat of what changed upstream since the last
200200
rebase. False by default.
201201

202+
rebase.autosquash::
203+
If set to true enable '--autosquash' option by default.
204+
202205
OPTIONS
203206
-------
204207
<newbase>::
@@ -333,6 +336,7 @@ idea unless you know what you are doing (see BUGS below).
333336
instead.
334337

335338
--autosquash::
339+
--no-autosquash::
336340
When the commit log message begins with "squash! ..." (or
337341
"fixup! ..."), and there is a commit whose title begins with
338342
the same ..., automatically modify the todo list of rebase -i
@@ -341,6 +345,10 @@ idea unless you know what you are doing (see BUGS below).
341345
commit from `pick` to `squash` (or `fixup`).
342346
+
343347
This option is only valid when the '--interactive' option is used.
348+
+
349+
If the '--autosquash' option is enabled by default using the
350+
configuration variable `rebase.autosquash`, this option can be
351+
used to override and disable this setting.
344352

345353
--no-ff::
346354
With --interactive, cherry-pick all rebased commits instead of

git-rebase--interactive.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ VERBOSE=
111111
OK_TO_SKIP_PRE_REBASE=
112112
REBASE_ROOT=
113113
AUTOSQUASH=
114+
test "$(git config --bool rebase.autosquash)" = "true" && AUTOSQUASH=t
114115
NEVER_FF=
115116

116117
GIT_CHERRY_PICK_HELP=" After resolving the conflicts,
@@ -831,6 +832,9 @@ first and then run 'git rebase --continue' again."
831832
--autosquash)
832833
AUTOSQUASH=t
833834
;;
835+
--no-autosquash)
836+
AUTOSQUASH=
837+
;;
834838
--onto)
835839
shift
836840
ONTO=$(parse_onto "$1") ||

t/t3415-rebase-autosquash.sh

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,62 @@ test_expect_success setup '
2121
git tag base
2222
'
2323

24-
test_expect_success 'auto fixup' '
24+
test_auto_fixup() {
2525
git reset --hard base &&
2626
echo 1 >file1 &&
2727
git add -u &&
2828
test_tick &&
2929
git commit -m "fixup! first"
3030

31-
git tag final-fixup &&
31+
git tag $1 &&
3232
test_tick &&
33-
git rebase --autosquash -i HEAD^^^ &&
33+
git rebase $2 -i HEAD^^^ &&
3434
git log --oneline >actual &&
3535
test 3 = $(wc -l <actual) &&
36-
git diff --exit-code final-fixup &&
36+
git diff --exit-code $1 &&
3737
test 1 = "$(git cat-file blob HEAD^:file1)" &&
3838
test 1 = $(git cat-file commit HEAD^ | grep first | wc -l)
39+
}
40+
41+
test_expect_success 'auto fixup (option)' '
42+
test_auto_fixup final-fixup-option --autosquash
43+
'
44+
45+
test_expect_success 'auto fixup (config)' '
46+
git config rebase.autosquash true &&
47+
test_auto_fixup final-fixup-config-true &&
48+
test_must_fail test_auto_fixup fixup-config-true-no --no-autosquash &&
49+
git config rebase.autosquash false &&
50+
test_must_fail test_auto_fixup final-fixup-config-false
3951
'
4052

41-
test_expect_success 'auto squash' '
53+
test_auto_squash() {
4254
git reset --hard base &&
4355
echo 1 >file1 &&
4456
git add -u &&
4557
test_tick &&
4658
git commit -m "squash! first"
4759

48-
git tag final-squash &&
60+
git tag $1 &&
4961
test_tick &&
50-
git rebase --autosquash -i HEAD^^^ &&
62+
git rebase $2 -i HEAD^^^ &&
5163
git log --oneline >actual &&
5264
test 3 = $(wc -l <actual) &&
53-
git diff --exit-code final-squash &&
65+
git diff --exit-code $1 &&
5466
test 1 = "$(git cat-file blob HEAD^:file1)" &&
5567
test 2 = $(git cat-file commit HEAD^ | grep first | wc -l)
68+
}
69+
70+
test_expect_success 'auto squash (option)' '
71+
test_auto_squash final-squash --autosquash
72+
'
73+
74+
test_expect_success 'auto squash (config)' '
75+
git config rebase.autosquash true &&
76+
test_auto_squash final-squash-config-true &&
77+
test_must_fail test_auto_squash squash-config-true-no --no-autosquash &&
78+
git config rebase.autosquash false &&
79+
test_must_fail test_auto_squash final-squash-config-false
5680
'
5781

5882
test_expect_success 'misspelled auto squash' '

0 commit comments

Comments
 (0)