Ben Avison | 4c69101 | 2019-05-19 15:26:49 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test cloning repos with submodules using remote-tracking branches' |
| 4 | |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Ævar Arnfjörð Bjarmason | dd4143e | 2022-11-08 19:17:47 +0100 | [diff] [blame] | 8 | TEST_PASSES_SANITIZE_LEAK=true |
Ben Avison | 4c69101 | 2019-05-19 15:26:49 +0100 | [diff] [blame] | 9 | . ./test-lib.sh |
| 10 | |
| 11 | pwd=$(pwd) |
| 12 | |
| 13 | test_expect_success 'setup' ' |
Taylor Blau | 225d2d5 | 2022-07-29 15:21:06 -0400 | [diff] [blame] | 14 | git config --global protocol.file.allow always && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 15 | git checkout -b main && |
Ben Avison | 4c69101 | 2019-05-19 15:26:49 +0100 | [diff] [blame] | 16 | test_commit commit1 && |
| 17 | mkdir sub && |
| 18 | ( |
| 19 | cd sub && |
| 20 | git init && |
| 21 | test_commit subcommit1 && |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 22 | git tag sub_when_added_to_super && |
| 23 | git branch other |
Ben Avison | 4c69101 | 2019-05-19 15:26:49 +0100 | [diff] [blame] | 24 | ) && |
| 25 | git submodule add "file://$pwd/sub" sub && |
| 26 | git commit -m "add submodule" && |
| 27 | ( |
| 28 | cd sub && |
| 29 | test_commit subcommit2 |
| 30 | ) |
| 31 | ' |
| 32 | |
Josh Steadmon | f05da2b | 2022-02-04 21:00:49 -0800 | [diff] [blame] | 33 | # bare clone giving "srv.bare" for use as our server. |
| 34 | test_expect_success 'setup bare clone for server' ' |
| 35 | git clone --bare "file://$(pwd)/." srv.bare && |
| 36 | git -C srv.bare config --local uploadpack.allowfilter 1 && |
| 37 | git -C srv.bare config --local uploadpack.allowanysha1inwant 1 |
| 38 | ' |
| 39 | |
Ben Avison | 4c69101 | 2019-05-19 15:26:49 +0100 | [diff] [blame] | 40 | test_expect_success 'clone with --no-remote-submodules' ' |
| 41 | test_when_finished "rm -rf super_clone" && |
| 42 | git clone --recurse-submodules --no-remote-submodules "file://$pwd/." super_clone && |
| 43 | ( |
| 44 | cd super_clone/sub && |
| 45 | git diff --exit-code sub_when_added_to_super |
| 46 | ) |
| 47 | ' |
| 48 | |
| 49 | test_expect_success 'clone with --remote-submodules' ' |
| 50 | test_when_finished "rm -rf super_clone" && |
| 51 | git clone --recurse-submodules --remote-submodules "file://$pwd/." super_clone && |
| 52 | ( |
| 53 | cd super_clone/sub && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 54 | git diff --exit-code remotes/origin/main |
Ben Avison | 4c69101 | 2019-05-19 15:26:49 +0100 | [diff] [blame] | 55 | ) |
| 56 | ' |
| 57 | |
| 58 | test_expect_success 'check the default is --no-remote-submodules' ' |
| 59 | test_when_finished "rm -rf super_clone" && |
| 60 | git clone --recurse-submodules "file://$pwd/." super_clone && |
| 61 | ( |
| 62 | cd super_clone/sub && |
| 63 | git diff --exit-code sub_when_added_to_super |
| 64 | ) |
| 65 | ' |
| 66 | |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 67 | test_expect_success 'clone with --single-branch' ' |
| 68 | test_when_finished "rm -rf super_clone" && |
| 69 | git clone --recurse-submodules --single-branch "file://$pwd/." super_clone && |
| 70 | ( |
| 71 | cd super_clone/sub && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 72 | git rev-parse --verify origin/main && |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 73 | test_must_fail git rev-parse --verify origin/other |
| 74 | ) |
| 75 | ' |
| 76 | |
Josh Steadmon | f05da2b | 2022-02-04 21:00:49 -0800 | [diff] [blame] | 77 | # do basic partial clone from "srv.bare" |
| 78 | # confirm partial clone was registered in the local config for super and sub. |
| 79 | test_expect_success 'clone with --filter' ' |
| 80 | git clone --recurse-submodules \ |
| 81 | --filter blob:none --also-filter-submodules \ |
| 82 | "file://$pwd/srv.bare" super_clone && |
| 83 | test_cmp_config -C super_clone true remote.origin.promisor && |
| 84 | test_cmp_config -C super_clone blob:none remote.origin.partialclonefilter && |
| 85 | test_cmp_config -C super_clone/sub true remote.origin.promisor && |
| 86 | test_cmp_config -C super_clone/sub blob:none remote.origin.partialclonefilter |
| 87 | ' |
| 88 | |
| 89 | # check that clone.filterSubmodules works (--also-filter-submodules can be |
| 90 | # omitted) |
| 91 | test_expect_success 'filters applied with clone.filterSubmodules' ' |
| 92 | test_config_global clone.filterSubmodules true && |
| 93 | git clone --recurse-submodules --filter blob:none \ |
| 94 | "file://$pwd/srv.bare" super_clone2 && |
| 95 | test_cmp_config -C super_clone2 true remote.origin.promisor && |
| 96 | test_cmp_config -C super_clone2 blob:none remote.origin.partialclonefilter && |
| 97 | test_cmp_config -C super_clone2/sub true remote.origin.promisor && |
| 98 | test_cmp_config -C super_clone2/sub blob:none remote.origin.partialclonefilter |
| 99 | ' |
| 100 | |
| 101 | test_expect_success '--no-also-filter-submodules overrides clone.filterSubmodules=true' ' |
| 102 | test_config_global clone.filterSubmodules true && |
| 103 | git clone --recurse-submodules --filter blob:none \ |
| 104 | --no-also-filter-submodules \ |
| 105 | "file://$pwd/srv.bare" super_clone3 && |
| 106 | test_cmp_config -C super_clone3 true remote.origin.promisor && |
| 107 | test_cmp_config -C super_clone3 blob:none remote.origin.partialclonefilter && |
| 108 | test_cmp_config -C super_clone3/sub false --default false remote.origin.promisor |
| 109 | ' |
| 110 | |
Ben Avison | 4c69101 | 2019-05-19 15:26:49 +0100 | [diff] [blame] | 111 | test_done |