|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +test_description='submodules handle mixed legacy and new (encoded) style gitdir paths' |
| 4 | + |
| 5 | +. ./test-lib.sh |
| 6 | +. "$TEST_DIRECTORY"/lib-verify-submodule-gitdir-path.sh |
| 7 | + |
| 8 | +test_expect_success 'setup: allow file protocol' ' |
| 9 | + git config --global protocol.file.allow always |
| 10 | +' |
| 11 | + |
| 12 | +test_expect_success 'create repo with mixed encoded and non-encoded submodules' ' |
| 13 | + git init -b main legacy-sub && |
| 14 | + test_commit -C legacy-sub legacy-initial && |
| 15 | + legacy_rev=$(git -C legacy-sub rev-parse HEAD) && |
| 16 | +
|
| 17 | + git init -b main new-sub && |
| 18 | + test_commit -C new-sub new-initial && |
| 19 | + new_rev=$(git -C new-sub rev-parse HEAD) && |
| 20 | +
|
| 21 | + git init -b main main && |
| 22 | + ( |
| 23 | + cd main && |
| 24 | + git submodule add ../legacy-sub legacy && |
| 25 | + test_commit legacy-sub && |
| 26 | +
|
| 27 | + git config core.repositoryformatversion 1 && |
| 28 | + git config extensions.submoduleEncoding true && |
| 29 | +
|
| 30 | + git submodule add ../new-sub "New Sub" && |
| 31 | + test_commit new |
| 32 | + ) |
| 33 | +' |
| 34 | + |
| 35 | +test_expect_success 'verify submodule name is properly encoded' ' |
| 36 | + verify_submodule_gitdir_path main legacy modules/legacy && |
| 37 | + verify_submodule_gitdir_path main "New Sub" modules/_new%20_sub |
| 38 | +' |
| 39 | + |
| 40 | +test_expect_success 'clone from repo with both legacy and new-style submodules' ' |
| 41 | + git clone --recurse-submodules main cloned-non-encoding && |
| 42 | + ( |
| 43 | + cd cloned-non-encoding && |
| 44 | +
|
| 45 | + test_path_is_dir .git/modules/legacy && |
| 46 | + test_path_is_dir .git/modules/"New Sub" && |
| 47 | +
|
| 48 | + git submodule status >list && |
| 49 | + test_grep "$legacy_rev legacy" list && |
| 50 | + test_grep "$new_rev New Sub" list |
| 51 | + ) && |
| 52 | +
|
| 53 | + git clone -c extensions.submoduleEncoding=true --recurse-submodules main cloned-encoding && |
| 54 | + ( |
| 55 | + cd cloned-encoding && |
| 56 | +
|
| 57 | + test_path_is_dir .git/modules/legacy && |
| 58 | + test_path_is_dir .git/modules/_new%20_sub && |
| 59 | +
|
| 60 | + git submodule status >list && |
| 61 | + test_grep "$legacy_rev legacy" list && |
| 62 | + test_grep "$new_rev New Sub" list |
| 63 | + ) |
| 64 | +' |
| 65 | + |
| 66 | +test_expect_success 'commit and push changes to encoded submodules' ' |
| 67 | + git -C legacy-sub config receive.denyCurrentBranch updateInstead && |
| 68 | + git -C new-sub config receive.denyCurrentBranch updateInstead && |
| 69 | + git -C main config receive.denyCurrentBranch updateInstead && |
| 70 | + ( |
| 71 | + cd cloned-encoding && |
| 72 | +
|
| 73 | + git -C legacy switch --track -C main origin/main && |
| 74 | + test_commit -C legacy second-commit && |
| 75 | + git -C legacy push && |
| 76 | +
|
| 77 | + git -C "New Sub" switch --track -C main origin/main && |
| 78 | + test_commit -C "New Sub" second-commit && |
| 79 | + git -C "New Sub" push && |
| 80 | +
|
| 81 | + # Stage and commit submodule changes in superproject |
| 82 | + git switch --track -C main origin/main && |
| 83 | + git add legacy "New Sub" && |
| 84 | + git commit -m "update submodules" && |
| 85 | +
|
| 86 | + # push superproject commit to main repo |
| 87 | + git push |
| 88 | + ) && |
| 89 | +
|
| 90 | + # update expected legacy & new submodule checksums |
| 91 | + legacy_rev=$(git -C legacy-sub rev-parse HEAD) && |
| 92 | + new_rev=$(git -C new-sub rev-parse HEAD) |
| 93 | +' |
| 94 | + |
| 95 | +test_expect_success 'fetch mixed submodule changes and verify updates' ' |
| 96 | + ( |
| 97 | + cd main && |
| 98 | +
|
| 99 | + # only update submodules because superproject was |
| 100 | + # pushed into at the end of last test |
| 101 | + git submodule update --init --recursive && |
| 102 | +
|
| 103 | + test_path_is_dir .git/modules/legacy && |
| 104 | + test_path_is_dir .git/modules/_new%20_sub && |
| 105 | +
|
| 106 | + # Verify both submodules are at the expected commits |
| 107 | + git submodule status >list && |
| 108 | + test_grep "$legacy_rev legacy" list && |
| 109 | + test_grep "$new_rev New Sub" list |
| 110 | + ) |
| 111 | +' |
| 112 | + |
| 113 | +test_expect_success 'setup submodules with nested git dirs' ' |
| 114 | + git init nested && |
| 115 | + test_commit -C nested nested && |
| 116 | + ( |
| 117 | + cd nested && |
| 118 | + cat >.gitmodules <<-EOF && |
| 119 | + [submodule "hippo"] |
| 120 | + url = . |
| 121 | + path = thing1 |
| 122 | + [submodule "hippo/hooks"] |
| 123 | + url = . |
| 124 | + path = thing2 |
| 125 | + EOF |
| 126 | + git clone . thing1 && |
| 127 | + git clone . thing2 && |
| 128 | + git add .gitmodules thing1 thing2 && |
| 129 | + test_tick && |
| 130 | + git commit -m nested |
| 131 | + ) |
| 132 | +' |
| 133 | + |
| 134 | +test_expect_success 'git dirs of encoded sibling submodules must not be nested' ' |
| 135 | + git clone -c extensions.submoduleEncoding=true --recurse-submodules nested clone_nested && |
| 136 | + verify_submodule_gitdir_path clone_nested hippo modules/hippo && |
| 137 | + verify_submodule_gitdir_path clone_nested hippo/hooks modules/hippo%2fhooks |
| 138 | +' |
| 139 | + |
| 140 | +test_expect_success 'submodule git dir nesting detection must work with parallel cloning' ' |
| 141 | + git clone -c extensions.submoduleEncoding=true --recurse-submodules --jobs=2 nested clone_parallel && |
| 142 | + verify_submodule_gitdir_path clone_parallel hippo modules/hippo && |
| 143 | + verify_submodule_gitdir_path clone_parallel hippo/hooks modules/hippo%2fhooks |
| 144 | +' |
| 145 | + |
| 146 | +test_done |
0 commit comments