| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2008 David Aguilar |
| 4 | # |
| 5 | |
| 6 | test_description='git submodule sync |
| 7 | |
| 8 | These tests exercise the "git submodule sync" subcommand. |
| 9 | ' |
| 10 | |
| 11 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 12 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 13 | |
| 14 | . ./test-lib.sh |
| 15 | |
| 16 | test_expect_success setup ' |
| 17 | git config --global protocol.file.allow always && |
| 18 | |
| 19 | echo file >file && |
| 20 | git add file && |
| 21 | test_tick && |
| 22 | git commit -m upstream && |
| 23 | git clone . super && |
| 24 | git clone super submodule && |
| 25 | ( |
| 26 | cd submodule && |
| 27 | git submodule add ../submodule sub-submodule && |
| 28 | test_tick && |
| 29 | git commit -m "sub-submodule" |
| 30 | ) && |
| 31 | ( |
| 32 | cd super && |
| 33 | git submodule add ../submodule submodule && |
| 34 | test_tick && |
| 35 | git commit -m "submodule" |
| 36 | ) && |
| 37 | git clone super super-clone && |
| 38 | ( |
| 39 | cd super-clone && |
| 40 | git submodule update --init --recursive |
| 41 | ) && |
| 42 | git clone super empty-clone && |
| 43 | ( |
| 44 | cd empty-clone && |
| 45 | git submodule init |
| 46 | ) && |
| 47 | git clone super top-only-clone && |
| 48 | git clone super relative-clone && |
| 49 | ( |
| 50 | cd relative-clone && |
| 51 | git submodule update --init --recursive |
| 52 | ) && |
| 53 | git clone super recursive-clone && |
| 54 | ( |
| 55 | cd recursive-clone && |
| 56 | git submodule update --init --recursive |
| 57 | ) |
| 58 | ' |
| 59 | |
| 60 | test_expect_success 'change submodule' ' |
| 61 | ( |
| 62 | cd submodule && |
| 63 | echo second line >>file && |
| 64 | test_tick && |
| 65 | git commit -a -m "change submodule" |
| 66 | ) |
| 67 | ' |
| 68 | |
| 69 | reset_submodule_urls () { |
| 70 | ( |
| 71 | root=$(pwd) && |
| 72 | cd super-clone/submodule && |
| 73 | git config remote.origin.url "$root/submodule" |
| 74 | ) && |
| 75 | ( |
| 76 | root=$(pwd) && |
| 77 | cd super-clone/submodule/sub-submodule && |
| 78 | git config remote.origin.url "$root/submodule" |
| 79 | ) |
| 80 | } |
| 81 | |
| 82 | test_expect_success 'change submodule url' ' |
| 83 | ( |
| 84 | cd super && |
| 85 | cd submodule && |
| 86 | git checkout main && |
| 87 | git pull |
| 88 | ) && |
| 89 | mv submodule moved-submodule && |
| 90 | ( |
| 91 | cd moved-submodule && |
| 92 | git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule && |
| 93 | test_tick && |
| 94 | git commit -a -m moved-sub-submodule |
| 95 | ) && |
| 96 | ( |
| 97 | cd super && |
| 98 | git config -f .gitmodules submodule.submodule.url ../moved-submodule && |
| 99 | test_tick && |
| 100 | git commit -a -m moved-submodule |
| 101 | ) |
| 102 | ' |
| 103 | |
| 104 | test_expect_success '"git submodule sync" should update submodule URLs' ' |
| 105 | ( |
| 106 | cd super-clone && |
| 107 | git pull --no-recurse-submodules && |
| 108 | git submodule sync |
| 109 | ) && |
| 110 | test -d "$( |
| 111 | cd super-clone/submodule && |
| 112 | git config remote.origin.url |
| 113 | )" && |
| 114 | test ! -d "$( |
| 115 | cd super-clone/submodule/sub-submodule && |
| 116 | git config remote.origin.url |
| 117 | )" && |
| 118 | ( |
| 119 | cd super-clone/submodule && |
| 120 | git checkout main && |
| 121 | git pull |
| 122 | ) && |
| 123 | ( |
| 124 | cd super-clone && |
| 125 | test -d "$(git config submodule.submodule.url)" |
| 126 | ) |
| 127 | ' |
| 128 | |
| 129 | test_expect_success '"git submodule sync --recursive" should update all submodule URLs' ' |
| 130 | ( |
| 131 | cd super-clone && |
| 132 | ( |
| 133 | cd submodule && |
| 134 | git pull --no-recurse-submodules |
| 135 | ) && |
| 136 | git submodule sync --recursive |
| 137 | ) && |
| 138 | test -d "$( |
| 139 | cd super-clone/submodule && |
| 140 | git config remote.origin.url |
| 141 | )" && |
| 142 | test -d "$( |
| 143 | cd super-clone/submodule/sub-submodule && |
| 144 | git config remote.origin.url |
| 145 | )" && |
| 146 | ( |
| 147 | cd super-clone/submodule/sub-submodule && |
| 148 | git checkout main && |
| 149 | git pull |
| 150 | ) |
| 151 | ' |
| 152 | |
| 153 | test_expect_success 'reset submodule URLs' ' |
| 154 | reset_submodule_urls super-clone |
| 155 | ' |
| 156 | |
| 157 | test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' ' |
| 158 | ( |
| 159 | cd super-clone && |
| 160 | git pull --no-recurse-submodules && |
| 161 | mkdir -p sub && |
| 162 | cd sub && |
| 163 | git submodule sync >../../output |
| 164 | ) && |
| 165 | test_grep "\\.\\./submodule" output && |
| 166 | test -d "$( |
| 167 | cd super-clone/submodule && |
| 168 | git config remote.origin.url |
| 169 | )" && |
| 170 | test ! -d "$( |
| 171 | cd super-clone/submodule/sub-submodule && |
| 172 | git config remote.origin.url |
| 173 | )" && |
| 174 | ( |
| 175 | cd super-clone/submodule && |
| 176 | git checkout main && |
| 177 | git pull |
| 178 | ) && |
| 179 | ( |
| 180 | cd super-clone && |
| 181 | test -d "$(git config submodule.submodule.url)" |
| 182 | ) |
| 183 | ' |
| 184 | |
| 185 | test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' ' |
| 186 | ( |
| 187 | cd super-clone && |
| 188 | ( |
| 189 | cd submodule && |
| 190 | git pull --no-recurse-submodules |
| 191 | ) && |
| 192 | mkdir -p sub && |
| 193 | cd sub && |
| 194 | git submodule sync --recursive >../../output |
| 195 | ) && |
| 196 | test_grep "\\.\\./submodule/sub-submodule" output && |
| 197 | test -d "$( |
| 198 | cd super-clone/submodule && |
| 199 | git config remote.origin.url |
| 200 | )" && |
| 201 | test -d "$( |
| 202 | cd super-clone/submodule/sub-submodule && |
| 203 | git config remote.origin.url |
| 204 | )" && |
| 205 | ( |
| 206 | cd super-clone/submodule/sub-submodule && |
| 207 | git checkout main && |
| 208 | git pull |
| 209 | ) |
| 210 | ' |
| 211 | |
| 212 | test_expect_success '"git submodule sync" should update known submodule URLs' ' |
| 213 | ( |
| 214 | cd empty-clone && |
| 215 | git pull && |
| 216 | git submodule sync && |
| 217 | test -d "$(git config submodule.submodule.url)" |
| 218 | ) |
| 219 | ' |
| 220 | |
| 221 | test_expect_success '"git submodule sync" should not vivify uninteresting submodule' ' |
| 222 | ( |
| 223 | cd top-only-clone && |
| 224 | git pull && |
| 225 | git submodule sync && |
| 226 | test -z "$(git config submodule.submodule.url)" && |
| 227 | git submodule sync submodule && |
| 228 | test -z "$(git config submodule.submodule.url)" |
| 229 | ) |
| 230 | ' |
| 231 | |
| 232 | test_expect_success '"git submodule sync" handles origin URL of the form foo' ' |
| 233 | ( |
| 234 | cd relative-clone && |
| 235 | git remote set-url origin foo && |
| 236 | git submodule sync && |
| 237 | ( |
| 238 | cd submodule && |
| 239 | #actual fails with: "cannot strip off url foo |
| 240 | test "$(git config remote.origin.url)" = "../submodule" |
| 241 | ) |
| 242 | ) |
| 243 | ' |
| 244 | |
| 245 | test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' ' |
| 246 | ( |
| 247 | cd relative-clone && |
| 248 | git remote set-url origin foo/bar && |
| 249 | git submodule sync && |
| 250 | ( |
| 251 | cd submodule && |
| 252 | #actual foo/submodule |
| 253 | test "$(git config remote.origin.url)" = "../foo/submodule" |
| 254 | ) && |
| 255 | ( |
| 256 | cd submodule/sub-submodule && |
| 257 | test "$(git config remote.origin.url)" != "../../foo/submodule" |
| 258 | ) |
| 259 | ) |
| 260 | ' |
| 261 | |
| 262 | test_expect_success '"git submodule sync --recursive" propagates changes in origin' ' |
| 263 | ( |
| 264 | cd recursive-clone && |
| 265 | git remote set-url origin foo/bar && |
| 266 | git submodule sync --recursive && |
| 267 | ( |
| 268 | cd submodule && |
| 269 | #actual foo/submodule |
| 270 | test "$(git config remote.origin.url)" = "../foo/submodule" |
| 271 | ) && |
| 272 | ( |
| 273 | cd submodule/sub-submodule && |
| 274 | test "$(git config remote.origin.url)" = "../../foo/submodule" |
| 275 | ) |
| 276 | ) |
| 277 | ' |
| 278 | |
| 279 | test_expect_success '"git submodule sync" handles origin URL of the form ./foo' ' |
| 280 | ( |
| 281 | cd relative-clone && |
| 282 | git remote set-url origin ./foo && |
| 283 | git submodule sync && |
| 284 | ( |
| 285 | cd submodule && |
| 286 | #actual ./submodule |
| 287 | test "$(git config remote.origin.url)" = "../submodule" |
| 288 | ) |
| 289 | ) |
| 290 | ' |
| 291 | |
| 292 | test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' ' |
| 293 | ( |
| 294 | cd relative-clone && |
| 295 | git remote set-url origin ./foo/bar && |
| 296 | git submodule sync && |
| 297 | ( |
| 298 | cd submodule && |
| 299 | #actual ./foo/submodule |
| 300 | test "$(git config remote.origin.url)" = "../foo/submodule" |
| 301 | ) |
| 302 | ) |
| 303 | ' |
| 304 | |
| 305 | test_expect_success '"git submodule sync" handles origin URL of the form ../foo' ' |
| 306 | ( |
| 307 | cd relative-clone && |
| 308 | git remote set-url origin ../foo && |
| 309 | git submodule sync && |
| 310 | ( |
| 311 | cd submodule && |
| 312 | #actual ../submodule |
| 313 | test "$(git config remote.origin.url)" = "../../submodule" |
| 314 | ) |
| 315 | ) |
| 316 | ' |
| 317 | |
| 318 | test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' ' |
| 319 | ( |
| 320 | cd relative-clone && |
| 321 | git remote set-url origin ../foo/bar && |
| 322 | git submodule sync && |
| 323 | ( |
| 324 | cd submodule && |
| 325 | #actual ../foo/submodule |
| 326 | test "$(git config remote.origin.url)" = "../../foo/submodule" |
| 327 | ) |
| 328 | ) |
| 329 | ' |
| 330 | |
| 331 | test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' ' |
| 332 | ( |
| 333 | cd relative-clone && |
| 334 | git remote set-url origin ../foo/bar && |
| 335 | mkdir -p a/b/c && |
| 336 | ( |
| 337 | cd a/b/c && |
| 338 | git init && |
| 339 | >.gitignore && |
| 340 | git add .gitignore && |
| 341 | test_tick && |
| 342 | git commit -m "initial commit" |
| 343 | ) && |
| 344 | git submodule add ../bar/a/b/c ./a/b/c && |
| 345 | git submodule sync && |
| 346 | ( |
| 347 | cd a/b/c && |
| 348 | #actual ../foo/bar/a/b/c |
| 349 | test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c" |
| 350 | ) |
| 351 | ) |
| 352 | ' |
| 353 | |
| 354 | |
| 355 | test_done |