]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ps/fix-reinit-includeif-onbranch'
authorJunio C Hamano <gitster@pobox.com>
Mon, 3 Jun 2024 20:11:11 +0000 (13:11 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 3 Jun 2024 20:11:11 +0000 (13:11 -0700)
"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

1  2 
setup.c
t/t0001-init.sh

diff --cc setup.c
index f00f6cf2b69f09b7c46a596e3b7a9ac6c923947f,c6fffa01643ed8db84676f7629bc1dd48ea49391..3ade79d245dfad00d273f27efed53fd5cc275d8c
+++ 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);
  
 -      prev_bare_repository = is_bare_repository();
 -
+       /*
+        * 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);
 -                                    &repo_fmt, prev_bare_repository,
 -                                    init_shared_repository);
+       reinit = create_default_files(template_dir, original_git_dir,
++                                    &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 b131d665db40e9858d4a3f9c13ab71eb77d6cc5f,319ed81631f291b15ed7df67cbc6ec108c086448..49e9bf77c6037541a9bdd8d98d482b3d40f6e070
@@@ -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" &&