From 91c5a5e000f765d8da351a094e8952317fe4e5dc Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 29 Jan 2024 12:07:17 +0100 Subject: t1300: make tests more robust with non-default ref backends The t1300 test suite exercises the git-config(1) tool. To do so, the test overwrites ".git/config" to contain custom contents in several places with code like the following: ``` cat > .git/config <<\EOF ... EOF ``` While this is easy enough to do, it may create problems when using a non-default repository format because this causes us to overwrite the repository format version as well as any potential extensions. With the upcoming "reftable" ref backend the result is that Git would try to access refs via the "files" backend even though the repository has been initialized with the "reftable" backend, which will cause failures when trying to access any refs. Ideally, we would rewrite the whole test suite to not depend on state written by previous tests, but that would result in a lot of changes in this test suite. Instead, we only refactor tests which access the refdb to be more robust by using their own separate repositories, which allows us to be more careful and not discard required extensions. Note that we also have to touch up how the CUSTOM_CONFIG_FILE gets accessed. This environment variable contains the relative path to a custom config file which we're setting up. But because we are now using subrepositories, this relative path will not be found anymore because our working directory changes. This issue is addressed by storing the absolute path to the file in CUSTOM_CONFIG_FILE instead. Signed-off-by: Patrick Steinhardt Reviewed-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t1300-config.sh | 78 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index f4e2752134..31c3878687 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1098,15 +1098,20 @@ test_expect_success SYMLINKS 'symlink to nonexistent configuration' ' test_must_fail git config --file=linktolinktonada --list ' -test_expect_success 'check split_cmdline return' " - git config alias.split-cmdline-fix 'echo \"' && - test_must_fail git split-cmdline-fix && - echo foo > foo && - git add foo && - git commit -m 'initial commit' && - git config branch.main.mergeoptions 'echo \"' && - test_must_fail git merge main -" +test_expect_success 'check split_cmdline return' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + git config alias.split-cmdline-fix "echo \"" && + test_must_fail git split-cmdline-fix && + echo foo >foo && + git add foo && + git commit -m "initial commit" && + git config branch.main.mergeoptions "echo \"" && + test_must_fail git merge main + ) +' test_expect_success 'git -c "key=value" support' ' cat >expect <<-\EOF && @@ -1157,10 +1162,16 @@ test_expect_success 'git -c works with aliases of builtins' ' ' test_expect_success 'aliases can be CamelCased' ' - test_config alias.CamelCased "rev-parse HEAD" && - git CamelCased >out && - git rev-parse HEAD >expect && - test_cmp expect out + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + test_commit A && + git config alias.CamelCased "rev-parse HEAD" && + git CamelCased >out && + git rev-parse HEAD >expect && + test_cmp expect out + ) ' test_expect_success 'git -c does not split values on equals' ' @@ -2009,11 +2020,11 @@ test_expect_success '--show-origin getting a single key' ' ' test_expect_success 'set up custom config file' ' - CUSTOM_CONFIG_FILE="custom.conf" && - cat >"$CUSTOM_CONFIG_FILE" <<-\EOF + cat >"custom.conf" <<-\EOF && [user] custom = true EOF + CUSTOM_CONFIG_FILE="$(test-tool path-utils real_path custom.conf)" ' test_expect_success !MINGW 'set up custom config file with special name characters' ' @@ -2052,22 +2063,33 @@ test_expect_success '--show-origin stdin with file include' ' ' test_expect_success '--show-origin blob' ' - blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") && - cat >expect <<-EOF && - blob:$blob user.custom=true - EOF - git config --blob=$blob --show-origin --list >output && - test_cmp expect output + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") && + cat >expect <<-EOF && + blob:$blob user.custom=true + EOF + git config --blob=$blob --show-origin --list >output && + test_cmp expect output + ) ' test_expect_success '--show-origin blob ref' ' - cat >expect <<-\EOF && - blob:main:custom.conf user.custom=true - EOF - git add "$CUSTOM_CONFIG_FILE" && - git commit -m "new config file" && - git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output && - test_cmp expect output + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + cat >expect <<-\EOF && + blob:main:custom.conf user.custom=true + EOF + cp "$CUSTOM_CONFIG_FILE" custom.conf && + git add custom.conf && + git commit -m "new config file" && + git config --blob=main:custom.conf --show-origin --list >output && + test_cmp expect output + ) ' test_expect_success '--show-origin with --default' ' -- cgit 1.2.3-korg From 1f83e752c52952572697b857018db67b537e7346 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 29 Jan 2024 12:07:22 +0100 Subject: t1301: mark test for `core.sharedRepository` as reffiles specific In t1301 we verify whether reflog files written by the "files" ref backend correctly honor permissions when "core.sharedRepository" is set. The test logic is thus specific to the reffiles backend and will not work with any other backends. Mark the test accordingly with the REFFILES prereq. Signed-off-by: Patrick Steinhardt Reviewed-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t1301-shared-repo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh index e5a0d65caa..8e2c01e760 100755 --- a/t/t1301-shared-repo.sh +++ b/t/t1301-shared-repo.sh @@ -137,7 +137,7 @@ test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' ' test_cmp expect actual ' -test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' ' +test_expect_success REFFILES,POSIXPERM 'git reflog expire honors core.sharedRepository' ' umask 077 && git config core.sharedRepository group && git reflog expire --all && -- cgit 1.2.3-korg From afb99327d07cafd5735392fcd6b0eb07558e53f2 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 29 Jan 2024 12:07:26 +0100 Subject: t1302: make tests more robust with new extensions In t1302 we exercise logic around "core.repositoryFormatVersion" and extensions. These tests are not particularly robust against extensions like the newly introduced "refStorage" extension as we tend to clobber the repository's config file. We thus overwrite any extensions that were set, which may render the repository inaccessible in case it has to be accessed with a non-default ref storage. Refactor the tests to be more robust: - Check the DEFAULT_REPO_FORMAT prereq to determine the expected repository format version. This helps to ensure that we only need to update the prereq in a central place when new extensions are added. Furthermore, this allows us to stop seeding the now-unneeded object ID cache that was only used to figure out the repository version. - Use a separate repository to rewrite ".git/config" to test combinations of the repository format version and extensions. This ensures that we don't break the main test repository. While we could rewrite these tests to not overwrite preexisting extensions, it feels cleaner like this so that we can test extensions standalone without interference from the environment. - Do not rewrite ".git/config" when exercising the "preciousObjects" extension. Signed-off-by: Patrick Steinhardt Reviewed-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t1302-repo-version.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh index 179474fa65..42caa0d297 100755 --- a/t/t1302-repo-version.sh +++ b/t/t1302-repo-version.sh @@ -9,10 +9,6 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' - test_oid_cache <<-\EOF && - version sha1:0 - version sha256:1 - EOF cat >test.patch <<-\EOF && diff --git a/test.txt b/test.txt new file mode 100644 @@ -28,7 +24,12 @@ test_expect_success 'setup' ' ' test_expect_success 'gitdir selection on normal repos' ' - test_oid version >expect && + if test_have_prereq DEFAULT_REPO_FORMAT + then + echo 0 + else + echo 1 + fi >expect && git config core.repositoryformatversion >actual && git -C test config core.repositoryformatversion >actual2 && test_cmp expect actual && @@ -79,8 +80,13 @@ mkconfig () { while read outcome version extensions; do test_expect_success "$outcome version=$version $extensions" " - mkconfig $version $extensions >.git/config && - check_${outcome} + test_when_finished 'rm -rf extensions' && + git init extensions && + ( + cd extensions && + mkconfig $version $extensions >.git/config && + check_${outcome} + ) " done <<\EOF allow 0 @@ -94,7 +100,8 @@ allow 1 noop-v1 EOF test_expect_success 'precious-objects allowed' ' - mkconfig 1 preciousObjects >.git/config && + git config core.repositoryFormatVersion 1 && + git config extensions.preciousObjects 1 && check_allow ' -- cgit 1.2.3-korg From 61e1c560bc7424278504b46f764a1ad945cebf37 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 29 Jan 2024 12:07:30 +0100 Subject: t1419: mark test suite as files-backend specific With 59c35fac54 (refs/packed-backend.c: implement jump lists to avoid excluded pattern(s), 2023-07-10) we have implemented logic to handle excluded refs more efficiently in the "packed" ref backend. This logic allows us to skip emitting refs completely which we know to not be of any interest to the caller, which can avoid quite some allocations and object lookups. This was wired up via a new `exclude_patterns` parameter passed to the backend's ref iterator. The backend only needs to handle them on a best effort basis though, and in fact we only handle it for the "packed-refs" file, but not for loose references. Consequently, all callers must still filter emitted refs with those exclude patterns. The result is that handling exclude patterns is completely optional in the ref backend, and any future backends may or may not implement it. Let's thus mark the test for t1419 to depend on the REFFILES prereq. An alternative would be to introduce a new prereq that tells us whether the backend under test supports exclude patterns or not. But this does feel a bit overblown: - It would either map to the REFFILES prereq, in which case it feels overengineered because the prereq is only ever relevant to t1419. - Otherwise, it could auto-detect whether the backend supports exclude patterns. But this could lead to silent failures in case the support for this feature breaks at any point in time. It should thus be good enough to just use the REFFILES prereq for now. If future backends ever grow support for exclude patterns we can easily add their respective prereq as another condition for this test suite to execute. Signed-off-by: Patrick Steinhardt Reviewed-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t1419-exclude-refs.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/t/t1419-exclude-refs.sh b/t/t1419-exclude-refs.sh index 5d8c86b657..1359574419 100755 --- a/t/t1419-exclude-refs.sh +++ b/t/t1419-exclude-refs.sh @@ -8,6 +8,12 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh +if test_have_prereq !REFFILES +then + skip_all='skipping `git for-each-ref --exclude` tests; need files backend' + test_done +fi + for_each_ref__exclude () { GIT_TRACE2_PERF=1 test-tool ref-store main \ for-each-ref--exclude "$@" >actual.raw -- cgit 1.2.3-korg From 7a746904a98c62cf23b47e8e0450f0e03bd159e9 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 29 Jan 2024 12:07:34 +0100 Subject: t5526: break test submodule differently In 10f5c52656 (submodule: avoid auto-discovery in prepare_submodule_repo_env(), 2016-09-01) we fixed a bug when doing a recursive fetch with submodule in the case where the submodule is broken due to whatever reason. The test to exercise that the fix works breaks the submodule by deleting its `HEAD` reference, which will cause us to not detect the directory as a Git repository. While this is perfectly fine in theory, this way of breaking the repo becomes problematic with the current efforts to introduce another refdb backend into Git. The new reftable backend has a stub HEAD file that always contains "ref: refs/heads/.invalid" so that tools continue to be able to detect such a repository. But as the reftable backend will never delete this file even when asked to delete `HEAD` the current way to delete the `HEAD` reference will stop working. Adapt the code to instead delete the objects database. Going back with this new way to cause breakage confirms that it triggers the infinite recursion just the same, and there are no equivalent ongoing efforts to replace the object database with an alternate backend. Signed-off-by: Patrick Steinhardt Reviewed-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t5526-fetch-submodules.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh index 7ab220fa31..5e566205ba 100755 --- a/t/t5526-fetch-submodules.sh +++ b/t/t5526-fetch-submodules.sh @@ -771,7 +771,7 @@ test_expect_success 'fetching submodule into a broken repository' ' git -C dst fetch --recurse-submodules && # Break the receiving submodule - test-tool -C dst/sub ref-store main delete-refs REF_NO_DEREF msg HEAD && + rm -r dst/sub/.git/objects && # NOTE: without the fix the following tests will recurse forever! # They should terminate with an error. -- cgit 1.2.3-korg From bbd6106967fdb8e97f190f9051b89dcf1633cc56 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 29 Jan 2024 12:07:38 +0100 Subject: t: mark tests regarding git-pack-refs(1) to be backend specific Both t1409 and t3210 exercise parts of git-pack-refs(1). Given that we must check the on-disk files to verify whether the backend has indeed packed refs as expected those test suites are deeply tied to the actual backend that is in use. Mark the test suites to depend on the REFFILES backend. Signed-off-by: Patrick Steinhardt Reviewed-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t1409-avoid-packing-refs.sh | 6 ++++++ t/t3210-pack-refs.sh | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/t/t1409-avoid-packing-refs.sh b/t/t1409-avoid-packing-refs.sh index f23c0152a8..7748973733 100755 --- a/t/t1409-avoid-packing-refs.sh +++ b/t/t1409-avoid-packing-refs.sh @@ -5,6 +5,12 @@ test_description='avoid rewriting packed-refs unnecessarily' TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh +if test_have_prereq !REFFILES +then + skip_all='skipping files-backend specific pack-refs tests' + test_done +fi + # Add an identifying mark to the packed-refs file header line. This # shouldn't upset readers, and it should be omitted if the file is # ever rewritten. diff --git a/t/t3210-pack-refs.sh b/t/t3210-pack-refs.sh index 7f4e98db7d..c0f1f9cfb7 100755 --- a/t/t3210-pack-refs.sh +++ b/t/t3210-pack-refs.sh @@ -15,6 +15,12 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh +if test_have_prereq !REFFILES +then + skip_all='skipping files-backend specific pack-refs tests' + test_done +fi + test_expect_success 'enable reflogs' ' git config core.logallrefupdates true ' -- cgit 1.2.3-korg