Skip to content

Commit 3099d4f

Browse files
committed
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
2 parents d4bda9b + 7555567 commit 3099d4f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

builtin/init-db.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static int create_default_files(const char *template_path,
212212
int reinit;
213213
int filemode;
214214
struct strbuf err = STRBUF_INIT;
215+
const char *work_tree = get_git_work_tree();
215216

216217
/* Just look for `init.templatedir` */
217218
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,
235236
* We must make sure command-line options continue to override any
236237
* values we might have just re-read from the config.
237238
*/
238-
is_bare_repository_cfg = init_is_bare_repository;
239+
is_bare_repository_cfg = init_is_bare_repository || !work_tree;
239240
if (init_shared_repository != -1)
240241
set_shared_repository(init_shared_repository);
241242

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

t/t5606-clone-options.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ test_expect_success 'redirected clone -v does show progress' '
104104
105105
'
106106

107+
test_expect_success 'clone does not segfault with --bare and core.bare=false' '
108+
test_config_global core.bare false &&
109+
git clone --bare parent clone-bare &&
110+
echo true >expect &&
111+
git -C clone-bare rev-parse --is-bare-repository >actual &&
112+
test_cmp expect actual
113+
'
114+
107115
test_expect_success 'chooses correct default initial branch name' '
108116
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
109117
git -c init.defaultBranch=foo init --bare empty &&

0 commit comments

Comments
 (0)