2009-12-08 04:13:14 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='auto squash'
|
|
|
|
|
2020-11-19 00:44:25 +01:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-19 00:44:19 +01:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2009-12-08 04:13:14 +01:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2013-06-27 21:26:31 +02:00
|
|
|
. "$TEST_DIRECTORY"/lib-rebase.sh
|
|
|
|
|
2009-12-08 04:13:14 +01: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-02 20:59:10 +01:00
|
|
|
git tag first-commit &&
|
2009-12-08 04:13:14 +01:00
|
|
|
echo 3 >file3 &&
|
|
|
|
git add . &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "second commit" &&
|
|
|
|
git tag base
|
|
|
|
'
|
|
|
|
|
2010-11-02 20:59:10 +01:00
|
|
|
test_auto_fixup () {
|
2020-01-07 05:53:08 +01:00
|
|
|
no_squash= &&
|
|
|
|
if test "x$1" = 'x!'
|
|
|
|
then
|
|
|
|
no_squash=true
|
|
|
|
shift
|
|
|
|
fi &&
|
|
|
|
|
2009-12-08 04:13:14 +01:00
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2010-10-01 23:19:19 +02:00
|
|
|
git commit -m "fixup! first" &&
|
2009-12-08 04:13:14 +01:00
|
|
|
|
2010-07-14 13:59:57 +02:00
|
|
|
git tag $1 &&
|
2009-12-08 04:13:14 +01:00
|
|
|
test_tick &&
|
2010-07-14 13:59:57 +02:00
|
|
|
git rebase $2 -i HEAD^^^ &&
|
2009-12-08 04:13:14 +01:00
|
|
|
git log --oneline >actual &&
|
2020-01-07 05:53:08 +01:00
|
|
|
if test -n "$no_squash"
|
|
|
|
then
|
|
|
|
test_line_count = 4 actual
|
|
|
|
else
|
|
|
|
test_line_count = 3 actual &&
|
|
|
|
git diff --exit-code $1 &&
|
|
|
|
echo 1 >expect &&
|
|
|
|
git cat-file blob HEAD^:file1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git cat-file commit HEAD^ >commit &&
|
|
|
|
grep first commit >actual &&
|
|
|
|
test_line_count = 1 actual
|
|
|
|
fi
|
2010-07-14 13:59:57 +02: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 &&
|
2020-01-07 05:53:08 +01:00
|
|
|
test_auto_fixup ! fixup-config-true-no --no-autosquash &&
|
2010-07-14 13:59:57 +02:00
|
|
|
git config rebase.autosquash false &&
|
2020-01-07 05:53:08 +01:00
|
|
|
test_auto_fixup ! final-fixup-config-false
|
2009-12-08 04:13:14 +01:00
|
|
|
'
|
|
|
|
|
2010-11-02 20:59:10 +01:00
|
|
|
test_auto_squash () {
|
2020-01-07 05:53:08 +01:00
|
|
|
no_squash= &&
|
|
|
|
if test "x$1" = 'x!'
|
|
|
|
then
|
|
|
|
no_squash=true
|
|
|
|
shift
|
|
|
|
fi &&
|
|
|
|
|
2009-12-08 04:13:14 +01:00
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2021-01-29 19:20:44 +01:00
|
|
|
git commit -m "squash! first" -m "extra para for first" &&
|
2010-07-14 13:59:57 +02:00
|
|
|
git tag $1 &&
|
2009-12-08 04:13:14 +01:00
|
|
|
test_tick &&
|
2010-07-14 13:59:57 +02:00
|
|
|
git rebase $2 -i HEAD^^^ &&
|
2009-12-08 04:13:14 +01:00
|
|
|
git log --oneline >actual &&
|
2020-01-07 05:53:08 +01:00
|
|
|
if test -n "$no_squash"
|
|
|
|
then
|
|
|
|
test_line_count = 4 actual
|
|
|
|
else
|
|
|
|
test_line_count = 3 actual &&
|
|
|
|
git diff --exit-code $1 &&
|
|
|
|
echo 1 >expect &&
|
|
|
|
git cat-file blob HEAD^:file1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git cat-file commit HEAD^ >commit &&
|
|
|
|
grep first commit >actual &&
|
|
|
|
test_line_count = 2 actual
|
|
|
|
fi
|
2010-07-14 13:59:57 +02: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 &&
|
2020-01-07 05:53:08 +01:00
|
|
|
test_auto_squash ! squash-config-true-no --no-autosquash &&
|
2010-07-14 13:59:57 +02:00
|
|
|
git config rebase.autosquash false &&
|
2020-01-07 05:53:08 +01:00
|
|
|
test_auto_squash ! final-squash-config-false
|
2009-12-08 04:13:14 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'misspelled auto squash' '
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2010-10-01 23:19:19 +02:00
|
|
|
git commit -m "squash! forst" &&
|
2009-12-08 04:13:14 +01:00
|
|
|
git tag final-missquash &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD^^^ &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 13:24:01 +02:00
|
|
|
test_line_count = 4 actual &&
|
2009-12-08 04:13:14 +01:00
|
|
|
git diff --exit-code final-missquash &&
|
2020-01-07 05:53:07 +01:00
|
|
|
git rev-list final-missquash...HEAD >list &&
|
|
|
|
test_must_be_empty list
|
2009-12-08 04:13:14 +01:00
|
|
|
'
|
|
|
|
|
2010-11-04 23:36:31 +01: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 &&
|
2021-01-29 19:20:44 +01:00
|
|
|
git commit -m "squash! first" -m "extra para for first" &&
|
2010-11-04 23:36:31 +01:00
|
|
|
git tag final-multisquash &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD~4 &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 13:24:01 +02:00
|
|
|
test_line_count = 4 actual &&
|
2010-11-04 23:36:31 +01:00
|
|
|
git diff --exit-code final-multisquash &&
|
2020-01-07 05:53:07 +01:00
|
|
|
echo 1 >expect &&
|
|
|
|
git cat-file blob HEAD^^:file1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git cat-file commit HEAD^^ >commit &&
|
|
|
|
grep first commit >actual &&
|
|
|
|
test_line_count = 2 actual &&
|
|
|
|
git cat-file commit HEAD >commit &&
|
|
|
|
grep first commit >actual &&
|
|
|
|
test_line_count = 1 actual
|
2010-11-04 23:36:31 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
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 13:24:01 +02:00
|
|
|
test_line_count = 5 actual &&
|
2010-11-04 23:36:31 +01:00
|
|
|
git diff --exit-code final-presquash &&
|
2020-01-07 05:53:07 +01:00
|
|
|
echo 0 >expect &&
|
|
|
|
git cat-file blob HEAD^^:file1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
echo 1 >expect &&
|
|
|
|
git cat-file blob HEAD^:file1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git cat-file commit HEAD >commit &&
|
|
|
|
grep third commit >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
|
|
|
git cat-file commit HEAD^ >commit &&
|
|
|
|
grep third commit >actual &&
|
|
|
|
test_line_count = 1 actual
|
2010-11-04 23:36:31 +01:00
|
|
|
'
|
2010-11-04 23:36:32 +01:00
|
|
|
test_expect_success 'auto squash that matches a sha1' '
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2020-01-07 05:53:07 +01:00
|
|
|
oid=$(git rev-parse --short HEAD^) &&
|
2021-01-29 19:20:44 +01:00
|
|
|
git commit -m "squash! $oid" -m "extra para" &&
|
2010-11-04 23:36:32 +01:00
|
|
|
git tag final-shasquash &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD^^^ &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 13:24:01 +02:00
|
|
|
test_line_count = 3 actual &&
|
2010-11-04 23:36:32 +01:00
|
|
|
git diff --exit-code final-shasquash &&
|
2020-01-07 05:53:07 +01:00
|
|
|
echo 1 >expect &&
|
|
|
|
git cat-file blob HEAD^:file1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git cat-file commit HEAD^ >commit &&
|
2021-01-29 19:20:44 +01:00
|
|
|
! grep "squash" commit &&
|
|
|
|
grep "^extra para" commit >actual &&
|
2020-01-07 05:53:07 +01:00
|
|
|
test_line_count = 1 actual
|
2010-11-04 23:36:32 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'auto squash that matches longer sha1' '
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2020-01-07 05:53:07 +01:00
|
|
|
oid=$(git rev-parse --short=11 HEAD^) &&
|
2021-01-29 19:20:44 +01:00
|
|
|
git commit -m "squash! $oid" -m "extra para" &&
|
2010-11-04 23:36:32 +01:00
|
|
|
git tag final-longshasquash &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD^^^ &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 13:24:01 +02:00
|
|
|
test_line_count = 3 actual &&
|
2010-11-04 23:36:32 +01:00
|
|
|
git diff --exit-code final-longshasquash &&
|
2020-01-07 05:53:07 +01:00
|
|
|
echo 1 >expect &&
|
|
|
|
git cat-file blob HEAD^:file1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git cat-file commit HEAD^ >commit &&
|
2021-01-29 19:20:44 +01:00
|
|
|
! grep "squash" commit &&
|
|
|
|
grep "^extra para" commit >actual &&
|
2020-01-07 05:53:07 +01:00
|
|
|
test_line_count = 1 actual
|
2010-11-04 23:36:32 +01:00
|
|
|
'
|
2010-11-04 23:36:31 +01:00
|
|
|
|
2022-09-25 00:29:04 +02:00
|
|
|
test_expect_success 'auto squash of fixup commit that matches branch name which points back to fixup commit' '
|
|
|
|
git reset --hard base &&
|
|
|
|
git commit --allow-empty -m "fixup! self-cycle" &&
|
|
|
|
git branch self-cycle &&
|
|
|
|
GIT_SEQUENCE_EDITOR="cat >tmp" git rebase --autosquash -i HEAD^^ &&
|
|
|
|
sed -ne "/^[^#]/{s/[0-9a-f]\{7,\}/HASH/g;p;}" tmp >actual &&
|
|
|
|
cat <<-EOF >expect &&
|
|
|
|
pick HASH second commit
|
|
|
|
pick HASH fixup! self-cycle # empty
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2010-11-02 20:59:10 +01:00
|
|
|
test_auto_commit_flags () {
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2021-01-29 19:20:44 +01:00
|
|
|
git commit --$1 first-commit -m "extra para for first" &&
|
2010-11-02 20:59:10 +01:00
|
|
|
git tag final-commit-$1 &&
|
|
|
|
test_tick &&
|
|
|
|
git rebase --autosquash -i HEAD^^^ &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 13:24:01 +02:00
|
|
|
test_line_count = 3 actual &&
|
2010-11-02 20:59:10 +01:00
|
|
|
git diff --exit-code final-commit-$1 &&
|
2020-01-07 05:53:07 +01:00
|
|
|
echo 1 >expect &&
|
|
|
|
git cat-file blob HEAD^:file1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git cat-file commit HEAD^ >commit &&
|
|
|
|
grep first commit >actual &&
|
|
|
|
test_line_count = $2 actual
|
2010-11-02 20:59:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'use commit --fixup' '
|
|
|
|
test_auto_commit_flags fixup 1
|
|
|
|
'
|
|
|
|
|
2010-11-02 20:59:12 +01:00
|
|
|
test_expect_success 'use commit --squash' '
|
|
|
|
test_auto_commit_flags squash 2
|
|
|
|
'
|
|
|
|
|
2013-06-27 21:26:31 +02:00
|
|
|
test_auto_fixup_fixup () {
|
|
|
|
git reset --hard base &&
|
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2021-01-29 19:20:44 +01:00
|
|
|
git commit -m "$1! first" -m "extra para for first" &&
|
2013-06-27 21:26:31 +02:00
|
|
|
echo 2 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2021-01-29 19:20:44 +01:00
|
|
|
git commit -m "$1! $2! first" -m "second extra para for first" &&
|
2013-06-27 21:26:31 +02:00
|
|
|
git tag "final-$1-$2" &&
|
|
|
|
test_tick &&
|
|
|
|
(
|
|
|
|
set_cat_todo_editor &&
|
|
|
|
test_must_fail git rebase --autosquash -i HEAD^^^^ >actual &&
|
2020-01-07 05:53:07 +01:00
|
|
|
head=$(git rev-parse --short HEAD) &&
|
|
|
|
parent1=$(git rev-parse --short HEAD^) &&
|
|
|
|
parent2=$(git rev-parse --short HEAD^^) &&
|
|
|
|
parent3=$(git rev-parse --short HEAD^^^) &&
|
2013-06-27 21:26:31 +02:00
|
|
|
cat >expected <<-EOF &&
|
2020-01-07 05:53:07 +01:00
|
|
|
pick $parent3 first commit
|
|
|
|
$1 $parent1 $1! first
|
|
|
|
$1 $head $1! $2! first
|
|
|
|
pick $parent2 second commit
|
2013-06-27 21:26:31 +02:00
|
|
|
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" &&
|
2020-01-07 05:53:07 +01:00
|
|
|
echo 2 >expect &&
|
|
|
|
git cat-file blob HEAD^:file1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git cat-file commit HEAD^ >commit &&
|
|
|
|
grep first commit >actual &&
|
2013-06-27 21:26:31 +02:00
|
|
|
if test "$1" = "fixup"
|
|
|
|
then
|
2020-01-07 05:53:07 +01:00
|
|
|
test_line_count = 1 actual
|
2013-06-27 21:26:31 +02:00
|
|
|
elif test "$1" = "squash"
|
|
|
|
then
|
2020-01-07 05:53:07 +01:00
|
|
|
test_line_count = 3 actual
|
2013-06-27 21:26:31 +02:00
|
|
|
else
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-02-11 02:53:51 +01:00
|
|
|
test_expect_success 'fixup! fixup!' '
|
2013-06-27 21:26:31 +02:00
|
|
|
test_auto_fixup_fixup fixup fixup
|
|
|
|
'
|
|
|
|
|
2021-02-11 02:53:51 +01:00
|
|
|
test_expect_success 'fixup! squash!' '
|
2013-06-27 21:26:31 +02:00
|
|
|
test_auto_fixup_fixup fixup squash
|
|
|
|
'
|
|
|
|
|
2021-02-11 02:53:51 +01:00
|
|
|
test_expect_success 'squash! squash!' '
|
2013-06-27 21:26:31 +02:00
|
|
|
test_auto_fixup_fixup squash squash
|
|
|
|
'
|
|
|
|
|
2021-02-11 02:53:51 +01:00
|
|
|
test_expect_success 'squash! fixup!' '
|
2013-06-27 21:26:31 +02:00
|
|
|
test_auto_fixup_fixup squash fixup
|
|
|
|
'
|
|
|
|
|
2021-02-11 02:53:51 +01:00
|
|
|
test_expect_success 'autosquash with custom inst format' '
|
2015-06-13 18:26:58 +02:00
|
|
|
git reset --hard base &&
|
|
|
|
git config --add rebase.instructionFormat "[%an @ %ar] %s" &&
|
|
|
|
echo 2 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2020-01-07 05:53:07 +01:00
|
|
|
oid=$(git rev-parse --short HEAD^) &&
|
2021-01-29 19:20:44 +01:00
|
|
|
git commit -m "squash! $oid" -m "extra para for first" &&
|
2015-06-13 18:26:58 +02:00
|
|
|
echo 1 >file1 &&
|
|
|
|
git add -u &&
|
|
|
|
test_tick &&
|
2020-01-07 05:53:07 +01:00
|
|
|
subject=$(git log -n 1 --format=%s HEAD~2) &&
|
2021-01-29 19:20:44 +01:00
|
|
|
git commit -m "squash! $subject" -m "second extra para for first" &&
|
2015-06-13 18:26:58 +02:00
|
|
|
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 &&
|
2020-01-07 05:53:07 +01:00
|
|
|
echo 1 >expect &&
|
|
|
|
git cat-file blob HEAD^:file1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git cat-file commit HEAD^ >commit &&
|
2021-01-29 19:20:44 +01:00
|
|
|
! grep "squash" commit &&
|
|
|
|
grep first commit >actual &&
|
|
|
|
test_line_count = 3 actual
|
2015-06-13 18:26:58 +02:00
|
|
|
'
|
|
|
|
|
2017-07-14 16:44:38 +02:00
|
|
|
test_expect_success 'autosquash with empty custom instructionFormat' '
|
|
|
|
git reset --hard base &&
|
|
|
|
test_commit empty-instructionFormat-test &&
|
|
|
|
(
|
|
|
|
set_cat_todo_editor &&
|
|
|
|
test_must_fail git -c rebase.instructionFormat= \
|
2019-03-25 19:14:19 +01:00
|
|
|
rebase --autosquash --force-rebase -i HEAD^ >actual &&
|
2017-07-14 16:44:38 +02:00
|
|
|
git log -1 --format="pick %h %s" >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-07-07 17:52:54 +02:00
|
|
|
set_backup_editor () {
|
|
|
|
write_script backup-editor.sh <<-\EOF
|
|
|
|
cp "$1" .git/backup-"$(basename "$1")"
|
|
|
|
EOF
|
|
|
|
test_set_editor "$PWD/backup-editor.sh"
|
|
|
|
}
|
|
|
|
|
2017-07-14 16:45:31 +02:00
|
|
|
test_expect_success 'autosquash with multiple empty patches' '
|
2016-07-07 17:52:54 +02:00
|
|
|
test_tick &&
|
|
|
|
git commit --allow-empty -m "empty" &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --allow-empty -m "empty2" &&
|
|
|
|
test_tick &&
|
|
|
|
>fixup &&
|
|
|
|
git add fixup &&
|
|
|
|
git commit --fixup HEAD^^ &&
|
|
|
|
(
|
|
|
|
set_backup_editor &&
|
|
|
|
GIT_USE_REBASE_HELPER=false \
|
|
|
|
git rebase -i --force-rebase --autosquash HEAD~4 &&
|
|
|
|
grep empty2 .git/backup-git-rebase-todo
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-07-07 17:52:57 +02:00
|
|
|
test_expect_success 'extra spaces after fixup!' '
|
|
|
|
base=$(git rev-parse HEAD) &&
|
|
|
|
test_commit to-fixup &&
|
|
|
|
git commit --allow-empty -m "fixup! to-fixup" &&
|
|
|
|
git rebase -i --autosquash --keep-empty HEAD~2 &&
|
|
|
|
parent=$(git rev-parse HEAD^) &&
|
|
|
|
test $base = $parent
|
|
|
|
'
|
|
|
|
|
2017-07-14 16:45:28 +02:00
|
|
|
test_expect_success 'wrapped original subject' '
|
|
|
|
if test -d .git/rebase-merge; then git rebase --abort; fi &&
|
|
|
|
base=$(git rev-parse HEAD) &&
|
|
|
|
echo "wrapped subject" >wrapped &&
|
|
|
|
git add wrapped &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --allow-empty -m "$(printf "To\nfixup")" &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --allow-empty -m "fixup! To fixup" &&
|
|
|
|
git rebase -i --autosquash --keep-empty HEAD~2 &&
|
|
|
|
parent=$(git rev-parse HEAD^) &&
|
|
|
|
test $base = $parent
|
|
|
|
'
|
|
|
|
|
2018-09-01 01:45:04 +02:00
|
|
|
test_expect_success 'abort last squash' '
|
2018-09-01 01:45:02 +02:00
|
|
|
test_when_finished "test_might_fail git rebase --abort" &&
|
2020-11-19 00:44:25 +01:00
|
|
|
test_when_finished "git checkout main" &&
|
2018-09-01 01:45:02 +02:00
|
|
|
|
|
|
|
git checkout -b some-squashes &&
|
|
|
|
git commit --allow-empty -m first &&
|
|
|
|
git commit --allow-empty --squash HEAD &&
|
|
|
|
git commit --allow-empty -m second &&
|
|
|
|
git commit --allow-empty --squash HEAD &&
|
|
|
|
|
|
|
|
test_must_fail git -c core.editor="grep -q ^pick" \
|
|
|
|
rebase -ki --autosquash HEAD~4 &&
|
|
|
|
: do not finish the squash, but resolve it manually &&
|
|
|
|
git commit --allow-empty --amend -m edited-first &&
|
|
|
|
git rebase --skip &&
|
|
|
|
git show >actual &&
|
|
|
|
! grep first actual
|
|
|
|
'
|
|
|
|
|
rebase --autosquash: fix a potential segfault
When rearranging the todo list so that the fixups/squashes are reordered
just after the commits they intend to fix up, we use two arrays to
maintain that list: `next` and `tail`.
The idea is that `next[i]`, if set to a non-negative value, contains the
index of the item that should be rearranged just after the `i`th item.
To avoid having to walk the entire `next` chain when appending another
fixup/squash, we also store the end of the `next` chain in `tail[i]`.
The logic we currently use to update these array items is based on the
assumption that given a fixup/squash item at index `i`, we just found
the index `i2` indicating the first item in that fixup chain.
However, as reported by Paul Ganssle, that need not be true: the special
form `fixup! <commit-hash>` is allowed to point to _another_ fixup
commit in the middle of the fixup chain.
Example:
* 0192a To fixup
* 02f12 fixup! To fixup
* 03763 fixup! To fixup
* 04ecb fixup! 02f12
Note how the fourth commit targets the second commit, which is already a
fixup that targets the first commit.
Previously, we would update `next` and `tail` under our assumption that
every `fixup!` commit would find the start of the `fixup!`/`squash!`
chain. This would lead to a segmentation fault because we would actually
end up with a `next[i]` pointing to a `fixup!` but the corresponding
`tail[i]` pointing nowhere, which would the lead to a segmentation
fault.
Let's fix this by _inserting_, rather than _appending_, the item. In
other words, if we make a given line successor of another line, we do
not simply forget any previously set successor of the latter, but make
it a successor of the former.
In the above example, at the point when we insert 04ecb just after
02f12, 03763 would already be recorded as a successor of 04ecb, and we
now "squeeze in" 04ecb.
To complete the idea, we now no longer assume that `next[i]` pointing to
a line means that `last[i]` points to a line, too. Instead, we extend
the concept of `last` to cover also partial `fixup!`/`squash!` chains,
i.e. chains starting in the middle of a larger such chain.
In the above example, after processing all lines, `last[0]`
(corresponding to 0192a) would point to 03763, which indeed is the end
of the overall `fixup!` chain, and `last[1]` (corresponding to 02f12)
would point to 04ecb (which is the last `fixup!` targeting 02f12, but it
has 03763 as successor, i.e. it is not the end of overall `fixup!`
chain).
Reported-by: Paul Ganssle <paul@ganssle.io>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-09 21:23:39 +02:00
|
|
|
test_expect_success 'fixup a fixup' '
|
|
|
|
echo 0to-fixup >file0 &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "to-fixup" file0 &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --squash HEAD -m X --allow-empty &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --squash HEAD^ -m Y --allow-empty &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "squash! $(git rev-parse HEAD^)" -m Z --allow-empty &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "squash! $(git rev-parse HEAD^^)" -m W --allow-empty &&
|
|
|
|
git rebase -ki --autosquash HEAD~5 &&
|
|
|
|
test XZWY = $(git show | tr -cd W-Z)
|
|
|
|
'
|
|
|
|
|
2021-01-28 17:16:42 +01:00
|
|
|
test_expect_success 'fixup does not clean up commit message' '
|
|
|
|
oneline="#818" &&
|
|
|
|
git commit --allow-empty -m "$oneline" &&
|
|
|
|
git commit --fixup HEAD --allow-empty &&
|
|
|
|
git -c commit.cleanup=strip rebase -ki --autosquash HEAD~2 &&
|
|
|
|
test "$oneline" = "$(git show -s --format=%s)"
|
|
|
|
'
|
|
|
|
|
2009-12-08 04:13:14 +01:00
|
|
|
test_done
|