git-commit-vandalism/t/t3201-branch-contains.sh
Johannes Schindelin 334afbc76f 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 15:44:17 -08:00

270 lines
5.5 KiB
Bash
Executable File

#!/bin/sh
test_description='branch --contains <commit>, --no-contains <commit> --merged, and --no-merged'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
test_expect_success setup '
>file &&
git add file &&
test_tick &&
git commit -m initial &&
git branch side &&
echo 1 >file &&
test_tick &&
git commit -a -m "second on master" &&
git checkout side &&
echo 1 >file &&
test_tick &&
git commit -a -m "second on side" &&
git merge master
'
test_expect_success 'branch --contains=master' '
git branch --contains=master >actual &&
{
echo " master" && echo "* side"
} >expect &&
test_cmp expect actual
'
test_expect_success 'branch --contains master' '
git branch --contains master >actual &&
{
echo " master" && echo "* side"
} >expect &&
test_cmp expect actual
'
test_expect_success 'branch --no-contains=master' '
git branch --no-contains=master >actual &&
test_must_be_empty actual
'
test_expect_success 'branch --no-contains master' '
git branch --no-contains master >actual &&
test_must_be_empty actual
'
test_expect_success 'branch --contains=side' '
git branch --contains=side >actual &&
{
echo "* side"
} >expect &&
test_cmp expect actual
'
test_expect_success 'branch --no-contains=side' '
git branch --no-contains=side >actual &&
{
echo " master"
} >expect &&
test_cmp expect actual
'
test_expect_success 'branch --contains with pattern implies --list' '
git branch --contains=master master >actual &&
{
echo " master"
} >expect &&
test_cmp expect actual
'
test_expect_success 'branch --no-contains with pattern implies --list' '
git branch --no-contains=master master >actual &&
test_must_be_empty actual
'
test_expect_success 'side: branch --merged' '
git branch --merged >actual &&
{
echo " master" &&
echo "* side"
} >expect &&
test_cmp expect actual
'
test_expect_success 'branch --merged with pattern implies --list' '
git branch --merged=side master >actual &&
{
echo " master"
} >expect &&
test_cmp expect actual
'
test_expect_success 'side: branch --no-merged' '
git branch --no-merged >actual &&
test_must_be_empty actual
'
test_expect_success 'master: branch --merged' '
git checkout master &&
git branch --merged >actual &&
{
echo "* master"
} >expect &&
test_cmp expect actual
'
test_expect_success 'master: branch --no-merged' '
git branch --no-merged >actual &&
{
echo " side"
} >expect &&
test_cmp expect actual
'
test_expect_success 'branch --no-merged with pattern implies --list' '
git branch --no-merged=master master >actual &&
test_must_be_empty actual
'
test_expect_success 'implicit --list conflicts with modification options' '
test_must_fail git branch --contains=master -d &&
test_must_fail git branch --contains=master -m foo &&
test_must_fail git branch --no-contains=master -d &&
test_must_fail git branch --no-contains=master -m foo
'
test_expect_success 'Assert that --contains only works on commits, not trees & blobs' '
test_must_fail git branch --contains master^{tree} &&
blob=$(git hash-object -w --stdin <<-\EOF
Some blob
EOF
) &&
test_must_fail git branch --contains $blob &&
test_must_fail git branch --no-contains $blob
'
test_expect_success 'multiple branch --contains' '
git checkout -b side2 master &&
>feature &&
git add feature &&
git commit -m "add feature" &&
git checkout -b next master &&
git merge side &&
git branch --contains side --contains side2 >actual &&
cat >expect <<-\EOF &&
* next
side
side2
EOF
test_cmp expect actual
'
test_expect_success 'multiple branch --merged' '
git branch --merged next --merged master >actual &&
cat >expect <<-\EOF &&
master
* next
side
EOF
test_cmp expect actual
'
test_expect_success 'multiple branch --no-contains' '
git branch --no-contains side --no-contains side2 >actual &&
cat >expect <<-\EOF &&
master
EOF
test_cmp expect actual
'
test_expect_success 'multiple branch --no-merged' '
git branch --no-merged next --no-merged master >actual &&
cat >expect <<-\EOF &&
side2
EOF
test_cmp expect actual
'
test_expect_success 'branch --contains combined with --no-contains' '
git checkout -b seen master &&
git merge side &&
git merge side2 &&
git branch --contains side --no-contains side2 >actual &&
cat >expect <<-\EOF &&
next
side
EOF
test_cmp expect actual
'
test_expect_success 'branch --merged combined with --no-merged' '
git branch --merged seen --no-merged next >actual &&
cat >expect <<-\EOF &&
* seen
side2
EOF
test_cmp expect actual
'
# We want to set up a case where the walk for the tracking info
# of one branch crosses the tip of another branch (and make sure
# that the latter walk does not mess up our flag to see if it was
# merged).
#
# Here "topic" tracks "master" with one extra commit, and "zzz" points to the
# same tip as master The name "zzz" must come alphabetically after "topic"
# as we process them in that order.
test_expect_success PREPARE_FOR_MAIN_BRANCH 'branch --merged with --verbose' '
git branch --track topic master &&
git branch zzz topic &&
git checkout topic &&
test_commit foo &&
git branch --merged topic >actual &&
cat >expect <<-\EOF &&
master
* topic
zzz
EOF
test_cmp expect actual &&
git branch --verbose --merged topic >actual &&
cat >expect <<-EOF &&
main $(git rev-parse --short main) second on main
* topic $(git rev-parse --short topic ) [ahead 1] foo
zzz $(git rev-parse --short zzz ) second on main
EOF
test_i18ncmp expect actual
'
test_done