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