check_repository_format_gently(): refuse extensions for old repositories

Previously, extensions were recognized regardless of repository format
version.  If the user sets an undefined "extensions" value on a
repository of version 0 and that value is used by a future git version,
they might get an undesired result.

Because all extensions now also upgrade repository versions, tightening
the check would help avoid this for future extensions.

Signed-off-by: Xin Li <delphij@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Xin Li 2020-06-05 02:10:04 -07:00 committed by Junio C Hamano
parent 98564d8059
commit 14c7fa269e
2 changed files with 20 additions and 3 deletions

View File

@ -507,9 +507,15 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
die("%s", err.buf); die("%s", err.buf);
} }
if (candidate->version >= 1) {
repository_format_precious_objects = candidate->precious_objects; repository_format_precious_objects = candidate->precious_objects;
set_repository_format_partial_clone(candidate->partial_clone); set_repository_format_partial_clone(candidate->partial_clone);
repository_format_worktree_config = candidate->worktree_config; repository_format_worktree_config = candidate->worktree_config;
} else {
repository_format_precious_objects = 0;
set_repository_format_partial_clone(NULL);
repository_format_worktree_config = 0;
}
string_list_clear(&candidate->unknown_extensions, 0); string_list_clear(&candidate->unknown_extensions, 0);
if (repository_format_worktree_config) { if (repository_format_worktree_config) {

View File

@ -42,6 +42,17 @@ test_expect_success 'convert shallow clone to partial clone' '
test_cmp_config -C client 1 core.repositoryformatversion test_cmp_config -C client 1 core.repositoryformatversion
' '
test_expect_success 'convert shallow clone to partial clone must fail with any extension' '
rm -fr server client &&
test_create_repo server &&
test_commit -C server my_commit 1 &&
test_commit -C server my_commit2 1 &&
git clone --depth=1 "file://$(pwd)/server" client &&
test_cmp_config -C client 0 core.repositoryformatversion &&
git -C client config extensions.partialclone origin &&
test_must_fail git -C client fetch --unshallow --filter="blob:none"
'
test_expect_success 'missing reflog object, but promised by a commit, passes fsck' ' test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
rm -rf repo && rm -rf repo &&
test_create_repo repo && test_create_repo repo &&