@@ -584,14 +584,39 @@ test_expect_success 'init with --ref-format=files' '
584584 test_cmp expect actual
585585'
586586
587- test_expect_success ' re-init with same format' '
588- test_when_finished "rm -rf refformat" &&
589- git init --ref-format=files refformat &&
590- git init --ref-format=files refformat &&
591- echo files >expect &&
592- git -C refformat rev-parse --show-ref-format >actual &&
593- test_cmp expect actual
594- '
587+ backends=" files reftable"
588+ for from_format in $backends
589+ do
590+ test_expect_success " re-init with same format ($from_format )" '
591+ test_when_finished "rm -rf refformat" &&
592+ git init --ref-format=$from_format refformat &&
593+ git init --ref-format=$from_format refformat &&
594+ echo $from_format >expect &&
595+ git -C refformat rev-parse --show-ref-format >actual &&
596+ test_cmp expect actual
597+ '
598+
599+ for to_format in $backends
600+ do
601+ if test " $from_format " = " $to_format "
602+ then
603+ continue
604+ fi
605+
606+ test_expect_success " re-init with different format fails ($from_format -> $to_format )" '
607+ test_when_finished "rm -rf refformat" &&
608+ git init --ref-format=$from_format refformat &&
609+ cat >expect <<-EOF &&
610+ fatal: attempt to reinitialize repository with different reference storage format
611+ EOF
612+ test_must_fail git init --ref-format=$to_format refformat 2>err &&
613+ test_cmp expect err &&
614+ echo $from_format >expect &&
615+ git -C refformat rev-parse --show-ref-format >actual &&
616+ test_cmp expect actual
617+ '
618+ done
619+ done
595620
596621test_expect_success ' init with --ref-format=garbage' '
597622 test_when_finished "rm -rf refformat" &&
@@ -678,4 +703,64 @@ test_expect_success 'branch -m with the initial branch' '
678703 test_cmp expect actual
679704'
680705
706+ test_expect_success ' init with includeIf.onbranch condition' '
707+ test_when_finished "rm -rf repo" &&
708+ git -c includeIf.onbranch:main.path=nonexistent init repo &&
709+ echo $GIT_DEFAULT_REF_FORMAT >expect &&
710+ git -C repo rev-parse --show-ref-format >actual &&
711+ test_cmp expect actual
712+ '
713+
714+ test_expect_success ' init with includeIf.onbranch condition with existing directory' '
715+ test_when_finished "rm -rf repo" &&
716+ mkdir repo &&
717+ git -c includeIf.onbranch:nonexistent.path=/does/not/exist init repo &&
718+ echo $GIT_DEFAULT_REF_FORMAT >expect &&
719+ git -C repo rev-parse --show-ref-format >actual &&
720+ test_cmp expect actual
721+ '
722+
723+ test_expect_success ' re-init with includeIf.onbranch condition' '
724+ test_when_finished "rm -rf repo" &&
725+ git init repo &&
726+ git -c includeIf.onbranch:nonexistent.path=/does/not/exist init repo &&
727+ echo $GIT_DEFAULT_REF_FORMAT >expect &&
728+ git -C repo rev-parse --show-ref-format >actual &&
729+ test_cmp expect actual
730+ '
731+
732+ test_expect_success ' re-init with includeIf.onbranch condition' '
733+ test_when_finished "rm -rf repo" &&
734+ git init repo &&
735+ git -c includeIf.onbranch:nonexistent.path=/does/not/exist init repo &&
736+ echo $GIT_DEFAULT_REF_FORMAT >expect &&
737+ git -C repo rev-parse --show-ref-format >actual &&
738+ test_cmp expect actual
739+ '
740+
741+ test_expect_success ' re-init skips non-matching includeIf.onbranch' '
742+ test_when_finished "rm -rf repo config" &&
743+ cat >config <<-EOF &&
744+ [
745+ garbage
746+ EOF
747+ git init repo &&
748+ git -c includeIf.onbranch:nonexistent.path="$(test-tool path-utils absolute_path config)" init repo
749+ '
750+
751+ test_expect_success ' re-init reads matching includeIf.onbranch' '
752+ test_when_finished "rm -rf repo config" &&
753+ cat >config <<-EOF &&
754+ [
755+ garbage
756+ EOF
757+ path="$(test-tool path-utils absolute_path config)" &&
758+ git init --initial-branch=branch repo &&
759+ cat >expect <<-EOF &&
760+ fatal: bad config line 1 in file $path
761+ EOF
762+ test_must_fail git -c includeIf.onbranch:branch.path="$path" init repo 2>err &&
763+ test_cmp expect err
764+ '
765+
681766test_done
0 commit comments