Skip to content

Commit afb9932

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f83e75 commit afb9932

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

t/t1302-repo-version.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ TEST_PASSES_SANITIZE_LEAK=true
99
. ./test-lib.sh
1010

1111
test_expect_success 'setup' '
12-
test_oid_cache <<-\EOF &&
13-
version sha1:0
14-
version sha256:1
15-
EOF
1612
cat >test.patch <<-\EOF &&
1713
diff --git a/test.txt b/test.txt
1814
new file mode 100644
@@ -28,7 +24,12 @@ test_expect_success 'setup' '
2824
'
2925

3026
test_expect_success 'gitdir selection on normal repos' '
31-
test_oid version >expect &&
27+
if test_have_prereq DEFAULT_REPO_FORMAT
28+
then
29+
echo 0
30+
else
31+
echo 1
32+
fi >expect &&
3233
git config core.repositoryformatversion >actual &&
3334
git -C test config core.repositoryformatversion >actual2 &&
3435
test_cmp expect actual &&
@@ -79,8 +80,13 @@ mkconfig () {
7980

8081
while read outcome version extensions; do
8182
test_expect_success "$outcome version=$version $extensions" "
82-
mkconfig $version $extensions >.git/config &&
83-
check_${outcome}
83+
test_when_finished 'rm -rf extensions' &&
84+
git init extensions &&
85+
(
86+
cd extensions &&
87+
mkconfig $version $extensions >.git/config &&
88+
check_${outcome}
89+
)
8490
"
8591
done <<\EOF
8692
allow 0
@@ -94,7 +100,8 @@ allow 1 noop-v1
94100
EOF
95101

96102
test_expect_success 'precious-objects allowed' '
97-
mkconfig 1 preciousObjects >.git/config &&
103+
git config core.repositoryFormatVersion 1 &&
104+
git config extensions.preciousObjects 1 &&
98105
check_allow
99106
'
100107

0 commit comments

Comments
 (0)