Merge branch 'bc/clone-with-git-default-hash-fix'
"git clone" that clones from SHA-1 repository, while GIT_DEFAULT_HASH set to use SHA-256 already, resulted in an unusable repository that half-claims to be SHA-256 repository with SHA-1 objects and refs. This has been corrected. * bc/clone-with-git-default-hash-fix: builtin/clone: avoid failure with GIT_DEFAULT_HASH
This commit is contained in:
@ -1233,7 +1233,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
|
|||||||
* Now that we know what algorithm the remote side is using,
|
* Now that we know what algorithm the remote side is using,
|
||||||
* let's set ours to the same thing.
|
* let's set ours to the same thing.
|
||||||
*/
|
*/
|
||||||
initialize_repository_version(hash_algo);
|
initialize_repository_version(hash_algo, 1);
|
||||||
repo_set_hash_algo(the_repository, hash_algo);
|
repo_set_hash_algo(the_repository, hash_algo);
|
||||||
|
|
||||||
mapped_refs = wanted_peer_refs(refs, &remote->fetch);
|
mapped_refs = wanted_peer_refs(refs, &remote->fetch);
|
||||||
|
@ -179,7 +179,7 @@ static int needs_work_tree_config(const char *git_dir, const char *work_tree)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize_repository_version(int hash_algo)
|
void initialize_repository_version(int hash_algo, int reinit)
|
||||||
{
|
{
|
||||||
char repo_version_string[10];
|
char repo_version_string[10];
|
||||||
int repo_version = GIT_REPO_VERSION;
|
int repo_version = GIT_REPO_VERSION;
|
||||||
@ -195,6 +195,8 @@ void initialize_repository_version(int hash_algo)
|
|||||||
if (hash_algo != GIT_HASH_SHA1)
|
if (hash_algo != GIT_HASH_SHA1)
|
||||||
git_config_set("extensions.objectformat",
|
git_config_set("extensions.objectformat",
|
||||||
hash_algos[hash_algo].name);
|
hash_algos[hash_algo].name);
|
||||||
|
else if (reinit)
|
||||||
|
git_config_set_gently("extensions.objectformat", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create_default_files(const char *template_path,
|
static int create_default_files(const char *template_path,
|
||||||
@ -277,7 +279,7 @@ static int create_default_files(const char *template_path,
|
|||||||
free(ref);
|
free(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize_repository_version(fmt->hash_algo);
|
initialize_repository_version(fmt->hash_algo, 0);
|
||||||
|
|
||||||
/* Check filemode trustability */
|
/* Check filemode trustability */
|
||||||
path = git_path_buf(&buf, "config");
|
path = git_path_buf(&buf, "config");
|
||||||
|
2
cache.h
2
cache.h
@ -629,7 +629,7 @@ int path_inside_repo(const char *prefix, const char *path);
|
|||||||
int init_db(const char *git_dir, const char *real_git_dir,
|
int init_db(const char *git_dir, const char *real_git_dir,
|
||||||
const char *template_dir, int hash_algo,
|
const char *template_dir, int hash_algo,
|
||||||
const char *initial_branch, unsigned int flags);
|
const char *initial_branch, unsigned int flags);
|
||||||
void initialize_repository_version(int hash_algo);
|
void initialize_repository_version(int hash_algo, int reinit);
|
||||||
|
|
||||||
void sanitize_stdfds(void);
|
void sanitize_stdfds(void);
|
||||||
int daemonize(void);
|
int daemonize(void);
|
||||||
|
@ -631,6 +631,20 @@ test_expect_success CASE_INSENSITIVE_FS 'colliding file detection' '
|
|||||||
test_i18ngrep "the following paths have collided" icasefs/warning
|
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 () {
|
partial_clone_server () {
|
||||||
SERVER="$1" &&
|
SERVER="$1" &&
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user