Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2014 Heiko Voigt |
| 4 | # |
| 5 | |
| 6 | test_description='Test submodules config cache infrastructure |
| 7 | |
Heiko Voigt | 851e18c | 2015-08-17 17:21:59 -0700 | [diff] [blame] | 8 | This test verifies that parsing .gitmodules configurations directly |
| 9 | from the database and from the worktree works. |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 10 | ' |
| 11 | |
| 12 | TEST_NO_CREATE_REPO=1 |
| 13 | . ./test-lib.sh |
| 14 | |
Taylor Blau | 0d3beb7 | 2022-07-29 15:21:40 -0400 | [diff] [blame] | 15 | test_expect_success 'setup' ' |
| 16 | git config --global protocol.file.allow always |
| 17 | ' |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 18 | test_expect_success 'submodule config cache setup' ' |
| 19 | mkdir submodule && |
| 20 | (cd submodule && |
| 21 | git init && |
| 22 | echo a >a && |
| 23 | git add . && |
| 24 | git commit -ma |
| 25 | ) && |
| 26 | mkdir super && |
| 27 | (cd super && |
| 28 | git init && |
| 29 | git submodule add ../submodule && |
| 30 | git submodule add ../submodule a && |
| 31 | git commit -m "add as submodule and as a" && |
| 32 | git mv a b && |
| 33 | git commit -m "move a to b" |
| 34 | ) |
| 35 | ' |
| 36 | |
Brandon Williams | 5ea5095 | 2017-07-25 14:39:14 -0700 | [diff] [blame] | 37 | test_expect_success 'configuration parsing with error' ' |
| 38 | test_when_finished "rm -rf repo" && |
| 39 | test_create_repo repo && |
| 40 | cat >repo/.gitmodules <<-\EOF && |
| 41 | [submodule "s"] |
| 42 | path |
| 43 | ignore |
| 44 | EOF |
| 45 | ( |
| 46 | cd repo && |
Nguyễn Thái Ngọc Duy | b618821 | 2018-03-24 08:45:01 +0100 | [diff] [blame] | 47 | test_must_fail test-tool submodule-config "" s 2>actual && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 48 | test_grep "bad config" actual |
Brandon Williams | 5ea5095 | 2017-07-25 14:39:14 -0700 | [diff] [blame] | 49 | ) |
| 50 | ' |
| 51 | |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 52 | cat >super/expect <<EOF |
| 53 | Submodule name: 'a' for path 'a' |
| 54 | Submodule name: 'a' for path 'b' |
| 55 | Submodule name: 'submodule' for path 'submodule' |
| 56 | Submodule name: 'submodule' for path 'submodule' |
| 57 | EOF |
| 58 | |
| 59 | test_expect_success 'test parsing and lookup of submodule config by path' ' |
| 60 | (cd super && |
Nguyễn Thái Ngọc Duy | b618821 | 2018-03-24 08:45:01 +0100 | [diff] [blame] | 61 | test-tool submodule-config \ |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 62 | HEAD^ a \ |
| 63 | HEAD b \ |
| 64 | HEAD^ submodule \ |
| 65 | HEAD submodule \ |
| 66 | >actual && |
| 67 | test_cmp expect actual |
| 68 | ) |
| 69 | ' |
| 70 | |
| 71 | test_expect_success 'test parsing and lookup of submodule config by name' ' |
| 72 | (cd super && |
Nguyễn Thái Ngọc Duy | b618821 | 2018-03-24 08:45:01 +0100 | [diff] [blame] | 73 | test-tool submodule-config --name \ |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 74 | HEAD^ a \ |
| 75 | HEAD a \ |
| 76 | HEAD^ submodule \ |
| 77 | HEAD submodule \ |
| 78 | >actual && |
| 79 | test_cmp expect actual |
| 80 | ) |
| 81 | ' |
| 82 | |
| 83 | cat >super/expect_error <<EOF |
| 84 | Submodule name: 'a' for path 'b' |
| 85 | Submodule name: 'submodule' for path 'submodule' |
| 86 | EOF |
| 87 | |
Antonio Ospite | d1b13df | 2018-10-05 15:05:54 +0200 | [diff] [blame] | 88 | test_expect_success 'error in history of one submodule config lets continue, stderr message contains blob ref' ' |
Antonio Ospite | 996df4d | 2018-10-05 15:05:55 +0200 | [diff] [blame] | 89 | ORIG=$(git -C super rev-parse HEAD) && |
| 90 | test_when_finished "git -C super reset --hard $ORIG" && |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 91 | (cd super && |
| 92 | cp .gitmodules .gitmodules.bak && |
| 93 | echo " value = \"" >>.gitmodules && |
| 94 | git add .gitmodules && |
| 95 | mv .gitmodules.bak .gitmodules && |
| 96 | git commit -m "add error" && |
Heiko Voigt | 514dea9 | 2016-07-28 14:49:11 +0200 | [diff] [blame] | 97 | sha1=$(git rev-parse HEAD) && |
Nguyễn Thái Ngọc Duy | b618821 | 2018-03-24 08:45:01 +0100 | [diff] [blame] | 98 | test-tool submodule-config \ |
Heiko Voigt | 514dea9 | 2016-07-28 14:49:11 +0200 | [diff] [blame] | 99 | HEAD b \ |
| 100 | HEAD submodule \ |
Antonio Ospite | d1b13df | 2018-10-05 15:05:54 +0200 | [diff] [blame] | 101 | >actual \ |
| 102 | 2>actual_stderr && |
| 103 | test_cmp expect_error actual && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 104 | test_grep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null |
Heiko Voigt | 514dea9 | 2016-07-28 14:49:11 +0200 | [diff] [blame] | 105 | ) |
| 106 | ' |
| 107 | |
Stefan Beller | 73c293b | 2016-11-22 12:14:37 -0800 | [diff] [blame] | 108 | test_expect_success 'using different treeishs works' ' |
| 109 | ( |
| 110 | cd super && |
| 111 | git tag new_tag && |
| 112 | tree=$(git rev-parse HEAD^{tree}) && |
| 113 | commit=$(git rev-parse HEAD^{commit}) && |
Nguyễn Thái Ngọc Duy | b618821 | 2018-03-24 08:45:01 +0100 | [diff] [blame] | 114 | test-tool submodule-config $commit b >expect && |
| 115 | test-tool submodule-config $tree b >actual.1 && |
| 116 | test-tool submodule-config new_tag b >actual.2 && |
Stefan Beller | 73c293b | 2016-11-22 12:14:37 -0800 | [diff] [blame] | 117 | test_cmp expect actual.1 && |
| 118 | test_cmp expect actual.2 |
| 119 | ) |
| 120 | ' |
| 121 | |
Heiko Voigt | 027771f | 2015-08-17 17:22:00 -0700 | [diff] [blame] | 122 | test_expect_success 'error in history in fetchrecursesubmodule lets continue' ' |
Antonio Ospite | 996df4d | 2018-10-05 15:05:55 +0200 | [diff] [blame] | 123 | ORIG=$(git -C super rev-parse HEAD) && |
| 124 | test_when_finished "git -C super reset --hard $ORIG" && |
Heiko Voigt | 027771f | 2015-08-17 17:22:00 -0700 | [diff] [blame] | 125 | (cd super && |
| 126 | git config -f .gitmodules \ |
| 127 | submodule.submodule.fetchrecursesubmodules blabla && |
| 128 | git add .gitmodules && |
| 129 | git config --unset -f .gitmodules \ |
| 130 | submodule.submodule.fetchrecursesubmodules && |
| 131 | git commit -m "add error in fetchrecursesubmodules" && |
Nguyễn Thái Ngọc Duy | b618821 | 2018-03-24 08:45:01 +0100 | [diff] [blame] | 132 | test-tool submodule-config \ |
Heiko Voigt | 027771f | 2015-08-17 17:22:00 -0700 | [diff] [blame] | 133 | HEAD b \ |
| 134 | HEAD submodule \ |
| 135 | >actual && |
Antonio Ospite | 996df4d | 2018-10-05 15:05:55 +0200 | [diff] [blame] | 136 | test_cmp expect_error actual |
Heiko Voigt | 027771f | 2015-08-17 17:22:00 -0700 | [diff] [blame] | 137 | ) |
| 138 | ' |
| 139 | |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 140 | test_expect_success 'reading submodules config from the working tree' ' |
Antonio Ospite | 2502ffc | 2018-10-05 15:05:56 +0200 | [diff] [blame] | 141 | (cd super && |
| 142 | echo "../submodule" >expect && |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 143 | test-tool submodule config-list submodule.submodule.url >actual && |
Antonio Ospite | 2502ffc | 2018-10-05 15:05:56 +0200 | [diff] [blame] | 144 | test_cmp expect actual |
| 145 | ) |
| 146 | ' |
| 147 | |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 148 | test_expect_success 'unsetting submodules config from the working tree' ' |
Denton Liu | c89c494 | 2019-02-08 03:21:31 -0800 | [diff] [blame] | 149 | (cd super && |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 150 | test-tool submodule config-unset submodule.submodule.url && |
| 151 | test-tool submodule config-list submodule.submodule.url >actual && |
Denton Liu | c89c494 | 2019-02-08 03:21:31 -0800 | [diff] [blame] | 152 | test_must_be_empty actual |
| 153 | ) |
| 154 | ' |
| 155 | |
| 156 | |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 157 | test_expect_success 'writing submodules config' ' |
Antonio Ospite | 2502ffc | 2018-10-05 15:05:56 +0200 | [diff] [blame] | 158 | (cd super && |
| 159 | echo "new_url" >expect && |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 160 | test-tool submodule config-set submodule.submodule.url "new_url" && |
| 161 | test-tool submodule config-list submodule.submodule.url >actual && |
Antonio Ospite | 2502ffc | 2018-10-05 15:05:56 +0200 | [diff] [blame] | 162 | test_cmp expect actual |
| 163 | ) |
| 164 | ' |
| 165 | |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 166 | test_expect_success 'overwriting unstaged submodules config' ' |
Antonio Ospite | 2502ffc | 2018-10-05 15:05:56 +0200 | [diff] [blame] | 167 | test_when_finished "git -C super checkout .gitmodules" && |
| 168 | (cd super && |
| 169 | echo "newer_url" >expect && |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 170 | test-tool submodule config-set submodule.submodule.url "newer_url" && |
| 171 | test-tool submodule config-list submodule.submodule.url >actual && |
Antonio Ospite | 2502ffc | 2018-10-05 15:05:56 +0200 | [diff] [blame] | 172 | test_cmp expect actual |
| 173 | ) |
| 174 | ' |
| 175 | |
Antonio Ospite | b5c259f | 2018-10-05 15:05:59 +0200 | [diff] [blame] | 176 | test_expect_success 'writeable .gitmodules when it is in the working tree' ' |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 177 | test-tool -C super submodule config-writeable |
Antonio Ospite | b5c259f | 2018-10-05 15:05:59 +0200 | [diff] [blame] | 178 | ' |
| 179 | |
| 180 | test_expect_success 'writeable .gitmodules when it is nowhere in the repository' ' |
| 181 | ORIG=$(git -C super rev-parse HEAD) && |
| 182 | test_when_finished "git -C super reset --hard $ORIG" && |
| 183 | (cd super && |
| 184 | git rm .gitmodules && |
| 185 | git commit -m "remove .gitmodules from the current branch" && |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 186 | test-tool submodule config-writeable |
Antonio Ospite | b5c259f | 2018-10-05 15:05:59 +0200 | [diff] [blame] | 187 | ) |
| 188 | ' |
| 189 | |
| 190 | test_expect_success 'non-writeable .gitmodules when it is in the index but not in the working tree' ' |
| 191 | test_when_finished "git -C super checkout .gitmodules" && |
| 192 | (cd super && |
| 193 | rm -f .gitmodules && |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 194 | test_must_fail test-tool submodule config-writeable |
Antonio Ospite | b5c259f | 2018-10-05 15:05:59 +0200 | [diff] [blame] | 195 | ) |
| 196 | ' |
| 197 | |
| 198 | test_expect_success 'non-writeable .gitmodules when it is in the current branch but not in the index' ' |
| 199 | ORIG=$(git -C super rev-parse HEAD) && |
| 200 | test_when_finished "git -C super reset --hard $ORIG" && |
| 201 | (cd super && |
| 202 | git rm .gitmodules && |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 203 | test_must_fail test-tool submodule config-writeable |
Antonio Ospite | b5c259f | 2018-10-05 15:05:59 +0200 | [diff] [blame] | 204 | ) |
| 205 | ' |
| 206 | |
Antonio Ospite | 76e9bdc | 2018-10-25 18:18:12 +0200 | [diff] [blame] | 207 | test_expect_success 'reading submodules config from the index when .gitmodules is not in the working tree' ' |
| 208 | ORIG=$(git -C super rev-parse HEAD) && |
| 209 | test_when_finished "git -C super reset --hard $ORIG" && |
| 210 | (cd super && |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 211 | test-tool submodule config-set submodule.submodule.url "staged_url" && |
Antonio Ospite | 76e9bdc | 2018-10-25 18:18:12 +0200 | [diff] [blame] | 212 | git add .gitmodules && |
| 213 | rm -f .gitmodules && |
| 214 | echo "staged_url" >expect && |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 215 | test-tool submodule config-list submodule.submodule.url >actual && |
Antonio Ospite | 76e9bdc | 2018-10-25 18:18:12 +0200 | [diff] [blame] | 216 | test_cmp expect actual |
| 217 | ) |
| 218 | ' |
| 219 | |
| 220 | test_expect_success 'reading submodules config from the current branch when .gitmodules is not in the index' ' |
| 221 | ORIG=$(git -C super rev-parse HEAD) && |
| 222 | test_when_finished "git -C super reset --hard $ORIG" && |
| 223 | (cd super && |
| 224 | git rm .gitmodules && |
| 225 | echo "../submodule" >expect && |
Ævar Arnfjörð Bjarmason | cc74a4a | 2022-11-08 15:10:32 +0100 | [diff] [blame] | 226 | test-tool submodule config-list submodule.submodule.url >actual && |
Antonio Ospite | 76e9bdc | 2018-10-25 18:18:12 +0200 | [diff] [blame] | 227 | test_cmp expect actual |
| 228 | ) |
| 229 | ' |
| 230 | |
Antonio Ospite | 2b1257e | 2018-10-25 18:18:13 +0200 | [diff] [blame] | 231 | test_expect_success 'reading nested submodules config' ' |
| 232 | (cd super && |
| 233 | git init submodule/nested_submodule && |
| 234 | echo "a" >submodule/nested_submodule/a && |
| 235 | git -C submodule/nested_submodule add a && |
| 236 | git -C submodule/nested_submodule commit -m "add a" && |
| 237 | git -C submodule submodule add ./nested_submodule && |
| 238 | git -C submodule add nested_submodule && |
| 239 | git -C submodule commit -m "added nested_submodule" && |
| 240 | git add submodule && |
| 241 | git commit -m "updated submodule" && |
| 242 | echo "./nested_submodule" >expect && |
| 243 | test-tool submodule-nested-repo-config \ |
| 244 | submodule submodule.nested_submodule.url >actual && |
| 245 | test_cmp expect actual |
| 246 | ) |
| 247 | ' |
| 248 | |
Jeff King | 581d2fd | 2019-05-14 09:54:55 -0400 | [diff] [blame] | 249 | test_expect_success 'reading nested submodules config when .gitmodules is not in the working tree' ' |
Antonio Ospite | 2b1257e | 2018-10-25 18:18:13 +0200 | [diff] [blame] | 250 | test_when_finished "git -C super/submodule checkout .gitmodules" && |
| 251 | (cd super && |
| 252 | echo "./nested_submodule" >expect && |
| 253 | rm submodule/.gitmodules && |
| 254 | test-tool submodule-nested-repo-config \ |
| 255 | submodule submodule.nested_submodule.url >actual 2>warning && |
Jeff King | 581d2fd | 2019-05-14 09:54:55 -0400 | [diff] [blame] | 256 | test_must_be_empty warning && |
Antonio Ospite | 2b1257e | 2018-10-25 18:18:13 +0200 | [diff] [blame] | 257 | test_cmp expect actual |
| 258 | ) |
| 259 | ' |
| 260 | |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 261 | test_done |