Git fork
at reftables-rust 1508 lines 42 kB view raw
1#!/bin/sh 2# 3# Copyright (c) 2007 Lars Hjemli 4# 5 6test_description='Basic porcelain support for submodules 7 8This test tries to verify basic sanity of the init, update and status 9subcommands of git submodule. 10' 11 12GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 13export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 14 15. ./test-lib.sh 16 17test_expect_success 'setup - enable local submodules' ' 18 git config --global protocol.file.allow always 19' 20 21test_expect_success 'submodule usage: -h' ' 22 git submodule -h >out 2>err && 23 grep "^usage: git submodule" out && 24 test_must_be_empty err 25' 26 27test_expect_success 'submodule usage: --recursive' ' 28 test_expect_code 1 git submodule --recursive >out 2>err && 29 grep "^usage: git submodule" err && 30 test_must_be_empty out 31' 32 33test_expect_success 'submodule usage: status --' ' 34 test_expect_code 1 git submodule -- && 35 test_expect_code 1 git submodule --end-of-options 36' 37 38for opt in '--quiet' '--cached' 39do 40 test_expect_success "submodule usage: status $opt" ' 41 git submodule $opt && 42 git submodule status $opt && 43 git submodule $opt status 44 ' 45done 46 47test_expect_success 'submodule deinit works on empty repository' ' 48 git submodule deinit --all 49' 50 51test_expect_success 'setup - initial commit' ' 52 >t && 53 git add t && 54 git commit -m "initial commit" && 55 git branch initial 56' 57 58test_expect_success 'submodule init aborts on missing .gitmodules file' ' 59 test_when_finished "git update-index --remove sub" && 60 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && 61 # missing the .gitmodules file here 62 test_must_fail git submodule init 2>actual && 63 test_grep "No url found for submodule path" actual 64' 65 66test_expect_success 'submodule update aborts on missing .gitmodules file' ' 67 test_when_finished "git update-index --remove sub" && 68 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && 69 # missing the .gitmodules file here 70 git submodule update sub 2>actual && 71 test_grep "Submodule path .sub. not initialized" actual 72' 73 74test_expect_success 'submodule update aborts on missing gitmodules url' ' 75 test_when_finished "git update-index --remove sub" && 76 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && 77 test_when_finished "rm -f .gitmodules" && 78 git config -f .gitmodules submodule.s.path sub && 79 test_must_fail git submodule init 80' 81 82test_expect_success 'add aborts on repository with no commits' ' 83 cat >expect <<-\EOF && 84 fatal: '"'repo-no-commits'"' does not have a commit checked out 85 EOF 86 git init repo-no-commits && 87 test_must_fail git submodule add ../a ./repo-no-commits 2>actual && 88 test_cmp expect actual 89' 90 91test_expect_success 'status should ignore inner git repo when not added' ' 92 rm -fr inner && 93 mkdir inner && 94 ( 95 cd inner && 96 git init && 97 >t && 98 git add t && 99 git commit -m "initial" 100 ) && 101 test_must_fail git submodule status inner 2>output.err && 102 rm -fr inner && 103 test_grep "^error: .*did not match any file(s) known to git" output.err 104' 105 106test_expect_success 'setup - repository in init subdirectory' ' 107 mkdir init && 108 ( 109 cd init && 110 git init && 111 echo a >a && 112 git add a && 113 git commit -m "submodule commit 1" && 114 git tag -a -m "rev-1" rev-1 115 ) 116' 117 118test_expect_success 'setup - commit with gitlink' ' 119 echo a >a && 120 echo z >z && 121 git add a init z && 122 git commit -m "super commit 1" 123' 124 125test_expect_success 'setup - hide init subdirectory' ' 126 mv init .subrepo 127' 128 129test_expect_success 'setup - repository to add submodules to' ' 130 git init addtest && 131 git init addtest-ignore 132' 133 134# The 'submodule add' tests need some repository to add as a submodule. 135# The trash directory is a good one as any. We need to canonicalize 136# the name, though, as some tests compare it to the absolute path git 137# generates, which will expand symbolic links. 138submodurl=$(pwd -P) 139 140listbranches() { 141 git for-each-ref --format='%(refname)' 'refs/heads/*' 142} 143 144inspect() { 145 dir=$1 && 146 dotdot="${2:-..}" && 147 148 ( 149 cd "$dir" && 150 listbranches >"$dotdot/heads" && 151 { git symbolic-ref HEAD || :; } >"$dotdot/head" && 152 git rev-parse HEAD >"$dotdot/head-sha1" && 153 git update-index --refresh && 154 git diff-files --exit-code && 155 git clean -n -d -x >"$dotdot/untracked" 156 ) 157} 158 159test_expect_success 'submodule add' ' 160 echo "refs/heads/main" >expect && 161 162 ( 163 cd addtest && 164 git submodule add -q "$submodurl" submod >actual && 165 test_must_be_empty actual && 166 echo "gitdir: ../.git/modules/submod" >expect && 167 test_cmp expect submod/.git && 168 ( 169 cd submod && 170 git config core.worktree >actual && 171 echo "../../../submod" >expect && 172 test_cmp expect actual && 173 rm -f actual expect 174 ) && 175 git submodule init 176 ) && 177 178 rm -f heads head untracked && 179 inspect addtest/submod ../.. && 180 test_cmp expect heads && 181 test_cmp expect head && 182 test_must_be_empty untracked 183' 184 185test_expect_success !WINDOWS 'submodule add (absolute path)' ' 186 test_when_finished "git reset --hard" && 187 git submodule add "$submodurl" "$submodurl/add-abs" 188' 189 190test_expect_success 'setup parent and one repository' ' 191 test_create_repo parent && 192 test_commit -C parent one 193' 194 195test_expect_success 'redirected submodule add does not show progress' ' 196 git -C addtest submodule add "file://$submodurl/parent" submod-redirected \ 197 2>err && 198 ! grep % err && 199 test_grep ! "Checking connectivity" err 200' 201 202test_expect_success 'redirected submodule add --progress does show progress' ' 203 git -C addtest submodule add --progress "file://$submodurl/parent" \ 204 submod-redirected-progress 2>err && \ 205 grep % err 206' 207 208test_expect_success 'submodule add to .gitignored path fails' ' 209 ( 210 cd addtest-ignore && 211 cat <<-\EOF >expect && 212 The following paths are ignored by one of your .gitignore files: 213 submod 214 hint: Use -f if you really want to add them. 215 hint: Disable this message with "git config set advice.addIgnoredFile false" 216 EOF 217 # Does not use test_commit due to the ignore 218 echo "*" > .gitignore && 219 git add --force .gitignore && 220 git commit -m"Ignore everything" && 221 ! git submodule add "$submodurl" submod >actual 2>&1 && 222 test_cmp expect actual 223 ) 224' 225 226test_expect_success 'submodule add to .gitignored path with --force' ' 227 ( 228 cd addtest-ignore && 229 git submodule add --force "$submodurl" submod 230 ) 231' 232 233test_expect_success 'submodule add to path with tracked content fails' ' 234 ( 235 cd addtest && 236 echo "fatal: '\''dir-tracked'\'' already exists in the index" >expect && 237 mkdir dir-tracked && 238 test_commit foo dir-tracked/bar && 239 test_must_fail git submodule add "$submodurl" dir-tracked >actual 2>&1 && 240 test_cmp expect actual 241 ) 242' 243 244test_expect_success 'submodule add to reconfigure existing submodule with --force' ' 245 ( 246 cd addtest-ignore && 247 bogus_url="$(pwd)/bogus-url" && 248 git submodule add --force "$bogus_url" submod && 249 git submodule add --force -b initial "$submodurl" submod-branch && 250 test "$bogus_url" = "$(git config -f .gitmodules submodule.submod.url)" && 251 test "$bogus_url" = "$(git config submodule.submod.url)" && 252 # Restore the url 253 git submodule add --force "$submodurl" submod && 254 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" && 255 test "$submodurl" = "$(git config submodule.submod.url)" 256 ) 257' 258 259test_expect_success 'submodule add relays add --dry-run stderr' ' 260 test_when_finished "rm -rf addtest/.git/index.lock" && 261 ( 262 cd addtest && 263 : >.git/index.lock && 264 ! git submodule add "$submodurl" sub-while-locked 2>output.err && 265 test_grep "^fatal: .*index\.lock" output.err && 266 test_path_is_missing sub-while-locked 267 ) 268' 269 270test_expect_success 'submodule add --branch' ' 271 echo "refs/heads/initial" >expect-head && 272 cat <<-\EOF >expect-heads && 273 refs/heads/initial 274 refs/heads/main 275 EOF 276 277 ( 278 cd addtest && 279 git submodule add -b initial "$submodurl" submod-branch && 280 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" && 281 git submodule init 282 ) && 283 284 rm -f heads head untracked && 285 inspect addtest/submod-branch ../.. && 286 test_cmp expect-heads heads && 287 test_cmp expect-head head && 288 test_must_be_empty untracked 289' 290 291test_expect_success 'submodule add with ./ in path' ' 292 echo "refs/heads/main" >expect && 293 294 ( 295 cd addtest && 296 git submodule add "$submodurl" ././dotsubmod/./frotz/./ && 297 git submodule init 298 ) && 299 300 rm -f heads head untracked && 301 inspect addtest/dotsubmod/frotz ../../.. && 302 test_cmp expect heads && 303 test_cmp expect head && 304 test_must_be_empty untracked 305' 306 307test_expect_success 'submodule add with /././ in path' ' 308 echo "refs/heads/main" >expect && 309 310 ( 311 cd addtest && 312 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ && 313 git submodule init 314 ) && 315 316 rm -f heads head untracked && 317 inspect addtest/dotslashdotsubmod/frotz ../../.. && 318 test_cmp expect heads && 319 test_cmp expect head && 320 test_must_be_empty untracked 321' 322 323test_expect_success 'submodule add with // in path' ' 324 echo "refs/heads/main" >expect && 325 326 ( 327 cd addtest && 328 git submodule add "$submodurl" slashslashsubmod///frotz// && 329 git submodule init 330 ) && 331 332 rm -f heads head untracked && 333 inspect addtest/slashslashsubmod/frotz ../../.. && 334 test_cmp expect heads && 335 test_cmp expect head && 336 test_must_be_empty untracked 337' 338 339test_expect_success 'submodule add with /.. in path' ' 340 echo "refs/heads/main" >expect && 341 342 ( 343 cd addtest && 344 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. && 345 git submodule init 346 ) && 347 348 rm -f heads head untracked && 349 inspect addtest/realsubmod ../.. && 350 test_cmp expect heads && 351 test_cmp expect head && 352 test_must_be_empty untracked 353' 354 355test_expect_success 'submodule add with ./, /.. and // in path' ' 356 echo "refs/heads/main" >expect && 357 358 ( 359 cd addtest && 360 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. && 361 git submodule init 362 ) && 363 364 rm -f heads head untracked && 365 inspect addtest/realsubmod2 ../.. && 366 test_cmp expect heads && 367 test_cmp expect head && 368 test_must_be_empty untracked 369' 370 371test_expect_success !CYGWIN 'submodule add with \\ in path' ' 372 test_when_finished "rm -rf parent sub\\with\\backslash" && 373 374 # Initialize a repo with a backslash in its name 375 git init sub\\with\\backslash && 376 touch sub\\with\\backslash/empty.file && 377 git -C sub\\with\\backslash add empty.file && 378 git -C sub\\with\\backslash commit -m "Added empty.file" && 379 380 # Add that repository as a submodule 381 git init parent && 382 git -C parent submodule add ../sub\\with\\backslash 383' 384 385test_expect_success 'submodule add in subdirectory' ' 386 echo "refs/heads/main" >expect && 387 388 mkdir addtest/sub && 389 ( 390 cd addtest/sub && 391 git submodule add "$submodurl" ../realsubmod3 && 392 git submodule init 393 ) && 394 395 rm -f heads head untracked && 396 inspect addtest/realsubmod3 ../.. && 397 test_cmp expect heads && 398 test_cmp expect head && 399 test_must_be_empty untracked 400' 401 402test_expect_success 'submodule add in subdirectory with relative path should fail' ' 403 ( 404 cd addtest/sub && 405 test_must_fail git submodule add ../../ submod3 2>../../output.err 406 ) && 407 test_grep toplevel output.err 408' 409 410test_expect_success 'setup - add an example entry to .gitmodules' ' 411 git config --file=.gitmodules submodule.example.url git://example.com/init.git 412' 413 414test_expect_success 'status should fail for unmapped paths' ' 415 test_must_fail git submodule status 416' 417 418test_expect_success 'setup - map path in .gitmodules' ' 419 cat <<\EOF >expect && 420[submodule "example"] 421 url = git://example.com/init.git 422 path = init 423EOF 424 425 git config --file=.gitmodules submodule.example.path init && 426 427 test_cmp expect .gitmodules 428' 429 430test_expect_success 'status should only print one line' ' 431 git submodule status >lines && 432 test_line_count = 1 lines 433' 434 435test_expect_success 'status from subdirectory should have the same SHA1' ' 436 test_when_finished "rmdir addtest/subdir" && 437 ( 438 cd addtest && 439 mkdir subdir && 440 git submodule status >output && 441 awk "{print \$1}" <output >expect && 442 cd subdir && 443 git submodule status >../output && 444 awk "{print \$1}" <../output >../actual && 445 test_cmp ../expect ../actual && 446 git -C ../submod checkout HEAD^ && 447 git submodule status >../output && 448 awk "{print \$1}" <../output >../actual2 && 449 cd .. && 450 git submodule status >output && 451 awk "{print \$1}" <output >expect2 && 452 test_cmp expect2 actual2 && 453 ! test_cmp actual actual2 454 ) 455' 456 457test_expect_success 'setup - fetch commit name from submodule' ' 458 rev1=$(cd .subrepo && git rev-parse HEAD) && 459 printf "rev1: %s\n" "$rev1" && 460 test -n "$rev1" 461' 462 463test_expect_success 'status should initially be "missing"' ' 464 git submodule status >lines && 465 grep "^-$rev1" lines 466' 467 468test_expect_success 'init should register submodule url in .git/config' ' 469 echo git://example.com/init.git >expect && 470 471 git submodule init && 472 git config submodule.example.url >url && 473 git config submodule.example.url ./.subrepo && 474 475 test_cmp expect url 476' 477 478test_expect_success 'status should still be "missing" after initializing' ' 479 rm -fr init && 480 mkdir init && 481 git submodule status >lines && 482 rm -fr init && 483 grep "^-$rev1" lines 484' 485 486test_failure_with_unknown_submodule () { 487 test_must_fail git submodule $1 no-such-submodule 2>output.err && 488 test_grep "^error: .*no-such-submodule" output.err 489} 490 491test_expect_success 'init should fail with unknown submodule' ' 492 test_failure_with_unknown_submodule init 493' 494 495test_expect_success 'update should fail with unknown submodule' ' 496 test_failure_with_unknown_submodule update 497' 498 499test_expect_success 'status should fail with unknown submodule' ' 500 test_failure_with_unknown_submodule status 501' 502 503test_expect_success 'sync should fail with unknown submodule' ' 504 test_failure_with_unknown_submodule sync 505' 506 507test_expect_success 'update should fail when path is used by a file' ' 508 echo hello >expect && 509 510 echo "hello" >init && 511 test_must_fail git submodule update && 512 513 test_cmp expect init 514' 515 516test_expect_success 'update should fail when path is used by a nonempty directory' ' 517 echo hello >expect && 518 519 rm -fr init && 520 mkdir init && 521 echo "hello" >init/a && 522 523 test_must_fail git submodule update && 524 525 test_cmp expect init/a 526' 527 528test_expect_success 'update should work when path is an empty dir' ' 529 rm -fr init && 530 rm -f head-sha1 && 531 echo "$rev1" >expect && 532 533 mkdir init && 534 git submodule update -q >update.out && 535 test_must_be_empty update.out && 536 537 inspect init && 538 test_cmp expect head-sha1 539' 540 541test_expect_success 'status should be "up-to-date" after update' ' 542 git submodule status >list && 543 grep "^ $rev1" list 544' 545 546test_expect_success 'status "up-to-date" from subdirectory' ' 547 mkdir -p sub && 548 ( 549 cd sub && 550 git submodule status >../list 551 ) && 552 grep "^ $rev1" list && 553 grep "\\.\\./init" list 554' 555 556test_expect_success 'status "up-to-date" from subdirectory with path' ' 557 mkdir -p sub && 558 ( 559 cd sub && 560 git submodule status ../init >../list 561 ) && 562 grep "^ $rev1" list && 563 grep "\\.\\./init" list 564' 565 566test_expect_success 'status should be "modified" after submodule commit' ' 567 ( 568 cd init && 569 echo b >b && 570 git add b && 571 git commit -m "submodule commit 2" 572 ) && 573 574 rev2=$(cd init && git rev-parse HEAD) && 575 test -n "$rev2" && 576 git submodule status >list && 577 578 grep "^+$rev2" list 579' 580 581test_expect_success '"submodule --cached" command forms should be identical' ' 582 git submodule status --cached >expect && 583 584 git submodule --cached >actual && 585 test_cmp expect actual && 586 587 git submodule --cached status >actual && 588 test_cmp expect actual 589' 590 591test_expect_success 'the --cached sha1 should be rev1' ' 592 git submodule --cached status >list && 593 grep "^+$rev1" list 594' 595 596test_expect_success 'git diff should report the SHA1 of the new submodule commit' ' 597 git diff >diff && 598 grep "^+Subproject commit $rev2" diff 599' 600 601test_expect_success 'update should checkout rev1' ' 602 rm -f head-sha1 && 603 echo "$rev1" >expect && 604 605 git submodule update init && 606 inspect init && 607 608 test_cmp expect head-sha1 609' 610 611test_expect_success 'status should be "up-to-date" after update' ' 612 git submodule status >list && 613 grep "^ $rev1" list 614' 615 616test_expect_success 'checkout superproject with subproject already present' ' 617 git checkout initial && 618 git checkout main 619' 620 621test_expect_success 'apply submodule diff' ' 622 git branch second && 623 ( 624 cd init && 625 echo s >s && 626 git add s && 627 git commit -m "change subproject" 628 ) && 629 git update-index --add init && 630 git commit -m "change init" && 631 git format-patch -1 --stdout >P.diff && 632 git checkout second && 633 git apply --index P.diff && 634 635 git diff --cached main >staged && 636 test_must_be_empty staged 637' 638 639test_expect_success 'update --init' ' 640 mv init init2 && 641 git config -f .gitmodules submodule.example.url "$(pwd)/init2" && 642 git config --remove-section submodule.example && 643 test_must_fail git config submodule.example.url && 644 645 git submodule update init 2> update.out && 646 test_grep "not initialized" update.out && 647 test_must_fail git rev-parse --resolve-git-dir init/.git && 648 649 git submodule update --init init && 650 git rev-parse --resolve-git-dir init/.git 651' 652 653test_expect_success 'update --init from subdirectory' ' 654 mv init init2 && 655 git config -f .gitmodules submodule.example.url "$(pwd)/init2" && 656 git config --remove-section submodule.example && 657 test_must_fail git config submodule.example.url && 658 659 mkdir -p sub && 660 ( 661 cd sub && 662 git submodule update ../init 2>update.out && 663 test_grep "not initialized" update.out && 664 test_must_fail git rev-parse --resolve-git-dir ../init/.git && 665 666 git submodule update --init ../init 667 ) && 668 git rev-parse --resolve-git-dir init/.git 669' 670 671test_expect_success 'do not add files from a submodule' ' 672 673 git reset --hard && 674 test_must_fail git add init/a 675 676' 677 678test_expect_success 'gracefully add/reset submodule with a trailing slash' ' 679 680 git reset --hard && 681 git commit -m "commit subproject" init && 682 (cd init && 683 echo b > a) && 684 git add init/ && 685 git diff --exit-code --cached init && 686 commit=$(cd init && 687 git commit -m update a >/dev/null && 688 git rev-parse HEAD) && 689 git add init/ && 690 test_must_fail git diff --exit-code --cached init && 691 test $commit = $(git ls-files --stage | 692 sed -n "s/^160000 \([^ ]*\).*/\1/p") && 693 git reset init/ && 694 git diff --exit-code --cached init 695 696' 697 698test_expect_success 'ls-files gracefully handles trailing slash' ' 699 700 test "init" = "$(git ls-files init/)" 701 702' 703 704test_expect_success 'moving to a commit without submodule does not leave empty dir' ' 705 rm -rf init && 706 mkdir init && 707 git reset --hard && 708 git checkout initial && 709 test ! -d init && 710 git checkout second 711' 712 713test_expect_success 'submodule <invalid-subcommand> fails' ' 714 test_must_fail git submodule no-such-subcommand 715' 716 717test_expect_success 'add submodules without specifying an explicit path' ' 718 mkdir repo && 719 ( 720 cd repo && 721 git init && 722 echo r >r && 723 git add r && 724 git commit -m "repo commit 1" 725 ) && 726 git clone --bare repo/ bare.git && 727 ( 728 cd addtest && 729 git submodule add "$submodurl/repo" && 730 git config -f .gitmodules submodule.repo.path repo && 731 git submodule add "$submodurl/bare.git" && 732 git config -f .gitmodules submodule.bare.path bare 733 ) 734' 735 736test_expect_success 'add should fail when path is used by a file' ' 737 ( 738 cd addtest && 739 touch file && 740 test_must_fail git submodule add "$submodurl/repo" file 741 ) 742' 743 744test_expect_success 'add should fail when path is used by an existing directory' ' 745 ( 746 cd addtest && 747 mkdir empty-dir && 748 test_must_fail git submodule add "$submodurl/repo" empty-dir 749 ) 750' 751 752test_expect_success 'use superproject as upstream when path is relative and no url is set there' ' 753 ( 754 cd addtest && 755 git submodule add ../repo relative && 756 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo && 757 git submodule sync relative && 758 test "$(git config submodule.relative.url)" = "$submodurl/repo" 759 ) 760' 761 762test_expect_success 'set up for relative path tests' ' 763 mkdir reltest && 764 ( 765 cd reltest && 766 git init && 767 mkdir sub && 768 ( 769 cd sub && 770 git init && 771 test_commit foo 772 ) && 773 git add sub && 774 git config -f .gitmodules submodule.sub.path sub && 775 git config -f .gitmodules submodule.sub.url ../subrepo && 776 cp .git/config pristine-.git-config && 777 cp .gitmodules pristine-.gitmodules 778 ) 779' 780 781test_expect_success '../subrepo works with URL - ssh://hostname/repo' ' 782 ( 783 cd reltest && 784 cp pristine-.git-config .git/config && 785 cp pristine-.gitmodules .gitmodules && 786 git config remote.origin.url ssh://hostname/repo && 787 git submodule init && 788 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo 789 ) 790' 791 792test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' ' 793 ( 794 cd reltest && 795 cp pristine-.git-config .git/config && 796 cp pristine-.gitmodules .gitmodules && 797 git config remote.origin.url ssh://hostname:22/repo && 798 git submodule init && 799 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo 800 ) 801' 802 803# About the choice of the path in the next test: 804# - double-slash side-steps path mangling issues on Windows 805# - it is still an absolute local path 806# - there cannot be a server with a blank in its name just in case the 807# path is used erroneously to access a //server/share style path 808test_expect_success '../subrepo path works with local path - //somewhere else/repo' ' 809 ( 810 cd reltest && 811 cp pristine-.git-config .git/config && 812 cp pristine-.gitmodules .gitmodules && 813 git config remote.origin.url "//somewhere else/repo" && 814 git submodule init && 815 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo" 816 ) 817' 818 819test_expect_success '../subrepo works with file URL - file:///tmp/repo' ' 820 ( 821 cd reltest && 822 cp pristine-.git-config .git/config && 823 cp pristine-.gitmodules .gitmodules && 824 git config remote.origin.url file:///tmp/repo && 825 git submodule init && 826 test "$(git config submodule.sub.url)" = file:///tmp/subrepo 827 ) 828' 829 830test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' ' 831 ( 832 cd reltest && 833 cp pristine-.git-config .git/config && 834 cp pristine-.gitmodules .gitmodules && 835 git config remote.origin.url helper:://hostname/repo && 836 git submodule init && 837 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo 838 ) 839' 840 841test_expect_success '../subrepo works with scp-style URL - user@host:repo' ' 842 ( 843 cd reltest && 844 cp pristine-.git-config .git/config && 845 git config remote.origin.url user@host:repo && 846 git submodule init && 847 test "$(git config submodule.sub.url)" = user@host:subrepo 848 ) 849' 850 851test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' ' 852 ( 853 cd reltest && 854 cp pristine-.git-config .git/config && 855 cp pristine-.gitmodules .gitmodules && 856 git config remote.origin.url user@host:path/to/repo && 857 git submodule init && 858 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo 859 ) 860' 861 862test_expect_success '../subrepo works with relative local path - foo' ' 863 ( 864 cd reltest && 865 cp pristine-.git-config .git/config && 866 cp pristine-.gitmodules .gitmodules && 867 git config remote.origin.url foo && 868 # actual: fails with an error 869 git submodule init && 870 test "$(git config submodule.sub.url)" = subrepo 871 ) 872' 873 874test_expect_success '../subrepo works with relative local path - foo/bar' ' 875 ( 876 cd reltest && 877 cp pristine-.git-config .git/config && 878 cp pristine-.gitmodules .gitmodules && 879 git config remote.origin.url foo/bar && 880 git submodule init && 881 test "$(git config submodule.sub.url)" = foo/subrepo 882 ) 883' 884 885test_expect_success '../subrepo works with relative local path - ./foo' ' 886 ( 887 cd reltest && 888 cp pristine-.git-config .git/config && 889 cp pristine-.gitmodules .gitmodules && 890 git config remote.origin.url ./foo && 891 git submodule init && 892 test "$(git config submodule.sub.url)" = subrepo 893 ) 894' 895 896test_expect_success '../subrepo works with relative local path - ./foo/bar' ' 897 ( 898 cd reltest && 899 cp pristine-.git-config .git/config && 900 cp pristine-.gitmodules .gitmodules && 901 git config remote.origin.url ./foo/bar && 902 git submodule init && 903 test "$(git config submodule.sub.url)" = foo/subrepo 904 ) 905' 906 907test_expect_success '../subrepo works with relative local path - ../foo' ' 908 ( 909 cd reltest && 910 cp pristine-.git-config .git/config && 911 cp pristine-.gitmodules .gitmodules && 912 git config remote.origin.url ../foo && 913 git submodule init && 914 test "$(git config submodule.sub.url)" = ../subrepo 915 ) 916' 917 918test_expect_success '../subrepo works with relative local path - ../foo/bar' ' 919 ( 920 cd reltest && 921 cp pristine-.git-config .git/config && 922 cp pristine-.gitmodules .gitmodules && 923 git config remote.origin.url ../foo/bar && 924 git submodule init && 925 test "$(git config submodule.sub.url)" = ../foo/subrepo 926 ) 927' 928 929test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' ' 930 ( 931 cd reltest && 932 cp pristine-.git-config .git/config && 933 cp pristine-.gitmodules .gitmodules && 934 mkdir -p a/b/c && 935 (cd a/b/c && git init && test_commit msg) && 936 git config remote.origin.url ../foo/bar.git && 937 git submodule add ../bar/a/b/c ./a/b/c && 938 git submodule init && 939 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c 940 ) 941' 942 943test_expect_success 'moving the superproject does not break submodules' ' 944 ( 945 cd addtest && 946 git submodule status >expect 947 ) && 948 mv addtest addtest2 && 949 ( 950 cd addtest2 && 951 git submodule status >actual && 952 test_cmp expect actual 953 ) 954' 955 956test_expect_success 'moving the submodule does not break the superproject' ' 957 ( 958 cd addtest2 && 959 git submodule status 960 ) >actual && 961 sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect && 962 mv addtest2/repo addtest2/repo.bak && 963 test_when_finished "mv addtest2/repo.bak addtest2/repo" && 964 ( 965 cd addtest2 && 966 git submodule status 967 ) >actual && 968 test_cmp expect actual 969' 970 971test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' ' 972 ( 973 cd addtest2 && 974 ( 975 cd repo && 976 echo "$submodurl/repo" >expect && 977 git config remote.origin.url >actual && 978 test_cmp expect actual && 979 echo "gitdir: ../.git/modules/repo" >expect && 980 test_cmp expect .git 981 ) && 982 rm -rf repo && 983 git rm repo && 984 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual && 985 test_must_be_empty actual && 986 echo "gitdir: ../.git/modules/submod" >expect && 987 test_cmp expect submod/.git && 988 ( 989 cd repo && 990 echo "$submodurl/bare.git" >expect && 991 git config remote.origin.url >actual && 992 test_cmp expect actual && 993 echo "gitdir: ../.git/modules/repo_new" >expect && 994 test_cmp expect .git 995 ) && 996 echo "repo" >expect && 997 test_must_fail git config -f .gitmodules submodule.repo.path && 998 git config -f .gitmodules submodule.repo_new.path >actual && 999 test_cmp expect actual && 1000 echo "$submodurl/repo" >expect && 1001 test_must_fail git config -f .gitmodules submodule.repo.url && 1002 echo "$submodurl/bare.git" >expect && 1003 git config -f .gitmodules submodule.repo_new.url >actual && 1004 test_cmp expect actual && 1005 echo "$submodurl/repo" >expect && 1006 git config submodule.repo.url >actual && 1007 test_cmp expect actual && 1008 echo "$submodurl/bare.git" >expect && 1009 git config submodule.repo_new.url >actual && 1010 test_cmp expect actual 1011 ) 1012' 1013 1014test_expect_success 'recursive relative submodules stay relative' ' 1015 test_when_finished "rm -rf super clone2 subsub sub3" && 1016 mkdir subsub && 1017 ( 1018 cd subsub && 1019 git init && 1020 >t && 1021 git add t && 1022 git commit -m "initial commit" 1023 ) && 1024 mkdir sub3 && 1025 ( 1026 cd sub3 && 1027 git init && 1028 >t && 1029 git add t && 1030 git commit -m "initial commit" && 1031 git submodule add ../subsub dirdir/subsub && 1032 git commit -m "add submodule subsub" 1033 ) && 1034 mkdir super && 1035 ( 1036 cd super && 1037 git init && 1038 >t && 1039 git add t && 1040 git commit -m "initial commit" && 1041 git submodule add ../sub3 && 1042 git commit -m "add submodule sub" 1043 ) && 1044 git clone super clone2 && 1045 ( 1046 cd clone2 && 1047 git submodule update --init --recursive && 1048 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect && 1049 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect 1050 ) && 1051 test_cmp clone2/sub3/.git_expect clone2/sub3/.git && 1052 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git 1053' 1054 1055test_expect_success 'submodule add with an existing name fails unless forced' ' 1056 ( 1057 cd addtest2 && 1058 rm -rf repo && 1059 git rm repo && 1060 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo && 1061 test ! -d repo && 1062 test_must_fail git config -f .gitmodules submodule.repo_new.path && 1063 test_must_fail git config -f .gitmodules submodule.repo_new.url && 1064 echo "$submodurl/bare.git" >expect && 1065 git config submodule.repo_new.url >actual && 1066 test_cmp expect actual && 1067 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo && 1068 test -d repo && 1069 echo "repo" >expect && 1070 git config -f .gitmodules submodule.repo_new.path >actual && 1071 test_cmp expect actual && 1072 echo "$submodurl/repo.git" >expect && 1073 git config -f .gitmodules submodule.repo_new.url >actual && 1074 test_cmp expect actual && 1075 echo "$submodurl/repo.git" >expect && 1076 git config submodule.repo_new.url >actual && 1077 test_cmp expect actual 1078 ) 1079' 1080 1081test_expect_success 'set up a second submodule' ' 1082 git submodule add ./init2 example2 && 1083 git commit -m "submodule example2 added" 1084' 1085 1086test_expect_success 'submodule deinit works on repository without submodules' ' 1087 test_when_finished "rm -rf newdirectory" && 1088 mkdir newdirectory && 1089 ( 1090 cd newdirectory && 1091 git init && 1092 >file && 1093 git add file && 1094 git commit -m "repo should not be empty" && 1095 git submodule deinit . && 1096 git submodule deinit --all 1097 ) 1098' 1099 1100test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' ' 1101 git config submodule.example.foo bar && 1102 git config submodule.example2.frotz nitfol && 1103 git submodule deinit init && 1104 test -z "$(git config --get-regexp "submodule\.example\.")" && 1105 test -n "$(git config --get-regexp "submodule\.example2\.")" && 1106 test -f example2/.git && 1107 rmdir init 1108' 1109 1110test_expect_success 'submodule deinit should unset core.worktree' ' 1111 test_path_is_file .git/modules/example/config && 1112 test_must_fail git config -f .git/modules/example/config core.worktree 1113' 1114 1115test_expect_success 'submodule deinit from subdirectory' ' 1116 git submodule update --init && 1117 git config submodule.example.foo bar && 1118 mkdir -p sub && 1119 ( 1120 cd sub && 1121 git submodule deinit ../init >../output 1122 ) && 1123 test_grep "\\.\\./init" output && 1124 test -z "$(git config --get-regexp "submodule\.example\.")" && 1125 test -n "$(git config --get-regexp "submodule\.example2\.")" && 1126 test -f example2/.git && 1127 rmdir init 1128' 1129 1130test_expect_success 'submodule deinit . deinits all initialized submodules' ' 1131 git submodule update --init && 1132 git config submodule.example.foo bar && 1133 git config submodule.example2.frotz nitfol && 1134 test_must_fail git submodule deinit && 1135 git submodule deinit . >actual && 1136 test -z "$(git config --get-regexp "submodule\.example\.")" && 1137 test -z "$(git config --get-regexp "submodule\.example2\.")" && 1138 test_grep "Cleared directory .init" actual && 1139 test_grep "Cleared directory .example2" actual && 1140 rmdir init example2 1141' 1142 1143test_expect_success 'submodule deinit --all deinits all initialized submodules' ' 1144 git submodule update --init && 1145 git config submodule.example.foo bar && 1146 git config submodule.example2.frotz nitfol && 1147 test_must_fail git submodule deinit && 1148 git submodule deinit --all >actual && 1149 test -z "$(git config --get-regexp "submodule\.example\.")" && 1150 test -z "$(git config --get-regexp "submodule\.example2\.")" && 1151 test_grep "Cleared directory .init" actual && 1152 test_grep "Cleared directory .example2" actual && 1153 rmdir init example2 1154' 1155 1156test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' ' 1157 git submodule update --init && 1158 rm -rf init example2/* example2/.git && 1159 git submodule deinit init example2 >actual && 1160 test -z "$(git config --get-regexp "submodule\.example\.")" && 1161 test -z "$(git config --get-regexp "submodule\.example2\.")" && 1162 test_grep ! "Cleared directory .init" actual && 1163 test_grep "Cleared directory .example2" actual && 1164 rmdir init 1165' 1166 1167test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' ' 1168 git submodule update --init && 1169 echo X >>init/s && 1170 test_must_fail git submodule deinit init && 1171 test -n "$(git config --get-regexp "submodule\.example\.")" && 1172 test -f example2/.git && 1173 git submodule deinit -f init >actual && 1174 test -z "$(git config --get-regexp "submodule\.example\.")" && 1175 test_grep "Cleared directory .init" actual && 1176 rmdir init 1177' 1178 1179test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' ' 1180 git submodule update --init && 1181 echo X >>init/untracked && 1182 test_must_fail git submodule deinit init && 1183 test -n "$(git config --get-regexp "submodule\.example\.")" && 1184 test -f example2/.git && 1185 git submodule deinit -f init >actual && 1186 test -z "$(git config --get-regexp "submodule\.example\.")" && 1187 test_grep "Cleared directory .init" actual && 1188 rmdir init 1189' 1190 1191test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' ' 1192 git submodule update --init && 1193 ( 1194 cd init && 1195 git checkout HEAD^ 1196 ) && 1197 test_must_fail git submodule deinit init && 1198 test -n "$(git config --get-regexp "submodule\.example\.")" && 1199 test -f example2/.git && 1200 git submodule deinit -f init >actual && 1201 test -z "$(git config --get-regexp "submodule\.example\.")" && 1202 test_grep "Cleared directory .init" actual && 1203 rmdir init 1204' 1205 1206test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' ' 1207 git submodule update --init && 1208 git submodule deinit init >actual && 1209 test_grep "Submodule .example. (.*) unregistered for path .init" actual && 1210 test_grep "Cleared directory .init" actual && 1211 git submodule deinit init >actual && 1212 test_grep ! "Submodule .example. (.*) unregistered for path .init" actual && 1213 test_grep "Cleared directory .init" actual && 1214 git submodule deinit . >actual && 1215 test_grep ! "Submodule .example. (.*) unregistered for path .init" actual && 1216 test_grep "Submodule .example2. (.*) unregistered for path .example2" actual && 1217 test_grep "Cleared directory .init" actual && 1218 git submodule deinit . >actual && 1219 test_grep ! "Submodule .example. (.*) unregistered for path .init" actual && 1220 test_grep ! "Submodule .example2. (.*) unregistered for path .example2" actual && 1221 test_grep "Cleared directory .init" actual && 1222 git submodule deinit --all >actual && 1223 test_grep ! "Submodule .example. (.*) unregistered for path .init" actual && 1224 test_grep ! "Submodule .example2. (.*) unregistered for path .example2" actual && 1225 test_grep "Cleared directory .init" actual && 1226 rmdir init example2 1227' 1228 1229test_expect_success 'submodule deinit absorbs .git directory if .git is a directory' ' 1230 git submodule update --init && 1231 ( 1232 cd init && 1233 rm .git && 1234 mv ../.git/modules/example .git && 1235 GIT_WORK_TREE=. git config --unset core.worktree 1236 ) && 1237 git submodule deinit init && 1238 test_path_is_missing init/.git && 1239 test -z "$(git config --get-regexp "submodule\.example\.")" 1240' 1241 1242test_expect_success 'submodule with UTF-8 name' ' 1243 svname=$(printf "\303\245 \303\244\303\266") && 1244 mkdir "$svname" && 1245 ( 1246 cd "$svname" && 1247 git init && 1248 >sub && 1249 git add sub && 1250 git commit -m "init sub" 1251 ) && 1252 git submodule add ./"$svname" && 1253 git submodule >&2 && 1254 test -n "$(git submodule | grep "$svname")" 1255' 1256 1257test_expect_success 'submodule add clone shallow submodule' ' 1258 mkdir super && 1259 pwd=$(pwd) && 1260 ( 1261 cd super && 1262 git init && 1263 git submodule add --depth=1 file://"$pwd"/example2 submodule && 1264 ( 1265 cd submodule && 1266 test 1 = $(git log --oneline | wc -l) 1267 ) 1268 ) 1269' 1270 1271test_expect_success 'setup superproject with submodules' ' 1272 git init sub1 && 1273 test_commit -C sub1 test && 1274 test_commit -C sub1 test2 && 1275 git init multisuper && 1276 git -C multisuper submodule add ../sub1 sub0 && 1277 git -C multisuper submodule add ../sub1 sub1 && 1278 git -C multisuper submodule add ../sub1 sub2 && 1279 git -C multisuper submodule add ../sub1 sub3 && 1280 git -C multisuper commit -m "add some submodules" 1281' 1282 1283cat >expect <<-EOF 1284-sub0 1285 sub1 (test2) 1286 sub2 (test2) 1287 sub3 (test2) 1288EOF 1289 1290test_expect_success 'submodule update --init with a specification' ' 1291 test_when_finished "rm -rf multisuper_clone" && 1292 pwd=$(pwd) && 1293 git clone file://"$pwd"/multisuper multisuper_clone && 1294 git -C multisuper_clone submodule update --init . ":(exclude)sub0" && 1295 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && 1296 test_cmp expect actual 1297' 1298 1299test_expect_success 'submodule update --init with submodule.active set' ' 1300 test_when_finished "rm -rf multisuper_clone" && 1301 pwd=$(pwd) && 1302 git clone file://"$pwd"/multisuper multisuper_clone && 1303 git -C multisuper_clone config submodule.active "." && 1304 git -C multisuper_clone config --add submodule.active ":(exclude)sub0" && 1305 git -C multisuper_clone submodule update --init && 1306 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && 1307 test_cmp expect actual 1308' 1309 1310test_expect_success 'submodule update and setting submodule.<name>.active' ' 1311 test_when_finished "rm -rf multisuper_clone" && 1312 pwd=$(pwd) && 1313 git clone file://"$pwd"/multisuper multisuper_clone && 1314 git -C multisuper_clone config --bool submodule.sub0.active "true" && 1315 git -C multisuper_clone config --bool submodule.sub1.active "false" && 1316 git -C multisuper_clone config --bool submodule.sub2.active "true" && 1317 1318 cat >expect <<-\EOF && 1319 sub0 (test2) 1320 -sub1 1321 sub2 (test2) 1322 -sub3 1323 EOF 1324 git -C multisuper_clone submodule update && 1325 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && 1326 test_cmp expect actual 1327' 1328 1329test_expect_success 'clone active submodule without submodule url set' ' 1330 test_when_finished "rm -rf test/test" && 1331 mkdir test && 1332 # another dir breaks accidental relative paths still being correct 1333 git clone file://"$pwd"/multisuper test/test && 1334 ( 1335 cd test/test && 1336 git config submodule.active "." && 1337 1338 # do not pass --init flag, as the submodule is already active: 1339 git submodule update && 1340 git submodule status >actual_raw && 1341 1342 cut -d" " -f3- actual_raw >actual && 1343 cat >expect <<-\EOF && 1344 sub0 (test2) 1345 sub1 (test2) 1346 sub2 (test2) 1347 sub3 (test2) 1348 EOF 1349 test_cmp expect actual 1350 ) 1351' 1352 1353test_expect_success 'update submodules without url set in .gitconfig' ' 1354 test_when_finished "rm -rf multisuper_clone" && 1355 git clone file://"$pwd"/multisuper multisuper_clone && 1356 1357 git -C multisuper_clone submodule init && 1358 for s in sub0 sub1 sub2 sub3 1359 do 1360 key=submodule.$s.url && 1361 git -C multisuper_clone config --local --unset $key && 1362 git -C multisuper_clone config --file .gitmodules --unset $key || return 1 1363 done && 1364 1365 test_must_fail git -C multisuper_clone submodule update 2>err && 1366 grep "cannot clone submodule .sub[0-3]. without a URL" err 1367' 1368 1369test_expect_success 'clone --recurse-submodules with a pathspec works' ' 1370 test_when_finished "rm -rf multisuper_clone" && 1371 cat >expected <<-\EOF && 1372 sub0 (test2) 1373 -sub1 1374 -sub2 1375 -sub3 1376 EOF 1377 1378 git clone --recurse-submodules="sub0" multisuper multisuper_clone && 1379 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && 1380 test_cmp expected actual 1381' 1382 1383test_expect_success 'clone with multiple --recurse-submodules options' ' 1384 test_when_finished "rm -rf multisuper_clone" && 1385 cat >expect <<-\EOF && 1386 -sub0 1387 sub1 (test2) 1388 -sub2 1389 sub3 (test2) 1390 EOF 1391 1392 git clone --recurse-submodules="." \ 1393 --recurse-submodules=":(exclude)sub0" \ 1394 --recurse-submodules=":(exclude)sub2" \ 1395 multisuper multisuper_clone && 1396 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && 1397 test_cmp expect actual 1398' 1399 1400test_expect_success 'clone and subsequent updates correctly auto-initialize submodules' ' 1401 test_when_finished "rm -rf multisuper_clone" && 1402 cat <<-\EOF >expect && 1403 -sub0 1404 sub1 (test2) 1405 -sub2 1406 sub3 (test2) 1407 EOF 1408 1409 cat <<-\EOF >expect2 && 1410 -sub0 1411 sub1 (test2) 1412 -sub2 1413 sub3 (test2) 1414 -sub4 1415 sub5 (test2) 1416 EOF 1417 1418 git clone --recurse-submodules="." \ 1419 --recurse-submodules=":(exclude)sub0" \ 1420 --recurse-submodules=":(exclude)sub2" \ 1421 --recurse-submodules=":(exclude)sub4" \ 1422 multisuper multisuper_clone && 1423 1424 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && 1425 test_cmp expect actual && 1426 1427 git -C multisuper submodule add ../sub1 sub4 && 1428 git -C multisuper submodule add ../sub1 sub5 && 1429 git -C multisuper commit -m "add more submodules" && 1430 # obtain the new superproject 1431 git -C multisuper_clone pull && 1432 git -C multisuper_clone submodule update --init && 1433 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && 1434 test_cmp expect2 actual 1435' 1436 1437test_expect_success 'init properly sets the config' ' 1438 test_when_finished "rm -rf multisuper_clone" && 1439 git clone --recurse-submodules="." \ 1440 --recurse-submodules=":(exclude)sub0" \ 1441 multisuper multisuper_clone && 1442 1443 git -C multisuper_clone submodule init -- sub0 sub1 && 1444 git -C multisuper_clone config --get submodule.sub0.active && 1445 test_must_fail git -C multisuper_clone config --get submodule.sub1.active 1446' 1447 1448test_expect_success 'recursive clone respects -q' ' 1449 test_when_finished "rm -rf multisuper_clone" && 1450 git clone -q --recurse-submodules multisuper multisuper_clone >actual && 1451 test_must_be_empty actual 1452' 1453 1454test_expect_success '`submodule init` and `init.templateDir`' ' 1455 mkdir -p tmpl/hooks && 1456 write_script tmpl/hooks/post-checkout <<-EOF && 1457 echo HOOK-RUN >&2 1458 echo I was here >hook.run 1459 exit 1 1460 EOF 1461 1462 test_config init.templateDir "$(pwd)/tmpl" && 1463 test_when_finished \ 1464 "git config --global --unset init.templateDir || true" && 1465 ( 1466 sane_unset GIT_TEMPLATE_DIR && 1467 NO_SET_GIT_TEMPLATE_DIR=t && 1468 export NO_SET_GIT_TEMPLATE_DIR && 1469 1470 git config --global init.templateDir "$(pwd)/tmpl" && 1471 test_must_fail git submodule \ 1472 add "$submodurl" sub-global 2>err && 1473 git config --global --unset init.templateDir && 1474 test_grep HOOK-RUN err && 1475 test_path_is_file sub-global/hook.run && 1476 1477 git config init.templateDir "$(pwd)/tmpl" && 1478 git submodule add "$submodurl" sub-local 2>err && 1479 git config --unset init.templateDir && 1480 test_grep ! HOOK-RUN err && 1481 test_path_is_missing sub-local/hook.run 1482 ) 1483' 1484 1485test_expect_success 'submodule add fails when name is reused' ' 1486 git init test-submodule && 1487 ( 1488 cd test-submodule && 1489 git commit --allow-empty -m init && 1490 1491 git init ../child-origin && 1492 git -C ../child-origin commit --allow-empty -m init && 1493 1494 git submodule add ../child-origin child && 1495 git commit -m "Add submodule child" && 1496 1497 git mv child child_old && 1498 git commit -m "Move child to child_old" && 1499 1500 # Now adding a *new* repo at the old name must fail 1501 git init ../child2-origin && 1502 git -C ../child2-origin commit --allow-empty -m init && 1503 test_must_fail git submodule add ../child2-origin child 2>err && 1504 test_grep "already used for" err 1505 ) 1506' 1507 1508test_done