From 47ac970309dc26c95c4de4991b2e6aa7c7b7f615 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sun, 20 Sep 2020 22:35:41 +0000 Subject: builtin/clone: avoid failure with GIT_DEFAULT_HASH If a user is cloning a SHA-1 repository with GIT_DEFAULT_HASH set to "sha256", then we can end up with a repository where the repository format version is 0 but the extensions.objectformat key is set to "sha256". This is both wrong (the user has a SHA-1 repository) and nonfunctional (because the extension cannot be used in a v0 repository). This happens because in a clone, we initially set up the repository, and then change its algorithm based on what the remote side tells us it's using. We've initially set up the repository as SHA-256 in this case, and then later on reset the repository version without clearing the extension. We could just always set the extension in this case, but that would mean that our SHA-1 repositories weren't compatible with older Git versions, even though there's no reason why they shouldn't be. And we also don't want to initialize the repository as SHA-1 initially, since that means if we're cloning an empty repository, we'll have failed to honor the GIT_DEFAULT_HASH variable and will end up with a SHA-1 repository, not a SHA-256 repository. Neither of those are appealing, so let's tell the repository initialization code if we're doing a reinit like this, and if so, to clear the extension if we're using SHA-1. This makes sure we produce a valid and functional repository and doesn't break any of our other use cases. Reported-by: Matheus Tavares Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t5601-clone.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 't') diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 15fb64c18d..b6c8312da1 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -631,6 +631,20 @@ test_expect_success CASE_INSENSITIVE_FS 'colliding file detection' ' test_i18ngrep "the following paths have collided" icasefs/warning ' +test_expect_success 'clone with GIT_DEFAULT_HASH' ' + ( + sane_unset GIT_DEFAULT_HASH && + git init --object-format=sha1 test-sha1 && + git init --object-format=sha256 test-sha256 + ) && + test_commit -C test-sha1 foo && + test_commit -C test-sha256 foo && + GIT_DEFAULT_HASH=sha1 git clone test-sha256 test-clone-sha256 && + GIT_DEFAULT_HASH=sha256 git clone test-sha1 test-clone-sha1 && + git -C test-clone-sha1 status && + git -C test-clone-sha256 status +' + partial_clone_server () { SERVER="$1" && -- cgit v1.2.3