Skip to content

Commit

Permalink
add configuration variable for --autosquash option of interactive rebase
Browse files Browse the repository at this point in the history
If you use this feature regularly you can now enable it by default. In
case the user wants to override this config on the commandline
--no-autosquash can be used to force disabling.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Heiko Voigt authored and Junio C Hamano committed Jul 14, 2010
1 parent 449aeb1 commit dd1e5b3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,9 @@ rebase.stat::
Whether to show a diffstat of what changed upstream since the last
rebase. False by default.

rebase.autosquash::
If set to true enable '--autosquash' option by default.

receive.autogc::
By default, git-receive-pack will run "git-gc --auto" after
receiving data from git-push and updating refs. You can stop
Expand Down
8 changes: 8 additions & 0 deletions Documentation/git-rebase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ rebase.stat::
Whether to show a diffstat of what changed upstream since the last
rebase. False by default.

rebase.autosquash::
If set to true enable '--autosquash' option by default.

OPTIONS
-------
<newbase>::
Expand Down Expand Up @@ -326,6 +329,7 @@ idea unless you know what you are doing (see BUGS below).
instead.

--autosquash::
--no-autosquash::
When the commit log message begins with "squash! ..." (or
"fixup! ..."), and there is a commit whose title begins with
the same ..., automatically modify the todo list of rebase -i
Expand All @@ -334,6 +338,10 @@ idea unless you know what you are doing (see BUGS below).
commit from `pick` to `squash` (or `fixup`).
+
This option is only valid when the '--interactive' option is used.
+
If the '--autosquash' option is enabled by default using the
configuration variable `rebase.autosquash`, this option can be
used to override and disable this setting.

--no-ff::
With --interactive, cherry-pick all rebased commits instead of
Expand Down
4 changes: 4 additions & 0 deletions git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ VERBOSE=
OK_TO_SKIP_PRE_REBASE=
REBASE_ROOT=
AUTOSQUASH=
test "$(git config --bool rebase.autosquash)" = "true" && AUTOSQUASH=t
NEVER_FF=

GIT_CHERRY_PICK_HELP=" After resolving the conflicts,
Expand Down Expand Up @@ -795,6 +796,9 @@ first and then run 'git rebase --continue' again."
--autosquash)
AUTOSQUASH=t
;;
--no-autosquash)
AUTOSQUASH=
;;
--onto)
shift
ONTO=$(parse_onto "$1") ||
Expand Down
40 changes: 32 additions & 8 deletions t/t3415-rebase-autosquash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,62 @@ test_expect_success setup '
git tag base
'

test_expect_success 'auto fixup' '
test_auto_fixup() {
git reset --hard base &&
echo 1 >file1 &&
git add -u &&
test_tick &&
git commit -m "fixup! first"

git tag final-fixup &&
git tag $1 &&
test_tick &&
git rebase --autosquash -i HEAD^^^ &&
git rebase $2 -i HEAD^^^ &&
git log --oneline >actual &&
test 3 = $(wc -l <actual) &&
git diff --exit-code final-fixup &&
git diff --exit-code $1 &&
test 1 = "$(git cat-file blob HEAD^:file1)" &&
test 1 = $(git cat-file commit HEAD^ | grep first | wc -l)
}

test_expect_success 'auto fixup (option)' '
test_auto_fixup final-fixup-option --autosquash
'

test_expect_success 'auto fixup (config)' '
git config rebase.autosquash true &&
test_auto_fixup final-fixup-config-true &&
test_must_fail test_auto_fixup fixup-config-true-no --no-autosquash &&
git config rebase.autosquash false &&
test_must_fail test_auto_fixup final-fixup-config-false
'

test_expect_success 'auto squash' '
test_auto_squash() {
git reset --hard base &&
echo 1 >file1 &&
git add -u &&
test_tick &&
git commit -m "squash! first"

git tag final-squash &&
git tag $1 &&
test_tick &&
git rebase --autosquash -i HEAD^^^ &&
git rebase $2 -i HEAD^^^ &&
git log --oneline >actual &&
test 3 = $(wc -l <actual) &&
git diff --exit-code final-squash &&
git diff --exit-code $1 &&
test 1 = "$(git cat-file blob HEAD^:file1)" &&
test 2 = $(git cat-file commit HEAD^ | grep first | wc -l)
}

test_expect_success 'auto squash (option)' '
test_auto_squash final-squash --autosquash
'

test_expect_success 'auto squash (config)' '
git config rebase.autosquash true &&
test_auto_squash final-squash-config-true &&
test_must_fail test_auto_squash squash-config-true-no --no-autosquash &&
git config rebase.autosquash false &&
test_must_fail test_auto_squash final-squash-config-false
'

test_expect_success 'misspelled auto squash' '
Expand Down

0 comments on commit dd1e5b3

Please sign in to comment.