From: Junio C Hamano Date: Mon, 3 Jun 2024 20:11:11 +0000 (-0700) Subject: Merge branch 'ps/fix-reinit-includeif-onbranch' X-Git-Tag: v2.46.0-rc0~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c7c063c1f2b862d4d91b2230fc064dd9cf2d414;p=thirdparty%2Fgit.git Merge branch 'ps/fix-reinit-includeif-onbranch' "git init" in an already created directory, when the user configuration has includeif.onbranch, started to fail recently, which has been corrected. * ps/fix-reinit-includeif-onbranch: setup: fix bug with "includeIf.onbranch" when initializing dir --- 5c7c063c1f2b862d4d91b2230fc064dd9cf2d414 diff --cc setup.c index f00f6cf2b6,c6fffa0164..3ade79d245 --- a/setup.c +++ b/setup.c @@@ -2368,6 -2213,21 +2359,18 @@@ int init_db(const char *git_dir, const repo_set_hash_algo(the_repository, repo_fmt.hash_algo); repo_set_ref_storage_format(the_repository, repo_fmt.ref_storage_format); + /* + * Ensure `core.hidedotfiles` is processed. This must happen after we + * have set up the repository format such that we can evaluate + * includeIf conditions correctly in the case of re-initialization. + */ + git_config(platform_core_config, NULL); + + safe_create_dir(git_dir, 0); + - prev_bare_repository = is_bare_repository(); - + reinit = create_default_files(template_dir, original_git_dir, - &repo_fmt, prev_bare_repository, - init_shared_repository); ++ &repo_fmt, init_shared_repository); + if (!(flags & INIT_DB_SKIP_REFDB)) create_reference_database(repo_fmt.ref_storage_format, initial_branch, flags & INIT_DB_QUIET); diff --cc t/t0001-init.sh index b131d665db,319ed81631..49e9bf77c6 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@@ -584,14 -584,39 +584,39 @@@ test_expect_success 'init with --ref-fo test_cmp expect actual ' - test_expect_success 're-init with same format' ' - test_when_finished "rm -rf refformat" && - git init --ref-format=files refformat && - git init --ref-format=files refformat && - echo files >expect && - git -C refformat rev-parse --show-ref-format >actual && - test_cmp expect actual - ' -backends="files" ++backends="files reftable" + for from_format in $backends + do + test_expect_success "re-init with same format ($from_format)" ' + test_when_finished "rm -rf refformat" && + git init --ref-format=$from_format refformat && + git init --ref-format=$from_format refformat && + echo $from_format >expect && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual + ' + + for to_format in $backends + do + if test "$from_format" = "$to_format" + then + continue + fi + + test_expect_success "re-init with different format fails ($from_format -> $to_format)" ' + test_when_finished "rm -rf refformat" && + git init --ref-format=$from_format refformat && + cat >expect <<-EOF && + fatal: attempt to reinitialize repository with different reference storage format + EOF + test_must_fail git init --ref-format=$to_format refformat 2>err && + test_cmp expect err && + echo $from_format >expect && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual + ' + done + done test_expect_success 'init with --ref-format=garbage' ' test_when_finished "rm -rf refformat" &&