Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t0001-init.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t0001-init.sh` 1235 lines ยท 38819 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='git init' 4 5 . ./test-lib.sh 6 7 check_config () { 8 if test_path_is_dir "$1" && 9 test_path_is_file "$1/config" && test_path_is_dir "$1/refs" 10 then 11 : happy 12 else 13 echo "expected a directory $1, a file $1/config and $1/refs" 14 return 1 15 fi 16 17 if test_have_prereq POSIXPERM && test -x "$1/config" 18 then 19 echo "$1/config is executable?" 20 return 1 21 fi 22 23 bare=$(cd "$1" && git config --bool core.bare) 24 worktree=$(cd "$1" && git config core.worktree) || 25 worktree=unset 26 27 test "$bare" = "$2" && test "$worktree" = "$3" || { 28 echo "expected bare=$2 worktree=$3" 29 echo " got bare=$bare worktree=$worktree" 30 return 1 31 } 32 } 33 34 test_expect_success 'plain' ' 35 git init plain && 36 check_config plain/.git false unset 37 ' 38 39 test_expect_success 'plain nested in bare' ' 40 ( 41 git init --bare bare-ancestor.git && 42 cd bare-ancestor.git && 43 mkdir plain-nested && 44 cd plain-nested && 45 git init 46 ) && 47 check_config bare-ancestor.git/plain-nested/.git false unset 48 ' 49 50 test_expect_success 'plain through aliased command, outside any git repo' ' 51 ( 52 HOME=$(pwd)/alias-config && 53 export HOME && 54 mkdir alias-config && 55 echo "[alias] aliasedinit = init" >alias-config/.gitconfig && 56 57 GIT_CEILING_DIRECTORIES=$(pwd) && 58 export GIT_CEILING_DIRECTORIES && 59 60 mkdir plain-aliased && 61 cd plain-aliased && 62 git aliasedinit 63 ) && 64 check_config plain-aliased/.git false unset 65 ' 66 67 test_expect_success 'plain nested through aliased command' ' 68 ( 69 git init plain-ancestor-aliased && 70 cd plain-ancestor-aliased && 71 echo "[alias] aliasedinit = init" >>.git/config && 72 mkdir plain-nested && 73 cd plain-nested && 74 git aliasedinit 75 ) && 76 check_config plain-ancestor-aliased/plain-nested/.git false unset 77 ' 78 79 test_expect_success 'plain nested in bare through aliased command' ' 80 ( 81 git init --bare bare-ancestor-aliased.git && 82 cd bare-ancestor-aliased.git && 83 echo "[alias] aliasedinit = init" >>config && 84 mkdir plain-nested && 85 cd plain-nested && 86 git aliasedinit 87 ) && 88 check_config bare-ancestor-aliased.git/plain-nested/.git false unset 89 ' 90 91 test_expect_success 'No extra GIT_* on alias scripts' ' 92 write_script script <<-\EOF && 93 env | 94 sed -n \ 95 -e "/^GIT_PREFIX=/d" \ 96 -e "/^GIT_TEXTDOMAINDIR=/d" \ 97 -e "/^GIT_TRACE2_PARENT/d" \ 98 -e "/^GIT_/s/=.*//p" | 99 sort 100 EOF 101 ./script >expected && 102 git config alias.script \!./script && 103 ( mkdir sub && cd sub && git script >../actual ) && 104 test_cmp expected actual 105 ' 106 107 test_expect_success 'plain with GIT_WORK_TREE' ' 108 mkdir plain-wt && 109 test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt 110 ' 111 112 test_expect_success 'plain bare' ' 113 git --bare init plain-bare-1 && 114 check_config plain-bare-1 true unset 115 ' 116 117 test_expect_success 'plain bare with GIT_WORK_TREE' ' 118 mkdir plain-bare-2 && 119 test_must_fail \ 120 env GIT_WORK_TREE="$(pwd)/plain-bare-2" \ 121 git --bare init plain-bare-2 122 ' 123 124 test_expect_success 'GIT_DIR bare' ' 125 mkdir git-dir-bare.git && 126 GIT_DIR=git-dir-bare.git git init && 127 check_config git-dir-bare.git true unset 128 ' 129 130 test_expect_success 'init --bare' ' 131 git init --bare init-bare.git && 132 check_config init-bare.git true unset 133 ' 134 135 test_expect_success 'GIT_DIR non-bare' ' 136 137 ( 138 mkdir non-bare && 139 cd non-bare && 140 GIT_DIR=.git git init 141 ) && 142 check_config non-bare/.git false unset 143 ' 144 145 test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' ' 146 147 ( 148 mkdir git-dir-wt-1.git && 149 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init 150 ) && 151 check_config git-dir-wt-1.git false "$(pwd)" 152 ' 153 154 test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' 155 mkdir git-dir-wt-2.git && 156 test_must_fail env \ 157 GIT_WORK_TREE="$(pwd)" \ 158 GIT_DIR=git-dir-wt-2.git \ 159 git --bare init 160 ' 161 162 test_expect_success 'reinit' ' 163 164 ( 165 mkdir again && 166 cd again && 167 git -c init.defaultBranch=initial init >out1 2>err1 && 168 git init >out2 2>err2 169 ) && 170 test_grep "Initialized empty" again/out1 && 171 test_grep "Reinitialized existing" again/out2 && 172 test_must_be_empty again/err1 && 173 test_must_be_empty again/err2 174 ' 175 176 test_expect_success 'init with --template' ' 177 mkdir template-source && 178 echo content >template-source/file && 179 git init --template=template-source template-custom && 180 test_cmp template-source/file template-custom/.git/file 181 ' 182 183 test_expect_success 'init with --template (blank)' ' 184 git init template-plain && 185 test_path_is_file template-plain/.git/info/exclude && 186 git init --template= template-blank && 187 test_path_is_missing template-blank/.git/info/exclude 188 ' 189 190 init_no_templatedir_env () { 191 ( 192 sane_unset GIT_TEMPLATE_DIR && 193 NO_SET_GIT_TEMPLATE_DIR=t && 194 export NO_SET_GIT_TEMPLATE_DIR && 195 git init "$1" 196 ) 197 } 198 199 test_expect_success 'init with init.templatedir set' ' 200 mkdir templatedir-source && 201 echo Content >templatedir-source/file && 202 test_config_global init.templatedir "${HOME}/templatedir-source" && 203 204 init_no_templatedir_env templatedir-set && 205 test_cmp templatedir-source/file templatedir-set/.git/file 206 ' 207 208 test_expect_success 'init with init.templatedir using ~ expansion' ' 209 mkdir -p templatedir-source && 210 echo Content >templatedir-source/file && 211 test_config_global init.templatedir "~/templatedir-source" && 212 213 init_no_templatedir_env templatedir-expansion && 214 test_cmp templatedir-source/file templatedir-expansion/.git/file 215 ' 216 217 test_expect_success 'init --bare/--shared overrides system/global config' ' 218 test_config_global core.bare false && 219 test_config_global core.sharedRepository 0640 && 220 git init --bare --shared=0666 init-bare-shared-override && 221 check_config init-bare-shared-override true unset && 222 test x0666 = \ 223 x$(git config -f init-bare-shared-override/config core.sharedRepository) 224 ' 225 226 test_expect_success 'init honors global core.sharedRepository' ' 227 test_config_global core.sharedRepository 0666 && 228 git init shared-honor-global && 229 test x0666 = \ 230 x$(git config -f shared-honor-global/.git/config core.sharedRepository) 231 ' 232 233 test_expect_success 'init allows insanely long --template' ' 234 git init --template=$(printf "x%09999dx" 1) test 235 ' 236 237 test_expect_success 'init creates a new directory' ' 238 rm -fr newdir && 239 git init newdir && 240 test_path_is_dir newdir/.git/refs 241 ' 242 243 test_expect_success 'init creates a new bare directory' ' 244 rm -fr newdir && 245 git init --bare newdir && 246 test_path_is_dir newdir/refs 247 ' 248 249 test_expect_success 'init recreates a directory' ' 250 rm -fr newdir && 251 mkdir newdir && 252 git init newdir && 253 test_path_is_dir newdir/.git/refs 254 ' 255 256 test_expect_success 'init recreates a new bare directory' ' 257 rm -fr newdir && 258 mkdir newdir && 259 git init --bare newdir && 260 test_path_is_dir newdir/refs 261 ' 262 263 test_expect_success 'init creates a new deep directory' ' 264 rm -fr newdir && 265 git init newdir/a/b/c && 266 test_path_is_dir newdir/a/b/c/.git/refs 267 ' 268 269 test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' ' 270 rm -fr newdir && 271 ( 272 # Leading directories should honor umask while 273 # the repository itself should follow "shared" 274 mkdir newdir && 275 # Remove a default ACL if possible. 276 (setfacl -k newdir 2>/dev/null || true) && 277 umask 002 && 278 git init --bare --shared=0660 newdir/a/b/c && 279 test_path_is_dir newdir/a/b/c/refs && 280 ls -ld newdir/a newdir/a/b > lsab.out && 281 test_grep ! -v "^drwxrw[sx]r-x" lsab.out && 282 ls -ld newdir/a/b/c > lsc.out && 283 test_grep ! -v "^drwxrw[sx]---" lsc.out 284 ) 285 ' 286 287 test_expect_success 'init notices EEXIST (1)' ' 288 rm -fr newdir && 289 >newdir && 290 test_must_fail git init newdir && 291 test_path_is_file newdir 292 ' 293 294 test_expect_success 'init notices EEXIST (2)' ' 295 rm -fr newdir && 296 mkdir newdir && 297 >newdir/a && 298 test_must_fail git init newdir/a/b && 299 test_path_is_file newdir/a 300 ' 301 302 test_expect_success POSIXPERM,SANITY 'init notices EPERM' ' 303 test_when_finished "chmod +w newdir" && 304 rm -fr newdir && 305 mkdir newdir && 306 chmod -w newdir && 307 test_must_fail git init newdir/a/b 308 ' 309 310 test_expect_success 'init creates a new bare directory with global --bare' ' 311 rm -rf newdir && 312 git --bare init newdir && 313 test_path_is_dir newdir/refs 314 ' 315 316 test_expect_success 'init prefers command line to GIT_DIR' ' 317 rm -rf newdir && 318 mkdir otherdir && 319 GIT_DIR=otherdir git --bare init newdir && 320 test_path_is_dir newdir/refs && 321 test_path_is_missing otherdir/refs 322 ' 323 324 test_expect_success 'init with separate gitdir' ' 325 rm -rf newdir && 326 git init --separate-git-dir realgitdir newdir && 327 newdir_git="$(cat newdir/.git)" && 328 test_cmp_fspath "$(pwd)/realgitdir" "${newdir_git#gitdir: }" && 329 test_path_is_dir realgitdir/refs 330 ' 331 332 test_expect_success 'explicit bare & --separate-git-dir incompatible' ' 333 test_must_fail git init --bare --separate-git-dir goop.git bare.git 2>err && 334 test_grep "cannot be used together" err 335 ' 336 337 test_expect_success 'implicit bare & --separate-git-dir incompatible' ' 338 test_when_finished "rm -rf bare.git" && 339 mkdir -p bare.git && 340 test_must_fail env GIT_DIR=. \ 341 git -C bare.git init --separate-git-dir goop.git 2>err && 342 test_grep "incompatible" err 343 ' 344 345 test_expect_success 'bare & --separate-git-dir incompatible within worktree' ' 346 test_when_finished "rm -rf bare.git linkwt seprepo" && 347 test_commit gumby && 348 git clone --bare . bare.git && 349 git -C bare.git worktree add --detach ../linkwt && 350 test_must_fail git -C linkwt init --separate-git-dir seprepo 2>err && 351 test_grep "incompatible" err 352 ' 353 354 test_lazy_prereq GETCWD_IGNORES_PERMS ' 355 base=GETCWD_TEST_BASE_DIR && 356 mkdir -p $base/dir && 357 chmod 100 $base || 358 BUG "cannot prepare $base" 359 360 ( 361 cd $base/dir && 362 test-tool getcwd 363 ) 364 status=$? 365 366 chmod 700 $base && 367 rm -rf $base || 368 BUG "cannot clean $base" 369 return $status 370 ' 371 372 check_long_base_path () { 373 # exceed initial buffer size of strbuf_getcwd() 374 component=`123456789abcdef` && 375 test_when_finished "chmod 0700 $component; rm -rf $component" && 376 p31=$component/$component && 377 p127=$p31/$p31/$p31/$p31 && 378 mkdir -p $p127 && 379 if test $# = 1 380 then 381 chmod $1 $component 382 fi && 383 ( 384 cd $p127 && 385 git init newdir 386 ) 387 } 388 389 test_expect_success 'init in long base path' ' 390 check_long_base_path 391 ' 392 393 test_expect_success GETCWD_IGNORES_PERMS 'init in long restricted base path' ' 394 check_long_base_path 0111 395 ' 396 397 test_expect_success 're-init on .git file' ' 398 ( cd newdir && git init ) 399 ' 400 401 test_expect_success 're-init to update git link' ' 402 git -C newdir init --separate-git-dir ../surrealgitdir && 403 newdir_git="$(cat newdir/.git)" && 404 test_cmp_fspath "$(pwd)/surrealgitdir" "${newdir_git#gitdir: }" && 405 test_path_is_dir surrealgitdir/refs && 406 test_path_is_missing realgitdir/refs 407 ' 408 409 test_expect_success 're-init to move gitdir' ' 410 rm -rf newdir realgitdir surrealgitdir && 411 git init newdir && 412 git -C newdir init --separate-git-dir ../realgitdir && 413 newdir_git="$(cat newdir/.git)" && 414 test_cmp_fspath "$(pwd)/realgitdir" "${newdir_git#gitdir: }" && 415 test_path_is_dir realgitdir/refs 416 ' 417 418 test_expect_success SYMLINKS 're-init to move gitdir symlink' ' 419 rm -rf newdir realgitdir && 420 git init newdir && 421 ( 422 cd newdir && 423 mv .git here && 424 ln -s here .git && 425 git init --separate-git-dir ../realgitdir 426 ) && 427 echo "gitdir: $(pwd)/realgitdir" >expected && 428 case "$GIT_TEST_CMP" in 429 # `git diff --no-index` does not resolve symlinks 430 *--no-index*) cmp expected newdir/.git;; 431 *) test_cmp expected newdir/.git;; 432 esac && 433 test_cmp expected newdir/here && 434 test_path_is_dir realgitdir/refs 435 ' 436 437 sep_git_dir_worktree () { 438 test_when_finished "rm -rf mainwt linkwt seprepo" && 439 git init mainwt && 440 if test "relative" = $2 441 then 442 test_config -C mainwt worktree.useRelativePaths true 443 else 444 test_config -C mainwt worktree.useRelativePaths false 445 fi 446 test_commit -C mainwt gumby && 447 git -C mainwt worktree add --detach ../linkwt && 448 git -C "$1" init --separate-git-dir ../seprepo && 449 git -C mainwt rev-parse --git-common-dir >expect && 450 git -C linkwt rev-parse --git-common-dir >actual && 451 test_cmp expect actual 452 } 453 454 test_expect_success 're-init to move gitdir with linked worktrees (absolute)' ' 455 sep_git_dir_worktree mainwt absolute 456 ' 457 458 test_expect_success 're-init to move gitdir within linked worktree (absolute)' ' 459 sep_git_dir_worktree linkwt absolute 460 ' 461 462 test_expect_success 're-init to move gitdir with linked worktrees (relative)' ' 463 sep_git_dir_worktree mainwt relative 464 ' 465 466 test_expect_success 're-init to move gitdir within linked worktree (relative)' ' 467 sep_git_dir_worktree linkwt relative 468 ' 469 470 test_expect_success MINGW '.git hidden' ' 471 rm -rf newdir && 472 ( 473 sane_unset GIT_DIR GIT_WORK_TREE && 474 mkdir newdir && 475 cd newdir && 476 git init && 477 test_path_is_hidden .git 478 ) && 479 check_config newdir/.git false unset 480 ' 481 482 test_expect_success MINGW 'bare git dir not hidden' ' 483 rm -rf newdir && 484 ( 485 sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && 486 mkdir newdir && 487 cd newdir && 488 git --bare init 489 ) && 490 ! is_hidden newdir 491 ' 492 493 test_expect_success 'remote init from does not use config from cwd' ' 494 rm -rf newdir && 495 test_config core.logallrefupdates true && 496 git init newdir && 497 echo true >expect && 498 git -C newdir config --bool core.logallrefupdates >actual && 499 test_cmp expect actual 500 ' 501 502 test_expect_success 're-init from a linked worktree' ' 503 git init main-worktree && 504 ( 505 cd main-worktree && 506 test_commit first && 507 git worktree add ../linked-worktree && 508 mv .git/info/exclude expected-exclude && 509 cp .git/config expected-config && 510 find .git/worktrees -print | sort >expected && 511 git -C ../linked-worktree init && 512 test_cmp expected-exclude .git/info/exclude && 513 test_cmp expected-config .git/config && 514 find .git/worktrees -print | sort >actual && 515 test_cmp expected actual 516 ) 517 ' 518 519 test_expect_success 'init honors GIT_DEFAULT_HASH' ' 520 test_when_finished "rm -rf sha1 sha256" && 521 GIT_DEFAULT_HASH=sha1 git init sha1 && 522 git -C sha1 rev-parse --show-object-format >actual && 523 echo sha1 >expected && 524 test_cmp expected actual && 525 GIT_DEFAULT_HASH=sha256 git init sha256 && 526 git -C sha256 rev-parse --show-object-format >actual && 527 echo sha256 >expected && 528 test_cmp expected actual 529 ' 530 531 test_expect_success 'init honors --object-format' ' 532 test_when_finished "rm -rf explicit-sha1 explicit-sha256" && 533 git init --object-format=sha1 explicit-sha1 && 534 git -C explicit-sha1 rev-parse --show-object-format >actual && 535 echo sha1 >expected && 536 test_cmp expected actual && 537 git init --object-format=sha256 explicit-sha256 && 538 git -C explicit-sha256 rev-parse --show-object-format >actual && 539 echo sha256 >expected && 540 test_cmp expected actual 541 ' 542 543 test_expect_success 'init honors init.defaultObjectFormat' ' 544 test_when_finished "rm -rf sha1 sha256" && 545 546 test_config_global init.defaultObjectFormat sha1 && 547 ( 548 sane_unset GIT_DEFAULT_HASH && 549 git init sha1 && 550 git -C sha1 rev-parse --show-object-format >actual && 551 echo sha1 >expected && 552 test_cmp expected actual 553 ) && 554 555 test_config_global init.defaultObjectFormat sha256 && 556 ( 557 sane_unset GIT_DEFAULT_HASH && 558 git init sha256 && 559 git -C sha256 rev-parse --show-object-format >actual && 560 echo sha256 >expected && 561 test_cmp expected actual 562 ) 563 ' 564 565 test_expect_success 'init warns about invalid init.defaultObjectFormat' ' 566 test_when_finished "rm -rf repo" && 567 test_config_global init.defaultObjectFormat garbage && 568 569 echo "warning: unknown hash algorithm ${SQ}garbage${SQ}" >expect && 570 git init repo 2>err && 571 test_cmp expect err && 572 573 git -C repo rev-parse --show-object-format >actual && 574 echo $GIT_DEFAULT_HASH >expected && 575 test_cmp expected actual 576 ' 577 578 test_expect_success '--object-format overrides GIT_DEFAULT_HASH' ' 579 test_when_finished "rm -rf repo" && 580 GIT_DEFAULT_HASH=sha1 git init --object-format=sha256 repo && 581 git -C repo rev-parse --show-object-format >actual && 582 echo sha256 >expected 583 ' 584 585 test_expect_success 'GIT_DEFAULT_HASH overrides init.defaultObjectFormat' ' 586 test_when_finished "rm -rf repo" && 587 test_config_global init.defaultObjectFormat sha1 && 588 GIT_DEFAULT_HASH=sha256 git init repo && 589 git -C repo rev-parse --show-object-format >actual && 590 echo sha256 >expected 591 ' 592 593 for hash in sha1 sha256 594 do 595 test_expect_success "reinit repository with GIT_DEFAULT_HASH=$hash does not change format" ' 596 test_when_finished "rm -rf repo" && 597 git init repo && 598 git -C repo rev-parse --show-object-format >expect && 599 GIT_DEFAULT_HASH=$hash git init repo && 600 git -C repo rev-parse --show-object-format >actual && 601 test_cmp expect actual 602 ' 603 done 604 605 test_expect_success 'extensions.objectFormat is not allowed with repo version 0' ' 606 test_when_finished "rm -rf explicit-v0" && 607 git init --object-format=sha256 explicit-v0 && 608 git -C explicit-v0 config core.repositoryformatversion 0 && 609 test_must_fail git -C explicit-v0 rev-parse --show-object-format 610 ' 611 612 test_expect_success 'init rejects attempts to initialize with different hash' ' 613 test_must_fail git -C sha1 init --object-format=sha256 && 614 test_must_fail git -C sha256 init --object-format=sha1 615 ' 616 617 test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage is not allowed with repo version 0' ' 618 test_when_finished "rm -rf refstorage" && 619 git init refstorage && 620 git -C refstorage config extensions.refStorage files && 621 test_must_fail git -C refstorage rev-parse 2>err && 622 test_grep "repo version is 0, but v1-only extension found" err 623 ' 624 625 test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with files backend' ' 626 test_when_finished "rm -rf refstorage" && 627 git init refstorage && 628 git -C refstorage config core.repositoryformatversion 1 && 629 git -C refstorage config extensions.refStorage files && 630 test_commit -C refstorage A && 631 git -C refstorage rev-parse --verify HEAD 632 ' 633 634 test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown backend' ' 635 test_when_finished "rm -rf refstorage" && 636 git init refstorage && 637 git -C refstorage config core.repositoryformatversion 1 && 638 git -C refstorage config extensions.refStorage garbage && 639 test_must_fail git -C refstorage rev-parse 2>err && 640 test_grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err 641 ' 642 643 test_expect_success 'init with GIT_DEFAULT_REF_STORAGE_FORMAT=garbage' ' 644 test_when_finished "rm -rf refformat" && 645 cat >expect <<-EOF && 646 fatal: unknown ref storage format specified via GIT_DEFAULT_REF_STORAGE_FORMAT: ${SQ}garbage${SQ} 647 EOF 648 test_must_fail env GIT_DEFAULT_REF_STORAGE_FORMAT=garbage git init refformat 2>err && 649 test_cmp expect err 650 ' 651 652 test_expect_success 'GIT_REF_STORAGE_FORMAT refuses to reinitialize with different storage format' ' 653 test_when_finished "rm -rf refbackend" && 654 git init --ref-storage-format=files refbackend && 655 cat >expect <<-EOF && 656 fatal: attempt to reinitialize repository with different reference storage format 657 EOF 658 test_must_fail env GIT_REF_STORAGE_FORMAT=reftable git init refbackend 2>err && 659 test_cmp expect err 660 ' 661 662 test_expect_success 'init warns about invalid init.defaultRefStorageFormat' ' 663 test_when_finished "rm -rf repo" && 664 test_config_global init.defaultRefStorageFormat garbage && 665 666 echo "warning: unknown ref storage format ${SQ}garbage${SQ}" >expect && 667 git init repo 2>err && 668 test_cmp expect err && 669 670 git -C repo rev-parse --show-ref-storage-format >actual && 671 echo $GIT_DEFAULT_REF_STORAGE_FORMAT >expected && 672 test_cmp expected actual 673 ' 674 675 test_expect_success 'default ref format' ' 676 test_when_finished "rm -rf refformat" && 677 ( 678 sane_unset GIT_DEFAULT_REF_STORAGE_FORMAT && 679 git init refformat 680 ) && 681 git version --build-options >build-options && 682 sed -ne "s/^default-ref-storage-format: //p" build-options >expect && 683 git -C refformat rev-parse --show-ref-storage-format >actual && 684 test_cmp expect actual 685 ' 686 687 backends="files reftable" 688 for format in $backends 689 do 690 test_expect_success DEFAULT_REPO_FORMAT "init with GIT_DEFAULT_REF_STORAGE_FORMAT=$format" ' 691 test_when_finished "rm -rf refformat" && 692 GIT_DEFAULT_REF_STORAGE_FORMAT=$format git init refformat && 693 694 if test $format = files 695 then 696 test_must_fail git -C refformat config extensions.refstorage && 697 echo 0 >expect 698 else 699 git -C refformat config extensions.refstorage && 700 echo 1 >expect 701 fi && 702 git -C refformat config core.repositoryformatversion >actual && 703 test_cmp expect actual && 704 705 echo $format >expect && 706 git -C refformat rev-parse --show-ref-storage-format >actual && 707 test_cmp expect actual 708 ' 709 710 test_expect_success "init with --ref-storage-format=$format" ' 711 test_when_finished "rm -rf refformat" && 712 git init --ref-storage-format=$format refformat && 713 echo $format >expect && 714 git -C refformat rev-parse --show-ref-storage-format >actual && 715 test_cmp expect actual 716 ' 717 718 test_expect_success "init with init.defaultRefStorageFormat=$format" ' 719 test_when_finished "rm -rf refformat" && 720 test_config_global init.defaultRefStorageFormat $format && 721 ( 722 sane_unset GIT_DEFAULT_REF_STORAGE_FORMAT && 723 git init refformat 724 ) && 725 726 echo $format >expect && 727 git -C refformat rev-parse --show-ref-storage-format >actual && 728 test_cmp expect actual 729 ' 730 731 test_expect_success "--ref-storage-format=$format overrides GIT_DEFAULT_REF_STORAGE_FORMAT" ' 732 test_when_finished "rm -rf refformat" && 733 GIT_DEFAULT_REF_STORAGE_FORMAT=garbage git init --ref-storage-format=$format refformat && 734 echo $format >expect && 735 git -C refformat rev-parse --show-ref-storage-format >actual && 736 test_cmp expect actual 737 ' 738 739 test_expect_success "reinit repository with GIT_DEFAULT_REF_STORAGE_FORMAT=$format does not change format" ' 740 test_when_finished "rm -rf refformat" && 741 git init refformat && 742 git -C refformat rev-parse --show-ref-storage-format >expect && 743 GIT_DEFAULT_REF_STORAGE_FORMAT=$format git init refformat && 744 git -C refformat rev-parse --show-ref-storage-format >actual && 745 test_cmp expect actual 746 ' 747 done 748 749 test_expect_success "--ref-storage-format= overrides GIT_DEFAULT_REF_STORAGE_FOMAT" ' 750 test_when_finished "rm -rf refformat" && 751 GIT_DEFAULT_REF_STORAGE_FORMAT=files git init --ref-storage-format=reftable refformat && 752 echo reftable >expect && 753 git -C refformat rev-parse --show-ref-storage-format >actual && 754 test_cmp expect actual 755 ' 756 757 test_expect_success "GIT_DEFAULT_REF_STORAGE_FORMAT= overrides init.defaultRefStorageFormat" ' 758 test_when_finished "rm -rf refformat" && 759 test_config_global init.defaultRefStorageFormat files && 760 761 GIT_DEFAULT_REF_STORAGE_FORMAT=reftable git init refformat && 762 echo reftable >expect && 763 git -C refformat rev-parse --show-ref-storage-format >actual && 764 test_cmp expect actual 765 ' 766 767 test_expect_success "init with feature.experimental=true" ' 768 test_when_finished "rm -rf refformat" && 769 test_config_global feature.experimental true && 770 ( 771 sane_unset GIT_DEFAULT_REF_STORAGE_FORMAT && 772 git init refformat 773 ) && 774 echo reftable >expect && 775 git -C refformat rev-parse --show-ref-storage-format >actual && 776 test_cmp expect actual 777 ' 778 779 test_expect_success "init.defaultRefStorageFormat overrides feature.experimental=true" ' 780 test_when_finished "rm -rf refformat" && 781 test_config_global feature.experimental true && 782 test_config_global init.defaultRefStorageFormat files && 783 ( 784 sane_unset GIT_DEFAULT_REF_STORAGE_FORMAT && 785 git init refformat 786 ) && 787 echo files >expect && 788 git -C refformat rev-parse --show-ref-storage-format >actual && 789 test_cmp expect actual 790 ' 791 792 test_expect_success "GIT_DEFAULT_REF_STORAGE_FORMAT= overrides feature.experimental=true" ' 793 test_when_finished "rm -rf refformat" && 794 test_config_global feature.experimental true && 795 GIT_DEFAULT_REF_STORAGE_FORMAT=files git init refformat && 796 echo files >expect && 797 git -C refformat rev-parse --show-ref-storage-format >actual && 798 test_cmp expect actual 799 ' 800 801 for from_format in $backends 802 do 803 test_expect_success "re-init with same format ($from_format)" ' 804 test_when_finished "rm -rf refformat" && 805 git init --ref-storage-format=$from_format refformat && 806 git init --ref-storage-format=$from_format refformat && 807 echo $from_format >expect && 808 git -C refformat rev-parse --show-ref-storage-format >actual && 809 test_cmp expect actual 810 ' 811 812 for to_format in $backends 813 do 814 if test "$from_format" = "$to_format" 815 then 816 continue 817 fi 818 819 test_expect_success "re-init with different format fails ($from_format -> $to_format)" ' 820 test_when_finished "rm -rf refformat" && 821 git init --ref-storage-format=$from_format refformat && 822 cat >expect <<-EOF && 823 fatal: attempt to reinitialize repository with different reference storage format 824 EOF 825 test_must_fail git init --ref-storage-format=$to_format refformat 2>err && 826 test_cmp expect err && 827 echo $from_format >expect && 828 git -C refformat rev-parse --show-ref-storage-format >actual && 829 test_cmp expect actual 830 ' 831 done 832 done 833 834 test_expect_success 'init with --ref-storage-format=garbage' ' 835 test_when_finished "rm -rf refformat" && 836 cat >expect <<-EOF && 837 fatal: unknown ref storage format specified via command line: ${SQ}garbage${SQ} 838 EOF 839 test_must_fail git init --ref-storage-format=garbage refformat 2>err && 840 test_cmp expect err 841 ' 842 843 test_expect_success DEFAULT_REPO_FORMAT 'extensions.objectStorage is not allowed with repo version 0' ' 844 test_when_finished "rm -rf objstorage" && 845 git init objstorage && 846 git -C objstorage config set extensions.objectStorage files && 847 test_must_fail git -C objstorage rev-parse 2>err && 848 test_grep "repo version is 0, but v1-only extension found" err 849 ' 850 851 test_expect_success DEFAULT_REPO_FORMAT 'extensions.objectStorage with files backend' ' 852 test_when_finished "rm -rf objstorage" && 853 git init objstorage && 854 git -C objstorage config set core.repositoryformatversion 1 && 855 git -C objstorage config set extensions.objectStorage files && 856 test_commit -C objstorage A && 857 git -C objstorage rev-parse --verify HEAD && 858 echo files >expect && 859 git -C objstorage rev-parse --show-object-storage-format >actual && 860 test_cmp expect actual 861 ' 862 863 test_expect_success DEFAULT_REPO_FORMAT 'extensions.objectStorage with unknown backend' ' 864 test_when_finished "rm -rf objstorage" && 865 git init objstorage && 866 git -C objstorage config set core.repositoryformatversion 1 && 867 git -C objstorage config set extensions.objectStorage garbage && 868 test_must_fail git -C objstorage rev-parse 2>err && 869 test_grep "invalid value for ${SQ}extensions.objectstorage${SQ}: ${SQ}garbage${SQ}" err && 870 871 git config --file objstorage/.git/config extensions.objectStorage garbage://payload && 872 test_must_fail git -C objstorage rev-parse 2>err && 873 test_grep "invalid value for ${SQ}extensions.objectstorage${SQ}: ${SQ}garbage://payload${SQ}" err 874 ' 875 876 test_expect_success DEFAULT_REPO_FORMAT 'GIT_OBJECT_STORAGE_FORMAT overrides extensions.objectStorage' ' 877 test_when_finished "rm -rf objstorage" && 878 git init objstorage && 879 ( 880 cd objstorage && 881 git config set core.repositoryformatversion 1 && 882 git config set extensions.objectStorage files://objs && 883 mkdir .git/objs .git/other && 884 885 echo content >file && 886 oid=$(git hash-object -w file) && 887 test_path_is_file .git/objs/$(test_oid_to_path "$oid") && 888 git cat-file -e "$oid" && 889 890 test_must_fail env GIT_OBJECT_STORAGE_FORMAT=files://other git cat-file -e "$oid" && 891 GIT_OBJECT_STORAGE_FORMAT=files://other git hash-object -w file && 892 test_path_is_file .git/other/$(test_oid_to_path "$oid") && 893 894 cat >expect <<-EOF && 895 fatal: unknown object storage format: ${SQ}garbage${SQ} 896 EOF 897 test_must_fail env GIT_OBJECT_STORAGE_FORMAT=garbage git rev-parse 2>err && 898 test_cmp expect err 899 ) 900 ' 901 902 test_expect_success 'init with --object-storage-format=files does not set extension' ' 903 test_when_finished "rm -rf objformat" && 904 git init --object-storage-format=files objformat && 905 test_must_fail git -C objformat config get extensions.objectstorage && 906 echo files >expect && 907 git -C objformat rev-parse --show-object-storage-format >actual && 908 test_cmp expect actual && 909 if test_have_prereq DEFAULT_REPO_FORMAT 910 then 911 echo 0 >expect && 912 git -C objformat config get core.repositoryformatversion >actual && 913 test_cmp expect actual 914 fi 915 ' 916 917 test_expect_success 'init with --object-storage-format=files:// does not set extension' ' 918 test_when_finished "rm -rf objformat" && 919 git init --object-storage-format=files:// objformat && 920 test_must_fail git -C objformat config get extensions.objectstorage && 921 echo files >expect && 922 git -C objformat rev-parse --show-object-storage-format >actual && 923 test_cmp expect actual 924 ' 925 926 test_expect_success 'init with --object-storage-format=files://' ' 927 test_when_finished "rm -rf objformat" && 928 git init --object-storage-format=files://objs objformat && 929 echo files://objs >expect && 930 git -C objformat config get extensions.objectstorage >actual && 931 test_cmp expect actual && 932 echo 1 >expect && 933 git -C objformat config get core.repositoryformatversion >actual && 934 test_cmp expect actual && 935 git -C objformat rev-parse --show-object-storage-format >actual && 936 echo files://objs >expect && 937 test_cmp expect actual && 938 test_path_is_dir objformat/.git/objects && 939 test_path_is_dir objformat/.git/objs && 940 test_commit -C objformat A && 941 git -C objformat rev-parse --verify HEAD && 942 test_path_is_missing objformat/.git/objects/pack && 943 test_path_is_dir objformat/.git/objs/pack 944 ' 945 946 test_expect_success 'init with --object-storage-format=files://' ' 947 test_when_finished "rm -rf objformat objdir" && 948 git init --object-storage-format=files://"$(pwd)/objdir" objformat && 949 echo "files://$(pwd)/objdir" >expect && 950 git -C objformat config get extensions.objectstorage >actual && 951 test_cmp expect actual && 952 test_commit -C objformat A && 953 git -C objformat rev-parse --verify HEAD && 954 test_path_is_dir objdir/pack 955 ' 956 957 test_expect_success 'GIT_OBJECT_DIRECTORY takes precedence over extensions.objectStorage payload' ' 958 test_when_finished "rm -rf objformat objdir" && 959 git init --object-storage-format=files://objs objformat && 960 test_commit -C objformat A && 961 mkdir objdir && 962 test_must_fail env GIT_DIR="$PWD/objformat/.git" GIT_OBJECT_DIRECTORY="$PWD/objdir" \ 963 git cat-file -e HEAD && 964 GIT_DIR="$PWD/objformat/.git" GIT_OBJECT_DIRECTORY="$PWD/objdir" \ 965 git hash-object -w objformat/A.t >oid && 966 test_path_is_file objdir/$(test_oid_to_path "$(cat oid)") 967 ' 968 969 test_expect_success 'init with --object-storage-format=garbage' ' 970 test_when_finished "rm -rf objformat" && 971 cat >expect <<-EOF && 972 fatal: unknown object storage format specified via command line: ${SQ}garbage${SQ} 973 EOF 974 test_must_fail git init --object-storage-format=garbage objformat 2>err && 975 test_cmp expect err 976 ' 977 978 test_expect_success 'init with GIT_DEFAULT_OBJECT_STORAGE_FORMAT=garbage' ' 979 test_when_finished "rm -rf objformat" && 980 cat >expect <<-EOF && 981 fatal: unknown object storage format specified via GIT_DEFAULT_OBJECT_STORAGE_FORMAT: ${SQ}garbage${SQ} 982 EOF 983 test_must_fail env GIT_DEFAULT_OBJECT_STORAGE_FORMAT=garbage git init objformat 2>err && 984 test_cmp expect err 985 ' 986 987 test_expect_success 'init with GIT_OBJECT_STORAGE_FORMAT=garbage' ' 988 test_when_finished "rm -rf objformat" && 989 cat >expect <<-EOF && 990 fatal: unknown object storage format specified via GIT_OBJECT_STORAGE_FORMAT: ${SQ}garbage${SQ} 991 EOF 992 test_must_fail env GIT_OBJECT_STORAGE_FORMAT=garbage git init objformat 2>err && 993 test_cmp expect err 994 ' 995 996 test_expect_success 'GIT_OBJECT_STORAGE_FORMAT takes precedence over default' ' 997 test_when_finished "rm -rf objformat" && 998 GIT_DEFAULT_OBJECT_STORAGE_FORMAT=files://default \ 999 GIT_OBJECT_STORAGE_FORMAT=files://explicit git init objformat && 1000 echo files://explicit >expect && 1001 git -C objformat rev-parse --show-object-storage-format >actual && 1002 test_cmp expect actual 1003 ' 1004 1005 test_expect_success '--object-storage-format= takes precedence over environment' ' 1006 test_when_finished "rm -rf objformat" && 1007 GIT_OBJECT_STORAGE_FORMAT=files://explicit \ 1008 git init --object-storage-format=files://cmdline objformat && 1009 echo files://cmdline >expect && 1010 git -C objformat rev-parse --show-object-storage-format >actual && 1011 test_cmp expect actual 1012 ' 1013 1014 test_expect_success 're-init refuses with different storage format' ' 1015 test_when_finished "rm -rf objformat" && 1016 git init --object-storage-format=files objformat && 1017 cat >expect <<-EOF && 1018 fatal: attempt to reinitialize repository with different object storage payload 1019 EOF 1020 test_must_fail env GIT_OBJECT_STORAGE_FORMAT=files://objs git init objformat 2>err && 1021 test_cmp expect err 1022 ' 1023 1024 test_expect_success 're-init with same object storage format' ' 1025 test_when_finished "rm -rf objformat" && 1026 git init --object-storage-format=files://objs objformat && 1027 git init --object-storage-format=files://objs objformat && 1028 git init objformat && 1029 echo files://objs >expect && 1030 git -C objformat rev-parse --show-object-storage-format >actual && 1031 test_cmp expect actual 1032 ' 1033 1034 test_expect_success DEFAULT_REPO_FORMAT 're-init with default object storage format drops extension' ' 1035 test_when_finished "rm -rf objformat" && 1036 1037 git init objformat && 1038 git -C objformat config set core.repositoryformatversion 1 && 1039 git -C objformat config set extensions.objectstorage files && 1040 1041 git init --object-storage-format=files objformat && 1042 echo 0 >expect && 1043 git -C objformat config get core.repositoryformatversion >actual && 1044 test_cmp expect actual && 1045 test_must_fail git -C objformat config get extensions.objectstorage 1046 ' 1047 1048 test_expect_success 'init warns about invalid init.defaultObjectStorageFormat' ' 1049 test_when_finished "rm -rf objformat" && 1050 test_config_global init.defaultObjectStorageFormat garbage && 1051 echo "warning: unknown object storage format ${SQ}garbage${SQ}" >expect && 1052 git init objformat 2>err && 1053 test_cmp expect err && 1054 echo files >expect && 1055 git -C objformat rev-parse --show-object-storage-format >actual && 1056 test_cmp expect actual 1057 ' 1058 1059 test_expect_success 'init with init.defaultObjectStorageFormat' ' 1060 test_when_finished "rm -rf objformat" && 1061 test_config_global init.defaultObjectStorageFormat files && 1062 git init objformat && 1063 echo files >expect && 1064 git -C objformat rev-parse --show-object-storage-format >actual && 1065 test_cmp expect actual 1066 ' 1067 1068 test_expect_success MINGW 'core.hidedotfiles = false' ' 1069 git config --global core.hidedotfiles false && 1070 rm -rf newdir && 1071 mkdir newdir && 1072 ( 1073 sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && 1074 git -C newdir init 1075 ) && 1076 ! is_hidden newdir/.git 1077 ' 1078 1079 test_expect_success MINGW 'redirect std handles' ' 1080 GIT_REDIRECT_STDOUT=output.txt git rev-parse --git-dir && 1081 test .git = "$(cat output.txt)" && 1082 test -z "$(GIT_REDIRECT_STDOUT=off git rev-parse --git-dir)" && 1083 test_must_fail env \ 1084 GIT_REDIRECT_STDOUT=output.txt \ 1085 GIT_REDIRECT_STDERR="2>&1" \ 1086 git rev-parse --git-dir --verify refs/invalid && 1087 test_grep "^\\.git\$" output.txt && 1088 test_grep "Needed a single revision" output.txt 1089 ' 1090 1091 test_expect_success '--initial-branch' ' 1092 git init --initial-branch=hello initial-branch-option && 1093 git -C initial-branch-option symbolic-ref HEAD >actual && 1094 echo refs/heads/hello >expect && 1095 test_cmp expect actual && 1096 1097 : re-initializing should not change the branch name && 1098 git init --initial-branch=ignore initial-branch-option 2>err && 1099 test_grep "ignored --initial-branch" err && 1100 git -C initial-branch-option symbolic-ref HEAD >actual && 1101 test_grep hello actual 1102 ' 1103 1104 test_expect_success 'overridden default initial branch name (config)' ' 1105 test_config_global init.defaultBranch nmb && 1106 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git init initial-branch-config && 1107 git -C initial-branch-config symbolic-ref HEAD >actual && 1108 test_grep nmb actual 1109 ' 1110 1111 test_expect_success 'advice on unconfigured init.defaultBranch' ' 1112 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \ 1113 init unconfigured-default-branch-name 2>err && 1114 test_decode_color decoded && 1115 test_grep "hint: " decoded 1116 ' 1117 1118 test_expect_success 'advice on unconfigured init.defaultBranch disabled' ' 1119 test_when_finished "rm -rf no-advice" && 1120 1121 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ 1122 git -c advice.defaultBranchName=false init no-advice 2>err && 1123 test_grep ! "hint: " err 1124 ' 1125 1126 test_expect_success 'default branch name' ' 1127 if test_have_prereq WITH_BREAKING_CHANGES 1128 then 1129 expect=main 1130 else 1131 expect=master 1132 fi && 1133 echo "refs/heads/$expect" >expect && 1134 ( 1135 sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME && 1136 git init default-initial-branch-name 1137 ) && 1138 git -C default-initial-branch-name symbolic-ref HEAD >actual && 1139 test_cmp expect actual 1140 ' 1141 1142 test_expect_success 'overridden default main branch name (env)' ' 1143 test_config_global init.defaultBranch nmb && 1144 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env && 1145 git -C main-branch-env symbolic-ref HEAD >actual && 1146 test_grep env actual 1147 ' 1148 1149 test_expect_success 'invalid default branch name' ' 1150 test_must_fail env GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME="with space" \ 1151 git init initial-branch-invalid 2>err && 1152 test_grep "invalid branch name" err 1153 ' 1154 1155 test_expect_success 'branch -m with the initial branch' ' 1156 git init rename-initial && 1157 git -C rename-initial branch -m renamed && 1158 echo renamed >expect && 1159 git -C rename-initial symbolic-ref --short HEAD >actual && 1160 test_cmp expect actual && 1161 1162 git -C rename-initial branch -m renamed again && 1163 echo again >expect && 1164 git -C rename-initial symbolic-ref --short HEAD >actual && 1165 test_cmp expect actual 1166 ' 1167 1168 test_expect_success 'init with includeIf.onbranch condition' ' 1169 test_when_finished "rm -rf repo" && 1170 git -c includeIf.onbranch:main.path=nonexistent init repo && 1171 echo $GIT_DEFAULT_REF_STORAGE_FORMAT >expect && 1172 git -C repo rev-parse --show-ref-storage-format >actual && 1173 test_cmp expect actual 1174 ' 1175 1176 test_expect_success 'init with includeIf.onbranch condition with existing directory' ' 1177 test_when_finished "rm -rf repo" && 1178 mkdir repo && 1179 git -c includeIf.onbranch:nonexistent.path=/does/not/exist init repo && 1180 echo $GIT_DEFAULT_REF_STORAGE_FORMAT >expect && 1181 git -C repo rev-parse --show-ref-storage-format >actual && 1182 test_cmp expect actual 1183 ' 1184 1185 test_expect_success 're-init with includeIf.onbranch condition' ' 1186 test_when_finished "rm -rf repo" && 1187 git init repo && 1188 git -c includeIf.onbranch:nonexistent.path=/does/not/exist init repo && 1189 echo $GIT_DEFAULT_REF_STORAGE_FORMAT >expect && 1190 git -C repo rev-parse --show-ref-storage-format >actual && 1191 test_cmp expect actual 1192 ' 1193 1194 test_expect_success 're-init skips non-matching includeIf.onbranch' ' 1195 test_when_finished "rm -rf repo config" && 1196 cat >config <<-EOF && 1197 [ 1198 garbage 1199 EOF 1200 git init repo && 1201 git -c includeIf.onbranch:nonexistent.path="$(test-tool path-utils absolute_path config)" init repo 1202 ' 1203 1204 test_expect_success 're-init reads matching includeIf.onbranch' ' 1205 test_when_finished "rm -rf repo config" && 1206 cat >config <<-EOF && 1207 [ 1208 garbage 1209 EOF 1210 path="$(test-tool path-utils absolute_path config)" && 1211 git init --initial-branch=branch repo && 1212 cat >expect <<-EOF && 1213 fatal: bad config line 1 in file $path 1214 EOF 1215 test_must_fail git -c includeIf.onbranch:branch.path="$path" init repo 2>err && 1216 test_cmp expect err 1217 ' 1218 1219 test_expect_success 'init honors GIT_OBJECT_DIRECTORY' ' 1220 test_when_finished "rm -rf init-objdir custom-odb" && 1221 mkdir custom-odb && 1222 env GIT_OBJECT_DIRECTORY="$(pwd)/custom-odb" \ 1223 git init init-objdir && 1224 test_path_is_missing init-objdir/.git/objects/pack && 1225 test_path_is_dir custom-odb/pack && 1226 test_path_is_dir custom-odb/info 1227 ' 1228 1229 test_expect_success 'init shows absolute path to gitdir' ' 1230 echo "Initialized empty Git repository in $(pwd)/init-path/.git/" >expect && 1231 git init init-path >actual && 1232 test_cmp expect actual 1233 ' 1234 1235 test_done