1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-19 12:56:08 +02:00
git/t/t1506-rev-parse-diagnosis.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

261 lines
7.6 KiB
Bash
Executable File

#!/bin/sh
test_description='test git rev-parse diagnosis for invalid argument'
exec </dev/null
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
test_did_you_mean ()
{
cat >expected <<-EOF &&
fatal: path '$2$3' $4, but not ${5:-$SQ$3$SQ}
hint: Did you mean '$1:$2$3'${2:+ aka $SQ$1:./$3$SQ}?
EOF
test_i18ncmp expected error
}
HASH_file=
test_expect_success 'set up basic repo' '
echo one > file.txt &&
mkdir subdir &&
echo two > subdir/file.txt &&
echo three > subdir/file2.txt &&
git add . &&
git commit -m init &&
echo four > index-only.txt &&
git add index-only.txt &&
echo five > disk-only.txt
'
test_expect_success 'correct file objects' '
HASH_file=$(git rev-parse HEAD:file.txt) &&
git rev-parse HEAD:subdir/file.txt &&
git rev-parse :index-only.txt &&
(cd subdir &&
git rev-parse HEAD:subdir/file2.txt &&
test $HASH_file = $(git rev-parse HEAD:file.txt) &&
test $HASH_file = $(git rev-parse :file.txt) &&
test $HASH_file = $(git rev-parse :0:file.txt) )
'
test_expect_success 'correct relative file objects (0)' '
git rev-parse :file.txt >expected &&
git rev-parse :./file.txt >result &&
test_cmp expected result &&
git rev-parse :0:./file.txt >result &&
test_cmp expected result
'
test_expect_success 'correct relative file objects (1)' '
git rev-parse HEAD:file.txt >expected &&
git rev-parse HEAD:./file.txt >result &&
test_cmp expected result
'
test_expect_success 'correct relative file objects (2)' '
(
cd subdir &&
git rev-parse HEAD:../file.txt >result &&
test_cmp ../expected result
)
'
test_expect_success 'correct relative file objects (3)' '
(
cd subdir &&
git rev-parse HEAD:../subdir/../file.txt >result &&
test_cmp ../expected result
)
'
test_expect_success 'correct relative file objects (4)' '
git rev-parse HEAD:subdir/file.txt >expected &&
(
cd subdir &&
git rev-parse HEAD:./file.txt >result &&
test_cmp ../expected result
)
'
test_expect_success 'correct relative file objects (5)' '
git rev-parse :subdir/file.txt >expected &&
(
cd subdir &&
git rev-parse :./file.txt >result &&
test_cmp ../expected result &&
git rev-parse :0:./file.txt >result &&
test_cmp ../expected result
)
'
test_expect_success 'correct relative file objects (6)' '
git rev-parse :file.txt >expected &&
(
cd subdir &&
git rev-parse :../file.txt >result &&
test_cmp ../expected result &&
git rev-parse :0:../file.txt >result &&
test_cmp ../expected result
)
'
test_expect_success 'incorrect revision id' '
test_must_fail git rev-parse foobar:file.txt 2>error &&
test_i18ngrep "invalid object name .foobar." error &&
test_must_fail git rev-parse foobar 2>error &&
test_i18ngrep "unknown revision or path not in the working tree." error
'
test_expect_success 'incorrect file in sha1:path' '
test_must_fail git rev-parse HEAD:nothing.txt 2>error &&
test_i18ngrep "path .nothing.txt. does not exist in .HEAD." error &&
test_must_fail git rev-parse HEAD:index-only.txt 2>error &&
test_i18ngrep "path .index-only.txt. exists on disk, but not in .HEAD." error &&
(cd subdir &&
test_must_fail git rev-parse HEAD:file2.txt 2>error &&
test_did_you_mean HEAD subdir/ file2.txt exists )
'
test_expect_success 'incorrect file in :path and :N:path' '
test_must_fail git rev-parse :nothing.txt 2>error &&
test_i18ngrep "path .nothing.txt. does not exist (neither on disk nor in the index)" error &&
test_must_fail git rev-parse :1:nothing.txt 2>error &&
test_i18ngrep "path .nothing.txt. does not exist (neither on disk nor in the index)" error &&
test_must_fail git rev-parse :1:file.txt 2>error &&
test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
(cd subdir &&
test_must_fail git rev-parse :1:file.txt 2>error &&
test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
test_must_fail git rev-parse :file2.txt 2>error &&
test_did_you_mean ":0" subdir/ file2.txt "is in the index" &&
test_must_fail git rev-parse :2:file2.txt 2>error &&
test_did_you_mean :0 subdir/ file2.txt "is in the index") &&
test_must_fail git rev-parse :disk-only.txt 2>error &&
test_i18ngrep "path .disk-only.txt. exists on disk, but not in the index" error
'
test_expect_success 'invalid @{n} reference' '
test_must_fail git rev-parse master@{99999} >output 2>error &&
test_must_be_empty output &&
test_i18ngrep "log for [^ ]* only has [0-9][0-9]* entries" error &&
test_must_fail git rev-parse --verify master@{99999} >output 2>error &&
test_must_be_empty output &&
test_i18ngrep "log for [^ ]* only has [0-9][0-9]* entries" error
'
test_expect_success 'relative path not found' '
(
cd subdir &&
test_must_fail git rev-parse HEAD:./nonexistent.txt 2>error &&
test_i18ngrep subdir/nonexistent.txt error
)
'
test_expect_success 'relative path outside worktree' '
test_must_fail git rev-parse HEAD:../file.txt >output 2>error &&
test_must_be_empty output &&
test_i18ngrep "outside repository" error
'
test_expect_success 'relative path when cwd is outside worktree' '
test_must_fail git --git-dir=.git --work-tree=subdir rev-parse HEAD:./file.txt >output 2>error &&
test_must_be_empty output &&
test_i18ngrep "relative path syntax can.t be used outside working tree" error
'
test_expect_success '<commit>:file correctly diagnosed after a pathname' '
test_must_fail git rev-parse file.txt HEAD:file.txt 1>actual 2>error &&
test_i18ngrep ! "exists on disk" error &&
test_i18ngrep "no such path in the working tree" error &&
cat >expect <<-\EOF &&
file.txt
HEAD:file.txt
EOF
test_cmp expect actual
'
test_expect_success 'dotdot is not an empty set' '
( H=$(git rev-parse HEAD) && echo $H && echo ^$H ) >expect &&
git rev-parse HEAD.. >actual &&
test_cmp expect actual &&
git rev-parse ..HEAD >actual &&
test_cmp expect actual &&
echo .. >expect &&
git rev-parse .. >actual &&
test_cmp expect actual
'
test_expect_success 'dotdot does not peel endpoints' '
git tag -a -m "annote" annotated HEAD &&
A=$(git rev-parse annotated) &&
H=$(git rev-parse annotated^0) &&
{
echo $A && echo ^$A
} >expect-with-two-dots &&
{
echo $A && echo $A && echo ^$H
} >expect-with-merge-base &&
git rev-parse annotated..annotated >actual-with-two-dots &&
test_cmp expect-with-two-dots actual-with-two-dots &&
git rev-parse annotated...annotated >actual-with-merge-base &&
test_cmp expect-with-merge-base actual-with-merge-base
'
test_expect_success 'arg before dashdash must be a revision (missing)' '
test_must_fail git rev-parse foobar -- 2>stderr &&
test_i18ngrep "bad revision" stderr
'
test_expect_success 'arg before dashdash must be a revision (file)' '
>foobar &&
test_must_fail git rev-parse foobar -- 2>stderr &&
test_i18ngrep "bad revision" stderr
'
test_expect_success 'arg before dashdash must be a revision (ambiguous)' '
>foobar &&
git update-ref refs/heads/foobar HEAD &&
{
# we do not want to use rev-parse here, because
# we are testing it
git show-ref -s refs/heads/foobar &&
printf "%s\n" --
} >expect &&
git rev-parse foobar -- >actual &&
test_cmp expect actual
'
test_expect_success 'reject Nth parent if N is too high' '
test_must_fail git rev-parse HEAD^100000000000000000000000000000000
'
test_expect_success 'reject Nth ancestor if N is too high' '
test_must_fail git rev-parse HEAD~100000000000000000000000000000000
'
test_expect_success 'pathspecs with wildcards are not ambiguous' '
echo "*.c" >expect &&
git rev-parse "*.c" >actual &&
test_cmp expect actual
'
test_expect_success 'backslash does not trigger wildcard rule' '
test_must_fail git rev-parse "foo\\bar"
'
test_expect_success 'escaped char does not trigger wildcard rule' '
test_must_fail git rev-parse "foo\\*bar"
'
test_done