Merge branch 'bc/clone-bare-with-conflicting-config'

"git -c core.bare=false clone --bare ..." would have segfaulted,
which has been corrected.

* bc/clone-bare-with-conflicting-config:
  builtin/init-db: handle bare clones when core.bare set to false
maint
Junio C Hamano 2021-03-22 14:00:25 -07:00
commit 3099d4faa3
2 changed files with 10 additions and 2 deletions

View File

@ -212,6 +212,7 @@ static int create_default_files(const char *template_path,
int reinit; int reinit;
int filemode; int filemode;
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
const char *work_tree = get_git_work_tree();


/* Just look for `init.templatedir` */ /* Just look for `init.templatedir` */
init_db_template_dir = NULL; /* re-set in case it was set before */ init_db_template_dir = NULL; /* re-set in case it was set before */
@ -235,7 +236,7 @@ static int create_default_files(const char *template_path,
* We must make sure command-line options continue to override any * We must make sure command-line options continue to override any
* values we might have just re-read from the config. * values we might have just re-read from the config.
*/ */
is_bare_repository_cfg = init_is_bare_repository; is_bare_repository_cfg = init_is_bare_repository || !work_tree;
if (init_shared_repository != -1) if (init_shared_repository != -1)
set_shared_repository(init_shared_repository); set_shared_repository(init_shared_repository);


@ -299,7 +300,6 @@ static int create_default_files(const char *template_path,
if (is_bare_repository()) if (is_bare_repository())
git_config_set("core.bare", "true"); git_config_set("core.bare", "true");
else { else {
const char *work_tree = get_git_work_tree();
git_config_set("core.bare", "false"); git_config_set("core.bare", "false");
/* allow template config file to override the default */ /* allow template config file to override the default */
if (log_all_ref_updates == LOG_REFS_UNSET) if (log_all_ref_updates == LOG_REFS_UNSET)

View File

@ -104,6 +104,14 @@ test_expect_success 'redirected clone -v does show progress' '


' '


test_expect_success 'clone does not segfault with --bare and core.bare=false' '
test_config_global core.bare false &&
git clone --bare parent clone-bare &&
echo true >expect &&
git -C clone-bare rev-parse --is-bare-repository >actual &&
test_cmp expect actual
'

test_expect_success 'chooses correct default initial branch name' ' test_expect_success 'chooses correct default initial branch name' '
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
git -c init.defaultBranch=foo init --bare empty && git -c init.defaultBranch=foo init --bare empty &&