2007-12-05 13:33:32 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Nguyễn Thái Ngọc Duy
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test repository version check'
|
|
|
|
|
tests: mark tests as passing with SANITIZE=leak
When the "ab/various-leak-fixes" topic was merged in [1] only t6021
would fail if the tests were run in the
"GIT_TEST_PASSING_SANITIZE_LEAK=check" mode, i.e. to check whether we
marked all leak-free tests with "TEST_PASSES_SANITIZE_LEAK=true".
Since then we've had various tests starting to pass under
SANITIZE=leak. Let's mark those as passing, this is when they started
to pass, narrowed down with "git bisect":
- t5317-pack-objects-filter-objects.sh: In
faebba436e6 (list-objects-filter: plug pattern_list leak, 2022-12-01).
- t3210-pack-refs.sh, t5613-info-alternate.sh,
t7403-submodule-sync.sh: In 189e97bc4ba (diff: remove parseopts member
from struct diff_options, 2022-12-01).
- t1408-packed-refs.sh: In ab91f6b7c42 (Merge branch
'rs/diff-parseopts', 2022-12-19).
- t0023-crlf-am.sh, t4152-am-subjects.sh, t4254-am-corrupt.sh,
t4256-am-format-flowed.sh, t4257-am-interactive.sh,
t5403-post-checkout-hook.sh: In a658e881c13 (am: don't pass strvec to
apply_parse_options(), 2022-12-13)
- t1301-shared-repo.sh, t1302-repo-version.sh: In b07a819c05f (reflog:
clear leftovers in reflog_expiry_cleanup(), 2022-12-13).
- t1304-default-acl.sh, t1410-reflog.sh,
t5330-no-lazy-fetch-with-commit-graph.sh, t5502-quickfetch.sh,
t5604-clone-reference.sh, t6014-rev-list-all.sh,
t7701-repack-unpack-unreachable.sh: In b0c61be3209 (Merge branch
'rs/reflog-expiry-cleanup', 2022-12-26)
- t3800-mktag.sh, t5302-pack-index.sh, t5306-pack-nobase.sh,
t5573-pull-verify-signatures.sh, t7612-merge-verify-signatures.sh: In
69bbbe484ba (hash-object: use fsck for object checks, 2023-01-18).
- t1451-fsck-buffer.sh: In 8e4309038f0 (fsck: do not assume
NUL-termination of buffers, 2023-01-19).
- t6501-freshen-objects.sh: In abf2bb895b4 (Merge branch
'jk/hash-object-fsck', 2023-01-30)
1. 9ea1378d046 (Merge branch 'ab/various-leak-fixes', 2022-12-14)
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-02-06 23:07:36 +00:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2007-12-05 13:33:32 +00:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2010-09-07 01:52:27 +00:00
|
|
|
test_expect_success 'setup' '
|
|
|
|
cat >test.patch <<-\EOF &&
|
|
|
|
diff --git a/test.txt b/test.txt
|
|
|
|
new file mode 100644
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/test.txt
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+123
|
|
|
|
EOF
|
2007-12-05 13:33:32 +00:00
|
|
|
|
2010-09-07 01:52:27 +00:00
|
|
|
test_create_repo "test" &&
|
|
|
|
test_create_repo "test2" &&
|
2014-03-20 23:17:01 +00:00
|
|
|
git config --file=test2/.git/config core.repositoryformatversion 99
|
2010-09-07 01:52:27 +00:00
|
|
|
'
|
2007-12-05 13:33:32 +00:00
|
|
|
|
|
|
|
test_expect_success 'gitdir selection on normal repos' '
|
2024-01-29 11:07:26 +00:00
|
|
|
if test_have_prereq DEFAULT_REPO_FORMAT
|
|
|
|
then
|
|
|
|
echo 0
|
|
|
|
else
|
|
|
|
echo 1
|
|
|
|
fi >expect &&
|
2010-09-07 01:52:27 +00:00
|
|
|
git config core.repositoryformatversion >actual &&
|
2016-09-13 03:24:00 +00:00
|
|
|
git -C test config core.repositoryformatversion >actual2 &&
|
2010-09-07 01:52:27 +00:00
|
|
|
test_cmp expect actual &&
|
|
|
|
test_cmp expect actual2
|
|
|
|
'
|
2007-12-05 13:33:32 +00:00
|
|
|
|
|
|
|
test_expect_success 'gitdir selection on unsupported repo' '
|
2010-09-07 01:52:27 +00:00
|
|
|
# Make sure it would stop at test2, not trash
|
2023-03-18 15:46:43 +00:00
|
|
|
test_expect_code 1 git -C test2 config core.repositoryformatversion
|
2010-09-07 01:52:27 +00:00
|
|
|
'
|
2007-12-05 13:33:32 +00:00
|
|
|
|
|
|
|
test_expect_success 'gitdir not required mode' '
|
2010-09-06 18:39:54 +00:00
|
|
|
git apply --stat test.patch &&
|
2016-09-13 03:24:00 +00:00
|
|
|
git -C test apply --stat ../test.patch &&
|
|
|
|
git -C test2 apply --stat ../test.patch
|
2010-09-07 01:42:54 +00:00
|
|
|
'
|
2007-12-05 13:33:32 +00:00
|
|
|
|
2010-09-07 01:52:27 +00:00
|
|
|
test_expect_success 'gitdir required mode' '
|
|
|
|
git apply --check --index test.patch &&
|
2016-09-13 03:24:00 +00:00
|
|
|
git -C test apply --check --index ../test.patch &&
|
|
|
|
test_must_fail git -C test2 apply --check --index ../test.patch
|
2008-02-01 09:50:53 +00:00
|
|
|
'
|
2007-12-05 13:33:32 +00:00
|
|
|
|
introduce "extensions" form of core.repositoryformatversion
Normally we try to avoid bumps of the whole-repository
core.repositoryformatversion field. However, it is
unavoidable if we want to safely change certain aspects of
git in a backwards-incompatible way (e.g., modifying the set
of ref tips that we must traverse to generate a list of
unreachable, safe-to-prune objects).
If we were to bump the repository version for every such
change, then any implementation understanding version `X`
would also have to understand `X-1`, `X-2`, and so forth,
even though the incompatibilities may be in orthogonal parts
of the system, and there is otherwise no reason we cannot
implement one without the other (or more importantly, that
the user cannot choose to use one feature without the other,
weighing the tradeoff in compatibility only for that
particular feature).
This patch documents the existing repositoryformatversion
strategy and introduces a new format, "1", which lets a
repository specify that it must run with an arbitrary set of
extensions. This can be used, for example:
- to inform git that the objects should not be pruned based
only on the reachability of the ref tips (e.g, because it
has "clone --shared" children)
- that the refs are stored in a format besides the usual
"refs" and "packed-refs" directories
Because we bump to format "1", and because format "1"
requires that a running git knows about any extensions
mentioned, we know that older versions of the code will not
do something dangerous when confronted with these new
formats.
For example, if the user chooses to use database storage for
refs, they may set the "extensions.refbackend" config to
"db". Older versions of git will not understand format "1"
and bail. Versions of git which understand "1" but do not
know about "refbackend", or which know about "refbackend"
but not about the "db" backend, will refuse to run. This is
annoying, of course, but much better than the alternative of
claiming that there are no refs in the repository, or
writing to a location that other implementations will not
read.
Note that we are only defining the rules for format 1 here.
We do not ever write format 1 ourselves; it is a tool that
is meant to be used by users and future extensions to
provide safety with older implementations.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-06-23 10:53:58 +00:00
|
|
|
check_allow () {
|
|
|
|
git rev-parse --git-dir >actual &&
|
|
|
|
echo .git >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
}
|
|
|
|
|
|
|
|
check_abort () {
|
|
|
|
test_must_fail git rev-parse --git-dir
|
|
|
|
}
|
|
|
|
|
|
|
|
# avoid git-config, since it cannot be trusted to run
|
|
|
|
# in a repository with a broken version
|
|
|
|
mkconfig () {
|
|
|
|
echo '[core]' &&
|
|
|
|
echo "repositoryformatversion = $1" &&
|
|
|
|
shift &&
|
|
|
|
|
|
|
|
if test $# -gt 0; then
|
|
|
|
echo '[extensions]' &&
|
|
|
|
for i in "$@"; do
|
|
|
|
echo "$i"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
while read outcome version extensions; do
|
|
|
|
test_expect_success "$outcome version=$version $extensions" "
|
2024-01-29 11:07:26 +00:00
|
|
|
test_when_finished 'rm -rf extensions' &&
|
|
|
|
git init extensions &&
|
|
|
|
(
|
|
|
|
cd extensions &&
|
|
|
|
mkconfig $version $extensions >.git/config &&
|
|
|
|
check_${outcome}
|
|
|
|
)
|
introduce "extensions" form of core.repositoryformatversion
Normally we try to avoid bumps of the whole-repository
core.repositoryformatversion field. However, it is
unavoidable if we want to safely change certain aspects of
git in a backwards-incompatible way (e.g., modifying the set
of ref tips that we must traverse to generate a list of
unreachable, safe-to-prune objects).
If we were to bump the repository version for every such
change, then any implementation understanding version `X`
would also have to understand `X-1`, `X-2`, and so forth,
even though the incompatibilities may be in orthogonal parts
of the system, and there is otherwise no reason we cannot
implement one without the other (or more importantly, that
the user cannot choose to use one feature without the other,
weighing the tradeoff in compatibility only for that
particular feature).
This patch documents the existing repositoryformatversion
strategy and introduces a new format, "1", which lets a
repository specify that it must run with an arbitrary set of
extensions. This can be used, for example:
- to inform git that the objects should not be pruned based
only on the reachability of the ref tips (e.g, because it
has "clone --shared" children)
- that the refs are stored in a format besides the usual
"refs" and "packed-refs" directories
Because we bump to format "1", and because format "1"
requires that a running git knows about any extensions
mentioned, we know that older versions of the code will not
do something dangerous when confronted with these new
formats.
For example, if the user chooses to use database storage for
refs, they may set the "extensions.refbackend" config to
"db". Older versions of git will not understand format "1"
and bail. Versions of git which understand "1" but do not
know about "refbackend", or which know about "refbackend"
but not about the "db" backend, will refuse to run. This is
annoying, of course, but much better than the alternative of
claiming that there are no refs in the repository, or
writing to a location that other implementations will not
read.
Note that we are only defining the rules for format 1 here.
We do not ever write format 1 ourselves; it is a tool that
is meant to be used by users and future extensions to
provide safety with older implementations.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-06-23 10:53:58 +00:00
|
|
|
"
|
|
|
|
done <<\EOF
|
|
|
|
allow 0
|
|
|
|
allow 1
|
|
|
|
allow 1 noop
|
|
|
|
abort 1 no-such-extension
|
|
|
|
allow 0 no-such-extension
|
2020-07-16 12:25:13 +00:00
|
|
|
allow 0 noop
|
|
|
|
abort 0 noop-v1
|
|
|
|
allow 1 noop-v1
|
introduce "extensions" form of core.repositoryformatversion
Normally we try to avoid bumps of the whole-repository
core.repositoryformatversion field. However, it is
unavoidable if we want to safely change certain aspects of
git in a backwards-incompatible way (e.g., modifying the set
of ref tips that we must traverse to generate a list of
unreachable, safe-to-prune objects).
If we were to bump the repository version for every such
change, then any implementation understanding version `X`
would also have to understand `X-1`, `X-2`, and so forth,
even though the incompatibilities may be in orthogonal parts
of the system, and there is otherwise no reason we cannot
implement one without the other (or more importantly, that
the user cannot choose to use one feature without the other,
weighing the tradeoff in compatibility only for that
particular feature).
This patch documents the existing repositoryformatversion
strategy and introduces a new format, "1", which lets a
repository specify that it must run with an arbitrary set of
extensions. This can be used, for example:
- to inform git that the objects should not be pruned based
only on the reachability of the ref tips (e.g, because it
has "clone --shared" children)
- that the refs are stored in a format besides the usual
"refs" and "packed-refs" directories
Because we bump to format "1", and because format "1"
requires that a running git knows about any extensions
mentioned, we know that older versions of the code will not
do something dangerous when confronted with these new
formats.
For example, if the user chooses to use database storage for
refs, they may set the "extensions.refbackend" config to
"db". Older versions of git will not understand format "1"
and bail. Versions of git which understand "1" but do not
know about "refbackend", or which know about "refbackend"
but not about the "db" backend, will refuse to run. This is
annoying, of course, but much better than the alternative of
claiming that there are no refs in the repository, or
writing to a location that other implementations will not
read.
Note that we are only defining the rules for format 1 here.
We do not ever write format 1 ourselves; it is a tool that
is meant to be used by users and future extensions to
provide safety with older implementations.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-06-23 10:53:58 +00:00
|
|
|
EOF
|
|
|
|
|
2015-06-23 10:54:11 +00:00
|
|
|
test_expect_success 'precious-objects allowed' '
|
2024-01-29 11:07:26 +00:00
|
|
|
git config core.repositoryFormatVersion 1 &&
|
|
|
|
git config extensions.preciousObjects 1 &&
|
2015-06-23 10:54:11 +00:00
|
|
|
check_allow
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'precious-objects blocks destructive repack' '
|
|
|
|
test_must_fail git repack -ad
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'other repacks are OK' '
|
|
|
|
test_commit foo &&
|
|
|
|
git repack
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'precious-objects blocks prune' '
|
|
|
|
test_must_fail git prune
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'gc runs without complaint' '
|
|
|
|
git gc
|
|
|
|
'
|
|
|
|
|
2007-12-05 13:33:32 +00:00
|
|
|
test_done
|