2009-12-08 11:13:14 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='auto squash'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2013-06-28 03:26:31 +08:00
|
|
|
. "$TEST_DIRECTORY"/lib-rebase.sh
|
|
|
|
|
2009-12-08 11:13:14 +08:00
|
|
|
test_expect_success setup '
|
|
|
|
echo 0 >file0 &&
|
|
|
|
git add . &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "initial commit" &&
|
|
|
|
echo 0 >file1 &&
|
|
|
|
echo 2 >file2 &&
|
|
|
|
git add . &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "first commit" &&
|
2010-11-03 03:59:10 +08:00
|
|
|
git tag first-commit &&
|
2009-12-08 11:13:14 +08:00
|
|
|
echo 3 >file3 &&
|
|
|
|
git add . &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "second commit" &&
|
|
|
|
git tag base
|
|
|
|
'
|
|
|
|
|
2010-11-03 03:59:10 +08:00
|
|
|
test_auto_fixup () {
|
2009-12-08 11:13:14 +08:00
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2010-10-02 05:19:19 +08:00
|
|
|
git commit -m "fixup! first" &&
|
2009-12-08 11:13:14 +08:00
|
|
|
|
2010-07-14 19:59:57 +08:00
|
|
|
git tag $1 &&
|
2009-12-08 11:13:14 +08:00
|
|
|
test_tick &&
|
2010-07-14 19:59:57 +08:00
|
|
|
git rebase $2 -i HEAD^^^ &&
|
2009-12-08 11:13:14 +08:00
|
|
|
git log --oneline >actual &&
|
2012-04-11 19:24:01 +08:00
|
|
|
test_line_count = 3 actual &&
|
2010-07-14 19:59:57 +08:00
|
|
|
git diff --exit-code $1 &&
|
2009-12-08 11:13:14 +08:00
|
|
|
test 1 = "$(git cat-file blob HEAD^:file1)" &&
|
|
|
|
test 1 = $(git cat-file commit HEAD^ | grep first | wc -l)
|
2010-07-14 19:59:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2009-12-08 11:13:14 +08:00
|
|
|
'
|
|
|
|
|
2010-11-03 03:59:10 +08:00
|
|
|
test_auto_squash () {
|
2009-12-08 11:13:14 +08:00
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2010-10-02 05:19:19 +08:00
|
|
|
git commit -m "squash! first" &&
|
2009-12-08 11:13:14 +08:00
|
|
|
|
2010-07-14 19:59:57 +08:00
|
|
|
git tag $1 &&
|
2009-12-08 11:13:14 +08:00
|
|
|
test_tick &&
|
2010-07-14 19:59:57 +08:00
|
|
|
git rebase $2 -i HEAD^^^ &&
|
2009-12-08 11:13:14 +08:00
|
|
|
git log --oneline >actual &&
|
2012-04-11 19:24:01 +08:00
|
|
|
test_line_count = 3 actual &&
|
2010-07-14 19:59:57 +08:00
|
|
|
git diff --exit-code $1 &&
|
2009-12-08 11:13:14 +08:00
|
|
|
test 1 = "$(git cat-file blob HEAD^:file1)" &&
|
|
|
|
test 2 = $(git cat-file commit HEAD^ | grep first | wc -l)
|
2010-07-14 19:59:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2009-12-08 11:13:14 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'misspelled auto squash' '
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2010-10-02 05:19:19 +08:00
|
|
|
git commit -m "squash! forst" &&
|
2009-12-08 11:13:14 +08:00
|
|
|
git tag final-missquash &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD^^^ &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 19:24:01 +08:00
|
|
|
test_line_count = 4 actual &&
|
2009-12-08 11:13:14 +08:00
|
|
|
git diff --exit-code final-missquash &&
|
|
|
|
test 0 = $(git rev-list final-missquash...HEAD | wc -l)
|
|
|
|
'
|
|
|
|
|
2010-11-05 06:36:31 +08:00
|
|
|
test_expect_success 'auto squash that matches 2 commits' '
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 4 >file4 &&
|
|
|
|
git add file4 &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "first new commit" &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "squash! first" &&
|
|
|
|
git tag final-multisquash &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD~4 &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 19:24:01 +08:00
|
|
|
test_line_count = 4 actual &&
|
2010-11-05 06:36:31 +08:00
|
|
|
git diff --exit-code final-multisquash &&
|
|
|
|
test 1 = "$(git cat-file blob HEAD^^:file1)" &&
|
|
|
|
test 2 = $(git cat-file commit HEAD^^ | grep first | wc -l) &&
|
|
|
|
test 1 = $(git cat-file commit HEAD | grep first | wc -l)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'auto squash that matches a commit after the squash' '
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "squash! third" &&
|
|
|
|
echo 4 >file4 &&
|
|
|
|
git add file4 &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "third commit" &&
|
|
|
|
git tag final-presquash &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD~4 &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 19:24:01 +08:00
|
|
|
test_line_count = 5 actual &&
|
2010-11-05 06:36:31 +08:00
|
|
|
git diff --exit-code final-presquash &&
|
|
|
|
test 0 = "$(git cat-file blob HEAD^^:file1)" &&
|
|
|
|
test 1 = "$(git cat-file blob HEAD^:file1)" &&
|
|
|
|
test 1 = $(git cat-file commit HEAD | grep third | wc -l) &&
|
|
|
|
test 1 = $(git cat-file commit HEAD^ | grep third | wc -l)
|
|
|
|
'
|
2010-11-05 06:36:32 +08:00
|
|
|
test_expect_success 'auto squash that matches a sha1' '
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "squash! $(git rev-parse --short HEAD^)" &&
|
|
|
|
git tag final-shasquash &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD^^^ &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 19:24:01 +08:00
|
|
|
test_line_count = 3 actual &&
|
2010-11-05 06:36:32 +08:00
|
|
|
git diff --exit-code final-shasquash &&
|
|
|
|
test 1 = "$(git cat-file blob HEAD^:file1)" &&
|
|
|
|
test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'auto squash that matches longer sha1' '
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "squash! $(git rev-parse --short=11 HEAD^)" &&
|
|
|
|
git tag final-longshasquash &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD^^^ &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 19:24:01 +08:00
|
|
|
test_line_count = 3 actual &&
|
2010-11-05 06:36:32 +08:00
|
|
|
git diff --exit-code final-longshasquash &&
|
|
|
|
test 1 = "$(git cat-file blob HEAD^:file1)" &&
|
|
|
|
test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l)
|
|
|
|
'
|
2010-11-05 06:36:31 +08:00
|
|
|
|
2010-11-03 03:59:10 +08:00
|
|
|
test_auto_commit_flags () {
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --$1 first-commit &&
|
|
|
|
git tag final-commit-$1 &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD^^^ &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 19:24:01 +08:00
|
|
|
test_line_count = 3 actual &&
|
2010-11-03 03:59:10 +08:00
|
|
|
git diff --exit-code final-commit-$1 &&
|
|
|
|
test 1 = "$(git cat-file blob HEAD^:file1)" &&
|
|
|
|
test $2 = $(git cat-file commit HEAD^ | grep first | wc -l)
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'use commit --fixup' '
|
|
|
|
test_auto_commit_flags fixup 1
|
|
|
|
'
|
|
|
|
|
2010-11-03 03:59:12 +08:00
|
|
|
test_expect_success 'use commit --squash' '
|
|
|
|
test_auto_commit_flags squash 2
|
|
|
|
'
|
|
|
|
|
2013-06-28 03:26:31 +08:00
|
|
|
test_auto_fixup_fixup () {
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "$1! first" &&
|
|
|
|
echo 2 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "$1! $2! first" &&
|
|
|
|
git tag "final-$1-$2" &&
|
|
|
|
test_tick &&
|
|
|
|
(
|
|
|
|
set_cat_todo_editor &&
|
|
|
|
test_must_fail git rebase --autosquash -i HEAD^^^^ >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
pick $(git rev-parse --short HEAD^^^) first commit
|
|
|
|
$1 $(git rev-parse --short HEAD^) $1! first
|
|
|
|
$1 $(git rev-parse --short HEAD) $1! $2! first
|
|
|
|
pick $(git rev-parse --short HEAD^^) second commit
|
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
) &&
|
|
|
|
git rebase --autosquash -i HEAD^^^^ &&
|
|
|
|
git log --oneline >actual &&
|
|
|
|
test_line_count = 3 actual
|
|
|
|
git diff --exit-code "final-$1-$2" &&
|
|
|
|
test 2 = "$(git cat-file blob HEAD^:file1)" &&
|
|
|
|
if test "$1" = "fixup"
|
|
|
|
then
|
|
|
|
test 1 = $(git cat-file commit HEAD^ | grep first | wc -l)
|
|
|
|
elif test "$1" = "squash"
|
|
|
|
then
|
|
|
|
test 3 = $(git cat-file commit HEAD^ | grep first | wc -l)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'fixup! fixup!' '
|
|
|
|
test_auto_fixup_fixup fixup fixup
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fixup! squash!' '
|
|
|
|
test_auto_fixup_fixup fixup squash
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'squash! squash!' '
|
|
|
|
test_auto_fixup_fixup squash squash
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'squash! fixup!' '
|
|
|
|
test_auto_fixup_fixup squash fixup
|
|
|
|
'
|
|
|
|
|
2015-06-14 00:26:58 +08:00
|
|
|
test_expect_success 'autosquash with custom inst format' '
|
|
|
|
git reset --hard base &&
|
|
|
|
git config --add rebase.instructionFormat "[%an @ %ar] %s" &&
|
|
|
|
echo 2 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "squash! $(git rev-parse --short HEAD^)" &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "squash! $(git log -n 1 --format=%s HEAD~2)" &&
|
|
|
|
git tag final-squash-instFmt &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD~4 &&
|
|
|
|
git log --oneline >actual &&
|
|
|
|
test_line_count = 3 actual &&
|
|
|
|
git diff --exit-code final-squash-instFmt &&
|
|
|
|
test 1 = "$(git cat-file blob HEAD^:file1)" &&
|
|
|
|
test 2 = $(git cat-file commit HEAD^ | grep squash | wc -l)
|
|
|
|
'
|
|
|
|
|
2009-12-08 11:13:14 +08:00
|
|
|
test_done
|