From dbbb8c50f59005c0c1f2fadbf3972ce89e3f9e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Fri, 3 Jun 2022 13:15:03 +0200 Subject: [PATCH 1/7] t0008: don't rely on default ".git/info/exclude" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change a test added in 368aa52952d (add git-check-ignore sub-command, 2013-01-06) to clobber .git/info/exclude rather than append to it. These tests would break if the "templates/info--exclude" file added in d3af621b147 (Redo the templates generation and installation., 2005-08-06) wasn't exactly 6 lines (of only comments). Let's instead clobber the default .git/info/excludes file, and test only our own expected content. This is not strictly needed for anything in this series, but is a good cleanup while we're at it. As discussed in the preceding commit a lot of things depend on the "info" directory being created, but this was the only test that relied on the specific content in the "templates/info--exclude" file. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t0008-ignores.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index 5575dade8e..c3655a0c53 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -225,7 +225,7 @@ test_expect_success 'setup' ' !globaltwo globalthree EOF - cat <<-\EOF >>.git/info/exclude + cat <<-\EOF >.git/info/exclude per-repo EOF ' @@ -543,9 +543,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 +566,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" From e942292a3e099f03ae23efd3fd9f09f8b512cadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Fri, 3 Jun 2022 13:15:04 +0200 Subject: [PATCH 2/7] tests: don't depend on template-created .git/branches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As noted in c8a58ac5a52 (Revert "Don't create the $GIT_DIR/branches directory on init", 2009-10-31) there was an attempt long ago in 0cc5691a8b0 (Don't create the $GIT_DIR/branches directory on init, 2009-10-30) to get rid of the legacy "branches" directory. We should probably get rid of its creation by removing the "templates/branches--" file. But whatever our default behavior, our tests should be tightened up to explicitly create the .git/branches directory if they rely on our default templates, to make the dependency on those templates clear. So let's amend the two tests that would fail if .git/branches wasn't created. To do this introduce a new "TEST_CREATE_REPO_NO_TEMPLATE" variable, which we'll set before sourcing test-lib.sh, and change the "git clone" and "git init" commands in the tests themselves to explicitly pass "--template=". This way they won't get a .git/branches in either their top-level .git, or in the ones they create. We can then amend the tests that rely on the ".git/branches" directory existing to create it explicitly, and to remove it after its creation. This new "TEST_CREATE_REPO_NO_TEMPLATE" variable is a less heavy-handed version of the "NO_SET_GIT_TEMPLATE_DIR" variable. See a94d305bf80 (t/t0001-init.sh: add test for 'init with init.templatedir set', 2010-02-26) for its implementation. Unlike "TEST_CREATE_REPO_NO_TEMPLATE", this new "TEST_CREATE_REPO_NO_TEMPLATE" variable is narrowly scoped to what the "git init" in test-lib.sh does, as opposed to the global effect of "NO_SET_GIT_TEMPLATE_DIR" and the setting of "GIT_TEMPLATE_DIR" in wrap-for-bin.sh. I experimented with adding a new "GIT_WRAP_FOR_BIN_VIA_TEST_LIB" variable set in test-lib.sh, which would cause wrap-for-bin.sh to not set GIT_TEMPLATE_DIR, GITPERLLIB etc, as we set those in test-lib.sh. I think that's a viable approach, but it would interact e.g. with the appending feature of GITPERLLIB added in 8bade1e12e2 (wrap-for-bin: make bin-wrappers chainable, 2013-07-04). Doing so would allow us to convert the tests in t0001-init.sh that now use "NO_SET_GIT_TEMPLATE_DIR" to simply unset "GIT_TEMPLATE_DIR" in a sub-shell before invoking "git init" or "git clone". I think that approach is worth pursuing, but let's table it for now. Some future wrap-for-bin.sh refactoring can try to address it. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t5505-remote.sh | 6 ++++-- t/t5516-fetch-push.sh | 16 ++++++++++++++-- t/test-lib.sh | 4 +++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index c90cf47acd..af4e0a1e72 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -923,11 +923,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 && @@ -938,10 +939,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 && diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 4dfb080433..5d3054eeb8 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -17,6 +17,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) @@ -25,7 +26,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 } @@ -77,7 +79,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 () { @@ -916,6 +918,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 && @@ -929,6 +932,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 && @@ -943,7 +947,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 && @@ -955,7 +963,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 && diff --git a/t/test-lib.sh b/t/test-lib.sh index 531cef097d..eb6d14fea7 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -1528,7 +1528,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" From 93e02b6e1e845f5178017c0bac4f18077b331499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Fri, 3 Jun 2022 13:15:05 +0200 Subject: [PATCH 3/7] tests: don't assume a .git/info for .git/info/grafts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change those tests that assumed that a .git/info directory would be created for them when writing .git/info/grafts to explicitly create the directory. Do this using the new "TEST_CREATE_REPO_NO_TEMPLATE" facility, and use "mkdir" instead of "mkdir -p" to assert that we don't have the .git/info already. An exception to this is the "with grafts" test in "t6001-rev-list-graft.sh". There we're modifying our ".git" state in a for-loop, in lieu of refactoring that more extensively let's use "mkdir -p" there. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/annotate-tests.sh | 3 ++- t/t2400-worktree-add.sh | 4 ++++ t/t5318-commit-graph.sh | 3 ++- t/t6001-rev-list-graft.sh | 1 + t/t6101-rev-parse-parents.sh | 2 ++ t/t8001-annotate.sh | 1 + t/t8002-blame.sh | 1 + t/t8012-blame-colors.sh | 1 + 8 files changed, 14 insertions(+), 2 deletions(-) diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index 09e86f9ba0..71f391fcaf 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -149,7 +149,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 @@ -164,6 +164,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 ' diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index 2f564d533d..f3242fef6b 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -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 $* diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index fbf0d64578..be0b5641ff 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -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 && diff --git a/t/t6001-rev-list-graft.sh b/t/t6001-rev-list-graft.sh index 7294147334..16635ecc33 100755 --- a/t/t6001-rev-list-graft.sh +++ b/t/t6001-rev-list-graft.sh @@ -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 " diff --git a/t/t6101-rev-parse-parents.sh b/t/t6101-rev-parse-parents.sh index c571fa5179..5f55ab98d3 100755 --- a/t/t6101-rev-parse-parents.sh +++ b/t/t6101-rev-parse-parents.sh @@ -8,6 +8,7 @@ test_description='Test git rev-parse with different parent options' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh test_cmp_rev_output () { @@ -25,6 +26,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 diff --git a/t/t8001-annotate.sh b/t/t8001-annotate.sh index a536a621b2..d7167f5539 100755 --- a/t/t8001-annotate.sh +++ b/t/t8001-annotate.sh @@ -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' diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh index ee4fdd8f18..0147de304b 100755 --- a/t/t8002-blame.sh +++ b/t/t8002-blame.sh @@ -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' diff --git a/t/t8012-blame-colors.sh b/t/t8012-blame-colors.sh index 90c75dbb28..c3a5f6d01f 100755 --- a/t/t8012-blame-colors.sh +++ b/t/t8012-blame-colors.sh @@ -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' From 8da0b02d9911d483d34ad8994c879953eebd345c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Fri, 3 Jun 2022 13:15:06 +0200 Subject: [PATCH 4/7] tests: don't assume a .git/info for .git/info/attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change those tests that assumed that a .git/info directory would be created for them when writing .git/info/attributes to explicitly create the directory by setting "TEST_CREATE_REPO_NO_TEMPLATE=1" before sourcing test-lib.sh, and using the "--template=" argument to "git clone". The change here in here in t7814-grep-recurse-submodules.sh would continue "succeeding" with only the "TEST_CREATE_REPO_NO_TEMPLATE=1" part of this change. That's because those tests use "test_expect_failure", so they'd "pass" without this change, as "test_expect_failure" by design isn't discerning about what failure conditions it'll accept. But as we're fixing these sorts of issues across the test suite let's fix this one too. This issue was spotted with a local merge with another topic of mine[1], which introduces a stricter alternative to "test_expect_failure". 1. https://lore.kernel.org/git/cover-0.7-00000000000-20220318T002951Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 5 ++++- t/t0028-working-tree-encoding.sh | 2 ++ t/t5000-tar-tree.sh | 5 ++++- t/t5001-archive-attr.sh | 5 ++++- t/t5002-archive-attr-pattern.sh | 5 ++++- t/t5003-archive-zip.sh | 5 ++++- t/t7814-grep-recurse-submodules.sh | 8 ++++++-- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 143f100517..f7ee2f2ff0 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -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 ' diff --git a/t/t0028-working-tree-encoding.sh b/t/t0028-working-tree-encoding.sh index 82905a2156..7140960e1a 100755 --- a/t/t0028-working-tree-encoding.sh +++ b/t/t0028-working-tree-encoding.sh @@ -5,6 +5,7 @@ test_description='working-tree-encoding conversion via gitattributes' 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-encoding.sh" @@ -69,6 +70,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 && diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 7f8d2ab0a7..de192b52c4 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -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 ' diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh index 712ae52299..2f6eef5e37 100755 --- a/t/t5001-archive-attr.sh +++ b/t/t5001-archive-attr.sh @@ -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 ' diff --git a/t/t5002-archive-attr-pattern.sh b/t/t5002-archive-attr-pattern.sh index a66b5ba27e..78ab75f1bc 100755 --- a/t/t5002-archive-attr-pattern.sh +++ b/t/t5002-archive-attr-pattern.sh @@ -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 ' diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh index d726964307..a7bbfcb7f7 100755 --- a/t/t5003-archive-zip.sh +++ b/t/t5003-archive-zip.sh @@ -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. diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh index a4476dc492..3ad80526c4 100755 --- a/t/t7814-grep-recurse-submodules.sh +++ b/t/t7814-grep-recurse-submodules.sh @@ -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" && From ce5369e3ef0078458a0608be9ddeb2b276e61b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Fri, 3 Jun 2022 13:15:07 +0200 Subject: [PATCH 5/7] tests: don't assume a .git/info for .git/info/refs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change those tests that assumed that a .git/info directory would be created for them when writing .git/info/refs to explicitly create the directory by using the "--template=" argument to "git init". Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t1301-shared-repo.sh | 3 ++- t/t5550-http-fetch-dumb.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh index 84bf1970d8..93a2f91f8a 100755 --- a/t/t1301-shared-repo.sh +++ b/t/t1301-shared-repo.sh @@ -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)" && diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh index f0d9cd584d..3ca621f33b 100755 --- a/t/t5550-http-fetch-dumb.sh +++ b/t/t5550-http-fetch-dumb.sh @@ -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" ' From 1d758728fb26f574169b7f0b420e59af1d0c3c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Fri, 3 Jun 2022 13:15:08 +0200 Subject: [PATCH 6/7] tests: don't assume a .git/info for .git/info/exclude MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change those tests that assumed that a .git/info directory would be created for them when writing .git/info/exclude to explicitly create the directory by setting "TEST_CREATE_REPO_NO_TEMPLATE=1" before sourcing test-lib.sh, and using the "--template=" argument to "git clone" and "git init". In the case of ".git/modules/sub1/info" we deviate from the established pattern in this and preceding commits of passing a "--template=" and doing a "mkdir .git/info". In that case "git checkout" will run the "submodule--helper clone", and both e.g. "git submodule update --init" and "git checkout" do not have a way to pass down options to the eventual "git init" or "git clone". Let's instead assume that the submodule was populated with our default templates, remove them, and then run the "mkdir". Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/lib-submodule-update.sh | 7 +++++-- t/t0008-ignores.sh | 2 ++ t/t3426-rebase-submodule.sh | 1 + t/t7063-status-untracked-cache.sh | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh index f7c7df0ca4..03e0abbdb8 100644 --- a/t/lib-submodule-update.sh +++ b/t/lib-submodule-update.sh @@ -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 && diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index c3655a0c53..c70d11bc91 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -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,6 +226,7 @@ test_expect_success 'setup' ' !globaltwo globalthree EOF + mkdir .git/info && cat <<-\EOF >.git/info/exclude per-repo EOF diff --git a/t/t3426-rebase-submodule.sh b/t/t3426-rebase-submodule.sh index 0ad3a07bf4..7a9f1127a4 100755 --- a/t/t3426-rebase-submodule.sh +++ b/t/t3426-rebase-submodule.sh @@ -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" diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh index ca90ee805e..92c2730f31 100755 --- a/t/t7063-status-untracked-cache.sh +++ b/t/t7063-status-untracked-cache.sh @@ -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 From ead74601c6ed7171e9e736e329b45c12d90153e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Fri, 3 Jun 2022 13:15:09 +0200 Subject: [PATCH 7/7] tests: don't assume a .git/info for .git/info/sparse-checkout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change those tests that assumed that a .git/info directory would be created for them when writing .git/info/sparse-checkout to explicitly create the directory by setting "TEST_CREATE_REPO_NO_TEMPLATE=1" before sourcing test-lib.sh, and using the "--template=" argument to "git clone". Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t1011-read-tree-sparse-checkout.sh | 2 ++ t/t1090-sparse-checkout-scope.sh | 5 ++++- t/t2018-checkout-branch.sh | 4 +++- t/t3507-cherry-pick-conflict.sh | 2 ++ t/t6435-merge-sparse.sh | 2 ++ t/t7418-submodule-sparse-gitmodules.sh | 3 ++- 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/t/t1011-read-tree-sparse-checkout.sh b/t/t1011-read-tree-sparse-checkout.sh index dd957be1b7..c763fa7afa 100755 --- a/t/t1011-read-tree-sparse-checkout.sh +++ b/t/t1011-read-tree-sparse-checkout.sh @@ -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 && diff --git a/t/t1090-sparse-checkout-scope.sh b/t/t1090-sparse-checkout-scope.sh index d1833c0f31..3a14218b24 100755 --- a/t/t1090-sparse-checkout-scope.sh +++ b/t/t1090-sparse-checkout-scope.sh @@ -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 && diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index 52e51b0726..771c3c3c50 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -2,6 +2,7 @@ test_description='checkout' +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh # Arguments: [!] [] @@ -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 && diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index 979e843c65..f32799e046 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -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 && diff --git a/t/t6435-merge-sparse.sh b/t/t6435-merge-sparse.sh index 74562e1235..fde4aa3cd1 100755 --- a/t/t6435-merge-sparse.sh +++ b/t/t6435-merge-sparse.sh @@ -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 diff --git a/t/t7418-submodule-sparse-gitmodules.sh b/t/t7418-submodule-sparse-gitmodules.sh index f87e524d6d..57d7ab3ece 100755 --- a/t/t7418-submodule-sparse-gitmodules.sh +++ b/t/t7418-submodule-sparse-gitmodules.sh @@ -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