Merge branch 'ab/test-without-templates'

Tweak tests so that they still work when the "git init" template
did not create .git/info directory.

* ab/test-without-templates:
  tests: don't assume a .git/info for .git/info/sparse-checkout
  tests: don't assume a .git/info for .git/info/exclude
  tests: don't assume a .git/info for .git/info/refs
  tests: don't assume a .git/info for .git/info/attributes
  tests: don't assume a .git/info for .git/info/grafts
  tests: don't depend on template-created .git/branches
  t0008: don't rely on default ".git/info/exclude"
This commit is contained in:
Junio C Hamano 2022-07-18 13:31:55 -07:00
commit 3d3874d537
30 changed files with 97 additions and 27 deletions

View File

@ -153,7 +153,7 @@ test_expect_success 'blame evil merge' '
test_expect_success 'blame huge graft' '
test_when_finished "git checkout branch2" &&
test_when_finished "rm -f .git/info/grafts" &&
test_when_finished "rm -rf .git/info" &&
graft= &&
for i in 0 1 2
do
@ -168,6 +168,7 @@ test_expect_success 'blame huge graft' '
graft="$graft$commit " || return 1
done
done &&
mkdir .git/info &&
printf "%s " $graft >.git/info/grafts &&
check_count -h 00 01 1 10 1
'

View File

@ -207,7 +207,7 @@ prolog () {
# should be updated to an existing commit.
reset_work_tree_to () {
rm -rf submodule_update &&
git clone submodule_update_repo submodule_update &&
git clone --template= submodule_update_repo submodule_update &&
(
cd submodule_update &&
rm -rf sub1 &&
@ -902,13 +902,14 @@ test_submodule_switch_recursing_with_args () {
'
# ... but an ignored file is fine.
test_expect_$RESULTOI "$command: added submodule removes an untracked ignored file" '
test_when_finished "rm submodule_update/.git/info/exclude" &&
test_when_finished "rm -rf submodule_update/.git/info" &&
prolog &&
reset_work_tree_to_interested no_submodule &&
(
cd submodule_update &&
git branch -t add_sub1 origin/add_sub1 &&
: >sub1 &&
mkdir .git/info &&
echo sub1 >.git/info/exclude &&
$command add_sub1 &&
test_superproject_content origin/add_sub1 &&
@ -951,7 +952,9 @@ test_submodule_switch_recursing_with_args () {
reset_work_tree_to_interested add_sub1 &&
(
cd submodule_update &&
rm -rf .git/modules/sub1/info &&
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
mkdir .git/modules/sub1/info &&
echo ignored >.git/modules/sub1/info/exclude &&
: >sub1/ignored &&
$command replace_sub1_with_file &&

View File

@ -3,6 +3,7 @@
test_description=gitattributes
TEST_PASSES_SANITIZE_LEAK=true
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
attr_check_basic () {
@ -284,7 +285,7 @@ test_expect_success 'using --git-dir and --work-tree' '
'
test_expect_success 'setup bare' '
git clone --bare . bare.git
git clone --template= --bare . bare.git
'
test_expect_success 'bare repository: check that .gitattribute is ignored' '
@ -315,6 +316,7 @@ test_expect_success 'bare repository: check that --cached honors index' '
test_expect_success 'bare repository: test info/attributes' '
(
cd bare.git &&
mkdir info &&
(
echo "f test=f" &&
echo "a/i test=a/i"
@ -360,6 +362,7 @@ test_expect_success SYMLINKS 'symlinks respected in core.attributesFile' '
test_expect_success SYMLINKS 'symlinks respected in info/attributes' '
test_when_finished "rm .git/info/attributes" &&
mkdir .git/info &&
ln -s ../../attr .git/info/attributes &&
attr_check file set
'

View File

@ -3,6 +3,7 @@
test_description=check-ignore
TEST_PASSES_SANITIZE_LEAK=true
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
init_vars () {
@ -225,7 +226,8 @@ test_expect_success 'setup' '
!globaltwo
globalthree
EOF
cat <<-\EOF >>.git/info/exclude
mkdir .git/info &&
cat <<-\EOF >.git/info/exclude
per-repo
EOF
'
@ -543,9 +545,9 @@ test_expect_success_multi 'submodule from subdirectory' '' '
test_expect_success 'global ignore not yet enabled' '
expect_from_stdin <<-\EOF &&
.git/info/exclude:7:per-repo per-repo
.git/info/exclude:1:per-repo per-repo
a/.gitignore:2:*three a/globalthree
.git/info/exclude:7:per-repo a/per-repo
.git/info/exclude:1:per-repo a/per-repo
EOF
test_check_ignore "-v globalone per-repo a/globalthree a/per-repo not-ignored a/globaltwo"
'
@ -566,10 +568,10 @@ test_expect_success 'global ignore with -v' '
enable_global_excludes &&
expect_from_stdin <<-EOF &&
$global_excludes:1:globalone globalone
.git/info/exclude:7:per-repo per-repo
.git/info/exclude:1:per-repo per-repo
$global_excludes:3:globalthree globalthree
a/.gitignore:2:*three a/globalthree
.git/info/exclude:7:per-repo a/per-repo
.git/info/exclude:1:per-repo a/per-repo
$global_excludes:2:!globaltwo globaltwo
EOF
test_check_ignore "-v globalone per-repo globalthree a/globalthree a/per-repo not-ignored globaltwo"

View File

@ -6,6 +6,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
. "$TEST_DIRECTORY/lib-encoding.sh"
@ -70,6 +71,7 @@ test_expect_success 'check $GIT_DIR/info/attributes support' '
test_when_finished "rm -f test.utf32.git" &&
test_when_finished "git reset --hard HEAD" &&
mkdir .git/info &&
echo "*.utf32 text working-tree-encoding=utf-32" >.git/info/attributes &&
git add test.utf32 &&

View File

@ -11,6 +11,7 @@ test_description='sparse checkout tests
A init.t
'
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-read-tree.sh
@ -53,6 +54,7 @@ test_expect_success 'read-tree without .git/info/sparse-checkout' '
'
test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
mkdir .git/info &&
echo >.git/info/sparse-checkout &&
read_tree_u_must_succeed -m -u HEAD &&
git ls-files -t >result &&

View File

@ -5,6 +5,7 @@ test_description='sparse checkout scope tests'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
test_expect_success 'setup' '
@ -25,6 +26,7 @@ test_expect_success 'create feature branch' '
test_expect_success 'perform sparse checkout of main' '
git config --local --bool core.sparsecheckout true &&
mkdir .git/info &&
echo "!/*" >.git/info/sparse-checkout &&
echo "/a" >>.git/info/sparse-checkout &&
echo "/c" >>.git/info/sparse-checkout &&
@ -73,7 +75,7 @@ test_expect_success 'skip-worktree on files outside sparse patterns' '
test_expect_success 'in partial clone, sparse checkout only fetches needed blobs' '
test_create_repo server &&
git clone "file://$(pwd)/server" client &&
git clone --template= "file://$(pwd)/server" client &&
test_config -C server uploadpack.allowfilter 1 &&
test_config -C server uploadpack.allowanysha1inwant 1 &&
@ -85,6 +87,7 @@ test_expect_success 'in partial clone, sparse checkout only fetches needed blobs
git -C server commit -m message &&
test_config -C client core.sparsecheckout 1 &&
mkdir client/.git/info &&
echo "!/*" >client/.git/info/sparse-checkout &&
echo "/a" >>client/.git/info/sparse-checkout &&
git -C client fetch --filter=blob:none origin &&

View File

@ -48,7 +48,7 @@ done
test_expect_success 'shared=all' '
mkdir sub &&
cd sub &&
git init --shared=all &&
git init --template= --shared=all &&
test 2 = $(git config core.sharedrepository)
'
@ -57,6 +57,7 @@ test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository'
git add a1 &&
test_tick &&
git commit -m a1 &&
mkdir .git/info &&
umask 0277 &&
git update-server-info &&
actual="$(ls -l .git/info/refs)" &&

View File

@ -2,6 +2,7 @@
test_description='checkout'
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
# Arguments: [!] <branch> <oid> [<checkout options>]
@ -257,11 +258,12 @@ test_expect_success 'checkout -b to a new branch preserves mergeable changes des
git checkout branch1-scratch &&
test_might_fail git branch -D branch3 &&
git config core.sparseCheckout false &&
rm .git/info/sparse-checkout" &&
rm -rf .git/info" &&
test_commit file2 &&
echo stuff >>file1 &&
mkdir .git/info &&
echo file2 >.git/info/sparse-checkout &&
git config core.sparseCheckout true &&

View File

@ -5,6 +5,7 @@ test_description='test git worktree add'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-rebase.sh
@ -229,6 +230,7 @@ test_expect_success 'checkout with grafts' '
SHA1=$(git rev-parse HEAD) &&
test_commit def &&
test_commit xyz &&
mkdir .git/info &&
echo "$(git rev-parse HEAD) $SHA1" >.git/info/grafts &&
cat >expected <<-\EOF &&
xyz
@ -559,6 +561,8 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' '
'
post_checkout_hook () {
test_when_finished "rm -rf .git/hooks" &&
mkdir .git/hooks &&
test_hook -C "$1" post-checkout <<-\EOF
{
echo $*

View File

@ -35,6 +35,7 @@ git_rebase_interactive () {
ls -1pR * >>actual &&
test_cmp expect actual &&
set_fake_editor &&
mkdir .git/info &&
echo "fake-editor.sh" >.git/info/exclude &&
may_only_be_test_must_fail "$2" &&
$2 git rebase -i "$1"

View File

@ -12,6 +12,7 @@ test_description='test cherry-pick and revert with conflicts
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
pristine_detach () {
@ -558,6 +559,7 @@ test_expect_success 'cherry-pick preserves sparse-checkout' '
echo \"/*\" >.git/info/sparse-checkout
git read-tree --reset -u HEAD
rm .git/info/sparse-checkout" &&
mkdir .git/info &&
echo /unrelated >.git/info/sparse-checkout &&
git read-tree --reset -u HEAD &&
test_must_fail git cherry-pick -Xours picked>actual &&

View File

@ -24,6 +24,7 @@ commit id embedding:
'
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
SUBSTFORMAT=%H%n
@ -143,6 +144,7 @@ test_expect_success 'populate workdir' '
test_expect_success \
'add ignored file' \
'echo ignore me >a/ignored &&
mkdir .git/info &&
echo ignored export-ignore >.git/info/attributes'
test_expect_success 'add files to repository' '
@ -157,7 +159,8 @@ test_expect_success 'setup export-subst' '
'
test_expect_success 'create bare clone' '
git clone --bare . bare.git &&
git clone --template= --bare . bare.git &&
mkdir bare.git/info &&
cp .git/info/attributes bare.git/info/attributes
'

View File

@ -2,6 +2,7 @@
test_description='git archive attribute tests'
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
SUBSTFORMAT='%H (%h)%n'
@ -20,6 +21,7 @@ extract_tar_to_dir () {
test_expect_success 'setup' '
echo ignored >ignored &&
mkdir .git/info &&
echo ignored export-ignore >>.git/info/attributes &&
git add ignored &&
@ -46,7 +48,8 @@ test_expect_success 'setup' '
git commit -m. &&
git clone --bare . bare &&
git clone --template= --bare . bare &&
mkdir bare/info &&
cp .git/info/attributes bare/info/attributes
'

View File

@ -3,6 +3,7 @@
test_description='git archive attribute pattern tests'
TEST_PASSES_SANITIZE_LEAK=true
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
test_expect_exists() {
@ -15,6 +16,7 @@ test_expect_missing() {
test_expect_success 'setup' '
echo ignored >ignored &&
mkdir .git/info &&
echo ignored export-ignore >>.git/info/attributes &&
git add ignored &&
@ -54,7 +56,8 @@ test_expect_success 'setup' '
git commit -m. &&
git clone --bare . bare &&
git clone --template= --bare . bare &&
mkdir bare/info &&
cp .git/info/attributes bare/info/attributes
'

View File

@ -2,6 +2,7 @@
test_description='git archive --format=zip test'
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
SUBSTFORMAT=%H%n
@ -121,6 +122,7 @@ test_expect_success 'prepare file list' '
test_expect_success \
'add ignored file' \
'echo ignore me >a/ignored &&
mkdir .git/info &&
echo ignored export-ignore >.git/info/attributes'
test_expect_success 'add files to repository' '
@ -139,7 +141,8 @@ test_expect_success 'setup export-subst and diff attributes' '
'
test_expect_success 'create bare clone' '
git clone --bare . bare.git &&
git clone --template= --bare . bare.git &&
mkdir bare.git/info &&
cp .git/info/attributes bare.git/info/attributes &&
# Recreate our changes to .git/config rather than just copying it, as
# we do not want to clobber core.bare or other settings.

View File

@ -361,13 +361,14 @@ test_expect_success 'replace-objects invalidates commit-graph' '
test_expect_success 'commit grafts invalidate commit-graph' '
cd "$TRASH_DIRECTORY" &&
test_when_finished rm -rf graft &&
git clone full graft &&
git clone --template= full graft &&
(
cd graft &&
git commit-graph write --reachable &&
test_path_is_file .git/objects/info/commit-graph &&
H1=$(git rev-parse --verify HEAD~1) &&
H3=$(git rev-parse --verify HEAD~3) &&
mkdir .git/info &&
echo "$H1 $H3" >.git/info/grafts &&
git -c core.commitGraph=false log >expect &&
git -c core.commitGraph=true log >actual &&

View File

@ -1003,11 +1003,12 @@ test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
'
test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
git clone one six &&
git clone --template= one six &&
origin_url=$(pwd)/one &&
(
cd six &&
git remote rm origin &&
mkdir .git/branches &&
echo "$origin_url#main" >.git/branches/origin &&
git remote rename origin origin &&
test_path_is_missing .git/branches/origin &&
@ -1018,10 +1019,11 @@ test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
'
test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
git clone one seven &&
git clone --template= one seven &&
(
cd seven &&
git remote rm origin &&
mkdir .git/branches &&
echo "quux#foom" > .git/branches/origin &&
git remote rename origin origin &&
test_path_is_missing .git/branches/origin &&

View File

@ -18,6 +18,7 @@ This test checks the following functionality:
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
D=$(pwd)
@ -26,7 +27,8 @@ mk_empty () {
repo_name="$1"
test_when_finished "rm -rf \"$repo_name\"" &&
test_path_is_missing "$repo_name" &&
git init "$repo_name" &&
git init --template= "$repo_name" &&
mkdir "$repo_name"/.git/hooks &&
git -C "$repo_name" config receive.denyCurrentBranch warn
}
@ -78,7 +80,7 @@ mk_test_with_hooks() {
mk_child() {
test_when_finished "rm -rf \"$2\"" &&
git clone "$1" "$2"
git clone --template= "$1" "$2"
}
check_push_result () {
@ -937,6 +939,7 @@ test_expect_success 'fetch with branches' '
mk_empty testrepo &&
git branch second $the_first_commit &&
git checkout second &&
mkdir testrepo/.git/branches &&
echo ".." > testrepo/.git/branches/branch1 &&
(
cd testrepo &&
@ -950,6 +953,7 @@ test_expect_success 'fetch with branches' '
test_expect_success 'fetch with branches containing #' '
mk_empty testrepo &&
mkdir testrepo/.git/branches &&
echo "..#second" > testrepo/.git/branches/branch2 &&
(
cd testrepo &&
@ -964,7 +968,11 @@ test_expect_success 'fetch with branches containing #' '
test_expect_success 'push with branches' '
mk_empty testrepo &&
git checkout second &&
test_when_finished "rm -rf .git/branches" &&
mkdir .git/branches &&
echo "testrepo" > .git/branches/branch1 &&
git push branch1 &&
(
cd testrepo &&
@ -976,7 +984,11 @@ test_expect_success 'push with branches' '
test_expect_success 'push with branches containing #' '
mk_empty testrepo &&
test_when_finished "rm -rf .git/branches" &&
mkdir .git/branches &&
echo "testrepo#branch3" > .git/branches/branch2 &&
git push branch2 &&
(
cd testrepo &&

View File

@ -422,7 +422,8 @@ test_expect_success 'set up evil alternates scheme' '
sha1=$(git -C "$victim" rev-parse HEAD) &&
evil=$HTTPD_DOCUMENT_ROOT_PATH/evil.git &&
git init --bare "$evil" &&
git init --template= --bare "$evil" &&
mkdir "$evil/info" &&
# do this by hand to avoid object existence check
printf "%s\\t%s\\n" $sha1 refs/heads/main >"$evil/info/refs"
'

View File

@ -99,6 +99,7 @@ do
"
test_expect_success 'with grafts' "
mkdir -p .git/info &&
echo '$B0 $A2' >.git/info/grafts &&
check $type $B2 -- $B2 $B1 $B0 $A2 $A1 $A0
"

View File

@ -9,6 +9,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
test_cmp_rev_output () {
@ -26,6 +27,7 @@ test_expect_success 'setup' '
git merge -m next --allow-unrelated-histories start2 &&
test_commit final &&
mkdir .git/info &&
test_seq 40 |
while read i
do

View File

@ -2,6 +2,7 @@
test_description='merge with sparse files'
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
# test_file $filename $content
@ -26,6 +27,7 @@ test_expect_success 'setup' '
git rm modify_delete &&
test_commit_this ours &&
git config core.sparseCheckout true &&
mkdir .git/info &&
echo "/checked-out" >.git/info/sparse-checkout &&
git reset --hard &&
test_must_fail git merge theirs

View File

@ -86,7 +86,7 @@ test_expect_success 'core.untrackedCache is unset' '
'
test_expect_success 'setup' '
git init worktree &&
git init --template= worktree &&
cd worktree &&
mkdir done dtwo dthree &&
touch one two three done/one dtwo/two dthree/three &&
@ -94,6 +94,7 @@ test_expect_success 'setup' '
test-tool chmtime =-300 done dtwo dthree &&
test-tool chmtime =-300 . &&
git add one two done/one &&
mkdir .git/info &&
: >.git/info/exclude &&
git update-index --untracked-cache &&
test_oid_cache <<-EOF

View File

@ -31,8 +31,9 @@ test_expect_success 'sparse checkout setup which hides .gitmodules' '
test_tick &&
git commit -m "Add submodule"
) &&
git clone upstream super &&
git clone --template= upstream super &&
(cd super &&
mkdir .git/info &&
cat >.git/info/sparse-checkout <<-\EOF &&
/*
!/.gitmodules

View File

@ -6,6 +6,7 @@ This test verifies the recurse-submodules feature correctly greps across
submodules.
'
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
@ -471,8 +472,10 @@ test_expect_failure 'grep --textconv: superproject .gitattributes (from index) d
test_expect_failure 'grep --textconv: superproject .git/info/attributes does not affect submodules' '
reset_and_clean &&
test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" &&
super_attr="$(git rev-parse --git-path info/attributes)" &&
super_info="$(git rev-parse --git-path info)" &&
super_attr="$super_info/attributes" &&
test_when_finished "rm -f \"$super_attr\"" &&
mkdir "$super_info" &&
echo "a diff=d2x" >"$super_attr" &&
cat >expect <<-\EOF &&
@ -516,7 +519,8 @@ test_expect_failure 'grep --textconv correctly reads submodule .git/info/attribu
reset_and_clean &&
test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" &&
submodule_attr="$(git -C submodule rev-parse --path-format=absolute --git-path info/attributes)" &&
submodule_info="$(git -C submodule rev-parse --path-format=absolute --git-path info)" &&
submodule_attr="$submodule_info/attributes" &&
test_when_finished "rm -f \"$submodule_attr\"" &&
echo "a diff=d2x" >"$submodule_attr" &&

View File

@ -4,6 +4,7 @@ test_description='git annotate'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
PROG='git annotate'

View File

@ -4,6 +4,7 @@ test_description='git blame'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
PROG='git blame -c'

View File

@ -4,6 +4,7 @@ test_description='colored git blame'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
PROG='git blame -c'

View File

@ -1456,7 +1456,9 @@ remove_trash_directory "$TRASH_DIRECTORY" || {
remove_trash=t
if test -z "$TEST_NO_CREATE_REPO"
then
git init "$TRASH_DIRECTORY" >&3 2>&4 ||
git init \
${TEST_CREATE_REPO_NO_TEMPLATE:+--template=} \
"$TRASH_DIRECTORY" >&3 2>&4 ||
error "cannot run git init"
else
mkdir -p "$TRASH_DIRECTORY"