| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2009 Red Hat, Inc. |
| 4 | # |
| 5 | |
| 6 | test_description='Test updating submodules |
| 7 | |
| 8 | This test verifies that "git submodule update" detaches the HEAD of the |
| 9 | submodule and "git submodule update --rebase/--merge" does not detach the HEAD. |
| 10 | ' |
| 11 | |
| 12 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 13 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 14 | |
| 15 | . ./test-lib.sh |
| 16 | |
| 17 | |
| 18 | compare_head() |
| 19 | { |
| 20 | sha_main=$(git rev-list --max-count=1 main) |
| 21 | sha_head=$(git rev-list --max-count=1 HEAD) |
| 22 | |
| 23 | test "$sha_main" = "$sha_head" |
| 24 | } |
| 25 | |
| 26 | |
| 27 | test_expect_success 'setup a submodule tree' ' |
| 28 | git config --global protocol.file.allow always && |
| 29 | echo file > file && |
| 30 | git add file && |
| 31 | test_tick && |
| 32 | git commit -m upstream && |
| 33 | git clone . super && |
| 34 | git clone super submodule && |
| 35 | git clone super rebasing && |
| 36 | git clone super merging && |
| 37 | git clone super none && |
| 38 | (cd super && |
| 39 | git submodule add ../submodule submodule && |
| 40 | test_tick && |
| 41 | git commit -m "submodule" && |
| 42 | git submodule init submodule |
| 43 | ) && |
| 44 | (cd submodule && |
| 45 | echo "line2" > file && |
| 46 | git add file && |
| 47 | git commit -m "Commit 2" |
| 48 | ) && |
| 49 | (cd super && |
| 50 | (cd submodule && |
| 51 | git pull --rebase origin |
| 52 | ) && |
| 53 | git add submodule && |
| 54 | git commit -m "submodule update" |
| 55 | ) && |
| 56 | (cd super && |
| 57 | git submodule add ../rebasing rebasing && |
| 58 | test_tick && |
| 59 | git commit -m "rebasing" |
| 60 | ) && |
| 61 | (cd super && |
| 62 | git submodule add ../merging merging && |
| 63 | test_tick && |
| 64 | git commit -m "rebasing" |
| 65 | ) && |
| 66 | (cd super && |
| 67 | git submodule add ../none none && |
| 68 | test_tick && |
| 69 | git commit -m "none" |
| 70 | ) && |
| 71 | git clone . recursivesuper && |
| 72 | ( cd recursivesuper && |
| 73 | git submodule add ../super super |
| 74 | ) |
| 75 | ' |
| 76 | |
| 77 | test_expect_success 'update --remote falls back to using HEAD' ' |
| 78 | test_create_repo main-branch-submodule && |
| 79 | test_commit -C main-branch-submodule initial && |
| 80 | |
| 81 | test_create_repo main-branch && |
| 82 | git -C main-branch submodule add ../main-branch-submodule && |
| 83 | git -C main-branch commit -m add-submodule && |
| 84 | |
| 85 | git -C main-branch-submodule switch -c hello && |
| 86 | test_commit -C main-branch-submodule world && |
| 87 | |
| 88 | git clone --recursive main-branch main-branch-clone && |
| 89 | git -C main-branch-clone submodule update --remote main-branch-submodule && |
| 90 | test_path_exists main-branch-clone/main-branch-submodule/world.t |
| 91 | ' |
| 92 | |
| 93 | test_expect_success 'submodule update detaching the HEAD ' ' |
| 94 | (cd super/submodule && |
| 95 | git reset --hard HEAD~1 |
| 96 | ) && |
| 97 | (cd super && |
| 98 | (cd submodule && |
| 99 | compare_head |
| 100 | ) && |
| 101 | git submodule update submodule && |
| 102 | cd submodule && |
| 103 | ! compare_head |
| 104 | ) |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'submodule update from subdirectory' ' |
| 108 | (cd super/submodule && |
| 109 | git reset --hard HEAD~1 |
| 110 | ) && |
| 111 | mkdir super/sub && |
| 112 | (cd super/sub && |
| 113 | (cd ../submodule && |
| 114 | compare_head |
| 115 | ) && |
| 116 | git submodule update ../submodule && |
| 117 | cd ../submodule && |
| 118 | ! compare_head |
| 119 | ) |
| 120 | ' |
| 121 | |
| 122 | supersha1=$(git -C super rev-parse HEAD) |
| 123 | mergingsha1=$(git -C super/merging rev-parse HEAD) |
| 124 | nonesha1=$(git -C super/none rev-parse HEAD) |
| 125 | rebasingsha1=$(git -C super/rebasing rev-parse HEAD) |
| 126 | submodulesha1=$(git -C super/submodule rev-parse HEAD) |
| 127 | pwd=$(pwd) |
| 128 | |
| 129 | cat <<EOF >expect |
| 130 | Submodule path '../super': checked out '$supersha1' |
| 131 | Submodule path '../super/merging': checked out '$mergingsha1' |
| 132 | Submodule path '../super/none': checked out '$nonesha1' |
| 133 | Submodule path '../super/rebasing': checked out '$rebasingsha1' |
| 134 | Submodule path '../super/submodule': checked out '$submodulesha1' |
| 135 | EOF |
| 136 | |
| 137 | cat <<EOF >expect2 |
| 138 | Cloning into '$pwd/recursivesuper/super/merging'... |
| 139 | Cloning into '$pwd/recursivesuper/super/none'... |
| 140 | Cloning into '$pwd/recursivesuper/super/rebasing'... |
| 141 | Cloning into '$pwd/recursivesuper/super/submodule'... |
| 142 | Submodule 'merging' ($pwd/merging) registered for path '../super/merging' |
| 143 | Submodule 'none' ($pwd/none) registered for path '../super/none' |
| 144 | Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing' |
| 145 | Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule' |
| 146 | done. |
| 147 | done. |
| 148 | done. |
| 149 | done. |
| 150 | EOF |
| 151 | |
| 152 | test_expect_success 'submodule update --init --recursive from subdirectory' ' |
| 153 | git -C recursivesuper/super reset --hard HEAD^ && |
| 154 | (cd recursivesuper && |
| 155 | mkdir tmp && |
| 156 | cd tmp && |
| 157 | git submodule update --init --recursive ../super >../../actual 2>../../actual2 |
| 158 | ) && |
| 159 | test_cmp expect actual && |
| 160 | sort actual2 >actual2.sorted && |
| 161 | test_cmp expect2 actual2.sorted |
| 162 | ' |
| 163 | |
| 164 | cat <<EOF >expect2 |
| 165 | Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub' |
| 166 | EOF |
| 167 | |
| 168 | test_expect_success 'submodule update --init from and of subdirectory' ' |
| 169 | git init withsubs && |
| 170 | (cd withsubs && |
| 171 | mkdir foo && |
| 172 | git submodule add "$(pwd)/../rebasing" foo/sub && |
| 173 | (cd foo && |
| 174 | git submodule deinit -f sub && |
| 175 | git submodule update --init sub 2>../../actual2 |
| 176 | ) |
| 177 | ) && |
| 178 | test_cmp expect2 actual2 |
| 179 | ' |
| 180 | |
| 181 | test_expect_success 'submodule update does not fetch already present commits' ' |
| 182 | (cd submodule && |
| 183 | echo line3 >> file && |
| 184 | git add file && |
| 185 | test_tick && |
| 186 | git commit -m "upstream line3" |
| 187 | ) && |
| 188 | (cd super/submodule && |
| 189 | head=$(git rev-parse --verify HEAD) && |
| 190 | echo "Submodule path ${SQ}submodule$SQ: checked out $SQ$head$SQ" > ../../expected && |
| 191 | git reset --hard HEAD~1 |
| 192 | ) && |
| 193 | (cd super && |
| 194 | git submodule update > ../actual 2> ../actual.err |
| 195 | ) && |
| 196 | test_cmp expected actual && |
| 197 | test_must_be_empty actual.err |
| 198 | ' |
| 199 | |
| 200 | test_expect_success 'submodule update should fail due to local changes' ' |
| 201 | (cd super/submodule && |
| 202 | git reset --hard HEAD~1 && |
| 203 | echo "local change" > file |
| 204 | ) && |
| 205 | (cd super && |
| 206 | (cd submodule && |
| 207 | compare_head |
| 208 | ) && |
| 209 | test_must_fail git submodule update submodule 2>../actual.raw |
| 210 | ) && |
| 211 | sed "s/^> //" >expect <<-\EOF && |
| 212 | > error: Your local changes to the following files would be overwritten by checkout: |
| 213 | > file |
| 214 | > Please commit your changes or stash them before you switch branches. |
| 215 | > Aborting |
| 216 | > fatal: Unable to checkout OID in submodule path '\''submodule'\'' |
| 217 | EOF |
| 218 | sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" <actual.raw >actual && |
| 219 | test_cmp expect actual |
| 220 | |
| 221 | ' |
| 222 | test_expect_success 'submodule update should throw away changes with --force ' ' |
| 223 | (cd super && |
| 224 | (cd submodule && |
| 225 | compare_head |
| 226 | ) && |
| 227 | git submodule update --force submodule && |
| 228 | cd submodule && |
| 229 | ! compare_head |
| 230 | ) |
| 231 | ' |
| 232 | |
| 233 | test_expect_success 'submodule update --force forcibly checks out submodules' ' |
| 234 | (cd super && |
| 235 | (cd submodule && |
| 236 | rm -f file |
| 237 | ) && |
| 238 | git submodule update --force submodule && |
| 239 | (cd submodule && |
| 240 | test "$(git status -s file)" = "" |
| 241 | ) |
| 242 | ) |
| 243 | ' |
| 244 | |
| 245 | test_expect_success 'submodule update --remote should fetch upstream changes' ' |
| 246 | (cd submodule && |
| 247 | echo line4 >> file && |
| 248 | git add file && |
| 249 | test_tick && |
| 250 | git commit -m "upstream line4" |
| 251 | ) && |
| 252 | (cd super && |
| 253 | git submodule update --remote --force submodule && |
| 254 | cd submodule && |
| 255 | test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)" |
| 256 | ) |
| 257 | ' |
| 258 | |
| 259 | test_expect_success 'submodule update --remote should fetch upstream changes with .' ' |
| 260 | ( |
| 261 | cd super && |
| 262 | git config -f .gitmodules submodule."submodule".branch "." && |
| 263 | git add .gitmodules && |
| 264 | git commit -m "submodules: update from the respective superproject branch" |
| 265 | ) && |
| 266 | ( |
| 267 | cd submodule && |
| 268 | echo line4a >> file && |
| 269 | git add file && |
| 270 | test_tick && |
| 271 | git commit -m "upstream line4a" && |
| 272 | git checkout -b test-branch && |
| 273 | test_commit on-test-branch |
| 274 | ) && |
| 275 | ( |
| 276 | cd super && |
| 277 | git submodule update --remote --force submodule && |
| 278 | git -C submodule log -1 --oneline >actual && |
| 279 | git -C ../submodule log -1 --oneline main >expect && |
| 280 | test_cmp expect actual && |
| 281 | git checkout -b test-branch && |
| 282 | git submodule update --remote --force submodule && |
| 283 | git -C submodule log -1 --oneline >actual && |
| 284 | git -C ../submodule log -1 --oneline test-branch >expect && |
| 285 | test_cmp expect actual && |
| 286 | git checkout main && |
| 287 | git branch -d test-branch && |
| 288 | git reset --hard HEAD^ |
| 289 | ) |
| 290 | ' |
| 291 | |
| 292 | test_expect_success 'local config should override .gitmodules branch' ' |
| 293 | (cd submodule && |
| 294 | git checkout test-branch && |
| 295 | echo line5 >> file && |
| 296 | git add file && |
| 297 | test_tick && |
| 298 | git commit -m "upstream line5" && |
| 299 | git checkout main |
| 300 | ) && |
| 301 | (cd super && |
| 302 | git config submodule.submodule.branch test-branch && |
| 303 | git submodule update --remote --force submodule && |
| 304 | cd submodule && |
| 305 | test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)" |
| 306 | ) |
| 307 | ' |
| 308 | |
| 309 | test_expect_success 'submodule update --rebase staying on main' ' |
| 310 | (cd super/submodule && |
| 311 | git checkout main |
| 312 | ) && |
| 313 | (cd super && |
| 314 | (cd submodule && |
| 315 | compare_head |
| 316 | ) && |
| 317 | git submodule update --rebase submodule && |
| 318 | cd submodule && |
| 319 | compare_head |
| 320 | ) |
| 321 | ' |
| 322 | |
| 323 | test_expect_success 'submodule update --merge staying on main' ' |
| 324 | (cd super/submodule && |
| 325 | git reset --hard HEAD~1 |
| 326 | ) && |
| 327 | (cd super && |
| 328 | (cd submodule && |
| 329 | compare_head |
| 330 | ) && |
| 331 | git submodule update --merge submodule && |
| 332 | cd submodule && |
| 333 | compare_head |
| 334 | ) |
| 335 | ' |
| 336 | |
| 337 | test_expect_success 'submodule update - rebase in .git/config' ' |
| 338 | (cd super && |
| 339 | git config submodule.submodule.update rebase |
| 340 | ) && |
| 341 | (cd super/submodule && |
| 342 | git reset --hard HEAD~1 |
| 343 | ) && |
| 344 | (cd super && |
| 345 | (cd submodule && |
| 346 | compare_head |
| 347 | ) && |
| 348 | git submodule update submodule && |
| 349 | cd submodule && |
| 350 | compare_head |
| 351 | ) |
| 352 | ' |
| 353 | |
| 354 | test_expect_success 'submodule update - checkout in .git/config but --rebase given' ' |
| 355 | (cd super && |
| 356 | git config submodule.submodule.update checkout |
| 357 | ) && |
| 358 | (cd super/submodule && |
| 359 | git reset --hard HEAD~1 |
| 360 | ) && |
| 361 | (cd super && |
| 362 | (cd submodule && |
| 363 | compare_head |
| 364 | ) && |
| 365 | git submodule update --rebase submodule && |
| 366 | cd submodule && |
| 367 | compare_head |
| 368 | ) |
| 369 | ' |
| 370 | |
| 371 | test_expect_success 'submodule update - merge in .git/config' ' |
| 372 | (cd super && |
| 373 | git config submodule.submodule.update merge |
| 374 | ) && |
| 375 | (cd super/submodule && |
| 376 | git reset --hard HEAD~1 |
| 377 | ) && |
| 378 | (cd super && |
| 379 | (cd submodule && |
| 380 | compare_head |
| 381 | ) && |
| 382 | git submodule update submodule && |
| 383 | cd submodule && |
| 384 | compare_head |
| 385 | ) |
| 386 | ' |
| 387 | |
| 388 | test_expect_success 'submodule update - checkout in .git/config but --merge given' ' |
| 389 | (cd super && |
| 390 | git config submodule.submodule.update checkout |
| 391 | ) && |
| 392 | (cd super/submodule && |
| 393 | git reset --hard HEAD~1 |
| 394 | ) && |
| 395 | (cd super && |
| 396 | (cd submodule && |
| 397 | compare_head |
| 398 | ) && |
| 399 | git submodule update --merge submodule && |
| 400 | cd submodule && |
| 401 | compare_head |
| 402 | ) |
| 403 | ' |
| 404 | |
| 405 | test_expect_success 'submodule update - checkout in .git/config' ' |
| 406 | (cd super && |
| 407 | git config submodule.submodule.update checkout |
| 408 | ) && |
| 409 | (cd super/submodule && |
| 410 | git reset --hard HEAD^ |
| 411 | ) && |
| 412 | (cd super && |
| 413 | (cd submodule && |
| 414 | compare_head |
| 415 | ) && |
| 416 | git submodule update submodule && |
| 417 | cd submodule && |
| 418 | ! compare_head |
| 419 | ) |
| 420 | ' |
| 421 | |
| 422 | test_expect_success 'submodule update - command in .git/config' ' |
| 423 | (cd super && |
| 424 | git config submodule.submodule.update "!git checkout" |
| 425 | ) && |
| 426 | (cd super/submodule && |
| 427 | git reset --hard HEAD^ |
| 428 | ) && |
| 429 | (cd super && |
| 430 | (cd submodule && |
| 431 | compare_head |
| 432 | ) && |
| 433 | git submodule update submodule && |
| 434 | cd submodule && |
| 435 | ! compare_head |
| 436 | ) |
| 437 | ' |
| 438 | |
| 439 | test_expect_success 'submodule update - command in .gitmodules is rejected' ' |
| 440 | test_when_finished "git -C super reset --hard HEAD^" && |
| 441 | git -C super config -f .gitmodules submodule.submodule.update "!false" && |
| 442 | git -C super commit -a -m "add command to .gitmodules file" && |
| 443 | git -C super/submodule reset --hard $submodulesha1^ && |
| 444 | test_must_fail git -C super submodule update submodule |
| 445 | ' |
| 446 | |
| 447 | test_expect_success 'fsck detects command in .gitmodules' ' |
| 448 | git init command-in-gitmodules && |
| 449 | ( |
| 450 | cd command-in-gitmodules && |
| 451 | git submodule add ../submodule submodule && |
| 452 | test_commit adding-submodule && |
| 453 | |
| 454 | git config -f .gitmodules submodule.submodule.update "!false" && |
| 455 | git add .gitmodules && |
| 456 | test_commit configuring-update && |
| 457 | test_must_fail git fsck |
| 458 | ) |
| 459 | ' |
| 460 | |
| 461 | cat << EOF >expect |
| 462 | fatal: Execution of 'false $submodulesha1' failed in submodule path 'submodule' |
| 463 | EOF |
| 464 | |
| 465 | test_expect_success 'submodule update - command in .git/config catches failure' ' |
| 466 | (cd super && |
| 467 | git config submodule.submodule.update "!false" |
| 468 | ) && |
| 469 | (cd super/submodule && |
| 470 | git reset --hard $submodulesha1^ |
| 471 | ) && |
| 472 | (cd super && |
| 473 | test_must_fail git submodule update submodule 2>../actual |
| 474 | ) && |
| 475 | test_cmp actual expect |
| 476 | ' |
| 477 | |
| 478 | cat << EOF >expect |
| 479 | fatal: Execution of 'false $submodulesha1' failed in submodule path '../submodule' |
| 480 | EOF |
| 481 | |
| 482 | test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' ' |
| 483 | (cd super && |
| 484 | git config submodule.submodule.update "!false" |
| 485 | ) && |
| 486 | (cd super/submodule && |
| 487 | git reset --hard $submodulesha1^ |
| 488 | ) && |
| 489 | (cd super && |
| 490 | mkdir tmp && cd tmp && |
| 491 | test_must_fail git submodule update ../submodule 2>../../actual |
| 492 | ) && |
| 493 | test_cmp actual expect |
| 494 | ' |
| 495 | |
| 496 | test_expect_success 'submodule update - command run for initial population of submodule' ' |
| 497 | cat >expect <<-EOF && |
| 498 | fatal: Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\'' |
| 499 | EOF |
| 500 | rm -rf super/submodule && |
| 501 | test_must_fail git -C super submodule update 2>actual && |
| 502 | test_cmp expect actual && |
| 503 | git -C super submodule update --checkout |
| 504 | ' |
| 505 | |
| 506 | cat << EOF >expect |
| 507 | fatal: Execution of 'false $submodulesha1' failed in submodule path '../super/submodule' |
| 508 | fatal: Failed to recurse into submodule path '../super' |
| 509 | EOF |
| 510 | |
| 511 | test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' ' |
| 512 | (cd recursivesuper && |
| 513 | git submodule update --remote super && |
| 514 | git add super && |
| 515 | git commit -m "update to latest to have more than one commit in submodules" |
| 516 | ) && |
| 517 | git -C recursivesuper/super config submodule.submodule.update "!false" && |
| 518 | git -C recursivesuper/super/submodule reset --hard $submodulesha1^ && |
| 519 | (cd recursivesuper && |
| 520 | mkdir -p tmp && cd tmp && |
| 521 | test_must_fail git submodule update --recursive ../super 2>../../actual |
| 522 | ) && |
| 523 | test_cmp actual expect |
| 524 | ' |
| 525 | |
| 526 | test_expect_success 'submodule init does not copy command into .git/config' ' |
| 527 | test_when_finished "git -C super update-index --force-remove submodule1" && |
| 528 | test_when_finished git config -f super/.gitmodules \ |
| 529 | --remove-section submodule.submodule1 && |
| 530 | (cd super && |
| 531 | git ls-files -s submodule >out && |
| 532 | H=$(cut -d" " -f2 out) && |
| 533 | mkdir submodule1 && |
| 534 | git update-index --add --cacheinfo 160000 $H submodule1 && |
| 535 | git config -f .gitmodules submodule.submodule1.path submodule1 && |
| 536 | git config -f .gitmodules submodule.submodule1.url ../submodule && |
| 537 | git config -f .gitmodules submodule.submodule1.update !false && |
| 538 | test_must_fail git submodule init submodule1 && |
| 539 | test_expect_code 1 git config submodule.submodule1.update >actual && |
| 540 | test_must_be_empty actual |
| 541 | ) |
| 542 | ' |
| 543 | |
| 544 | test_expect_success 'submodule init picks up rebase' ' |
| 545 | (cd super && |
| 546 | git config -f .gitmodules submodule.rebasing.update rebase && |
| 547 | git submodule init rebasing && |
| 548 | test "rebase" = "$(git config submodule.rebasing.update)" |
| 549 | ) |
| 550 | ' |
| 551 | |
| 552 | test_expect_success 'submodule init picks up merge' ' |
| 553 | (cd super && |
| 554 | git config -f .gitmodules submodule.merging.update merge && |
| 555 | git submodule init merging && |
| 556 | test "merge" = "$(git config submodule.merging.update)" |
| 557 | ) |
| 558 | ' |
| 559 | |
| 560 | test_expect_success 'submodule update --merge - ignores --merge for new submodules' ' |
| 561 | test_config -C super submodule.submodule.update checkout && |
| 562 | (cd super && |
| 563 | rm -rf submodule && |
| 564 | git submodule update submodule && |
| 565 | git status -s submodule >expect && |
| 566 | rm -rf submodule && |
| 567 | git submodule update --merge submodule && |
| 568 | git status -s submodule >actual && |
| 569 | test_cmp expect actual |
| 570 | ) |
| 571 | ' |
| 572 | |
| 573 | test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' ' |
| 574 | test_config -C super submodule.submodule.update checkout && |
| 575 | (cd super && |
| 576 | rm -rf submodule && |
| 577 | git submodule update submodule && |
| 578 | git status -s submodule >expect && |
| 579 | rm -rf submodule && |
| 580 | git submodule update --rebase submodule && |
| 581 | git status -s submodule >actual && |
| 582 | test_cmp expect actual |
| 583 | ) |
| 584 | ' |
| 585 | |
| 586 | test_expect_success 'submodule update ignores update=merge config for new submodules' ' |
| 587 | (cd super && |
| 588 | rm -rf submodule && |
| 589 | git submodule update submodule && |
| 590 | git status -s submodule >expect && |
| 591 | rm -rf submodule && |
| 592 | git config submodule.submodule.update merge && |
| 593 | git submodule update submodule && |
| 594 | git status -s submodule >actual && |
| 595 | git config --unset submodule.submodule.update && |
| 596 | test_cmp expect actual |
| 597 | ) |
| 598 | ' |
| 599 | |
| 600 | test_expect_success 'submodule update ignores update=rebase config for new submodules' ' |
| 601 | (cd super && |
| 602 | rm -rf submodule && |
| 603 | git submodule update submodule && |
| 604 | git status -s submodule >expect && |
| 605 | rm -rf submodule && |
| 606 | git config submodule.submodule.update rebase && |
| 607 | git submodule update submodule && |
| 608 | git status -s submodule >actual && |
| 609 | git config --unset submodule.submodule.update && |
| 610 | test_cmp expect actual |
| 611 | ) |
| 612 | ' |
| 613 | |
| 614 | test_expect_success 'submodule init picks up update=none' ' |
| 615 | (cd super && |
| 616 | git config -f .gitmodules submodule.none.update none && |
| 617 | git submodule init none && |
| 618 | test "none" = "$(git config submodule.none.update)" |
| 619 | ) |
| 620 | ' |
| 621 | |
| 622 | test_expect_success 'submodule update - update=none in .git/config' ' |
| 623 | (cd super && |
| 624 | git config submodule.submodule.update none && |
| 625 | (cd submodule && |
| 626 | git checkout main && |
| 627 | compare_head |
| 628 | ) && |
| 629 | git diff --name-only >out && |
| 630 | grep ^submodule$ out && |
| 631 | git submodule update && |
| 632 | git diff --name-only >out && |
| 633 | grep ^submodule$ out && |
| 634 | (cd submodule && |
| 635 | compare_head |
| 636 | ) && |
| 637 | git config --unset submodule.submodule.update && |
| 638 | git submodule update submodule |
| 639 | ) |
| 640 | ' |
| 641 | |
| 642 | test_expect_success 'submodule update - update=none in .git/config but --checkout given' ' |
| 643 | (cd super && |
| 644 | git config submodule.submodule.update none && |
| 645 | (cd submodule && |
| 646 | git checkout main && |
| 647 | compare_head |
| 648 | ) && |
| 649 | git diff --name-only >out && |
| 650 | grep ^submodule$ out && |
| 651 | git submodule update --checkout && |
| 652 | git diff --name-only >out && |
| 653 | ! grep ^submodule$ out && |
| 654 | (cd submodule && |
| 655 | ! compare_head |
| 656 | ) && |
| 657 | git config --unset submodule.submodule.update |
| 658 | ) |
| 659 | ' |
| 660 | |
| 661 | test_expect_success 'submodule update --init skips submodule with update=none' ' |
| 662 | (cd super && |
| 663 | git add .gitmodules && |
| 664 | git commit -m ".gitmodules" |
| 665 | ) && |
| 666 | git clone super cloned && |
| 667 | (cd cloned && |
| 668 | git submodule update --init && |
| 669 | test_path_exists submodule/.git && |
| 670 | test_path_is_missing none/.git |
| 671 | ) |
| 672 | ' |
| 673 | |
| 674 | test_expect_success 'submodule update with pathspec warns against uninitialized ones' ' |
| 675 | test_when_finished "rm -fr selective" && |
| 676 | git clone super selective && |
| 677 | ( |
| 678 | cd selective && |
| 679 | git submodule init submodule && |
| 680 | |
| 681 | git submodule update submodule 2>err && |
| 682 | ! grep "Submodule path .* not initialized" err && |
| 683 | |
| 684 | git submodule update rebasing 2>err && |
| 685 | grep "Submodule path .rebasing. not initialized" err && |
| 686 | |
| 687 | test_path_exists submodule/.git && |
| 688 | test_path_is_missing rebasing/.git |
| 689 | ) |
| 690 | |
| 691 | ' |
| 692 | |
| 693 | test_expect_success 'submodule update without pathspec updates only initialized ones' ' |
| 694 | test_when_finished "rm -fr selective" && |
| 695 | git clone super selective && |
| 696 | ( |
| 697 | cd selective && |
| 698 | git submodule init submodule && |
| 699 | git submodule update 2>err && |
| 700 | test_path_exists submodule/.git && |
| 701 | test_path_is_missing rebasing/.git && |
| 702 | ! grep "Submodule path .* not initialized" err |
| 703 | ) |
| 704 | |
| 705 | ' |
| 706 | |
| 707 | test_expect_success 'submodule update continues after checkout error' ' |
| 708 | (cd super && |
| 709 | git reset --hard HEAD && |
| 710 | git submodule add ../submodule submodule2 && |
| 711 | git submodule init && |
| 712 | git commit -am "new_submodule" && |
| 713 | (cd submodule2 && |
| 714 | git rev-parse --verify HEAD >../expect |
| 715 | ) && |
| 716 | (cd submodule && |
| 717 | test_commit "update_submodule" file |
| 718 | ) && |
| 719 | (cd submodule2 && |
| 720 | test_commit "update_submodule2" file |
| 721 | ) && |
| 722 | git add submodule && |
| 723 | git add submodule2 && |
| 724 | git commit -m "two_new_submodule_commits" && |
| 725 | (cd submodule && |
| 726 | echo "" > file |
| 727 | ) && |
| 728 | git checkout HEAD^ && |
| 729 | test_must_fail git submodule update && |
| 730 | (cd submodule2 && |
| 731 | git rev-parse --verify HEAD >../actual |
| 732 | ) && |
| 733 | test_cmp expect actual |
| 734 | ) |
| 735 | ' |
| 736 | test_expect_success 'submodule update continues after recursive checkout error' ' |
| 737 | (cd super && |
| 738 | git reset --hard HEAD && |
| 739 | git checkout main && |
| 740 | git submodule update && |
| 741 | (cd submodule && |
| 742 | git submodule add ../submodule subsubmodule && |
| 743 | git submodule init && |
| 744 | git commit -m "new_subsubmodule" |
| 745 | ) && |
| 746 | git add submodule && |
| 747 | git commit -m "update_submodule" && |
| 748 | (cd submodule && |
| 749 | (cd subsubmodule && |
| 750 | test_commit "update_subsubmodule" file |
| 751 | ) && |
| 752 | git add subsubmodule && |
| 753 | test_commit "update_submodule_again" file && |
| 754 | (cd subsubmodule && |
| 755 | test_commit "update_subsubmodule_again" file |
| 756 | ) && |
| 757 | test_commit "update_submodule_again_again" file |
| 758 | ) && |
| 759 | (cd submodule2 && |
| 760 | git rev-parse --verify HEAD >../expect && |
| 761 | test_commit "update_submodule2_again" file |
| 762 | ) && |
| 763 | git add submodule && |
| 764 | git add submodule2 && |
| 765 | git commit -m "new_commits" && |
| 766 | git checkout HEAD^ && |
| 767 | (cd submodule && |
| 768 | git checkout HEAD^ && |
| 769 | (cd subsubmodule && |
| 770 | echo "" > file |
| 771 | ) |
| 772 | ) && |
| 773 | test_expect_code 1 git submodule update --recursive && |
| 774 | (cd submodule2 && |
| 775 | git rev-parse --verify HEAD >../actual |
| 776 | ) && |
| 777 | test_cmp expect actual |
| 778 | ) |
| 779 | ' |
| 780 | |
| 781 | test_expect_success 'submodule update exit immediately in case of merge conflict' ' |
| 782 | (cd super && |
| 783 | git checkout main && |
| 784 | git reset --hard HEAD && |
| 785 | (cd submodule && |
| 786 | (cd subsubmodule && |
| 787 | git reset --hard HEAD |
| 788 | ) |
| 789 | ) && |
| 790 | git submodule update --recursive && |
| 791 | (cd submodule && |
| 792 | test_commit "update_submodule_2" file |
| 793 | ) && |
| 794 | (cd submodule2 && |
| 795 | test_commit "update_submodule2_2" file |
| 796 | ) && |
| 797 | git add submodule && |
| 798 | git add submodule2 && |
| 799 | git commit -m "two_new_submodule_commits" && |
| 800 | (cd submodule && |
| 801 | git checkout main && |
| 802 | test_commit "conflict" file && |
| 803 | echo "conflict" > file |
| 804 | ) && |
| 805 | git checkout HEAD^ && |
| 806 | (cd submodule2 && |
| 807 | git rev-parse --verify HEAD >../expect |
| 808 | ) && |
| 809 | git config submodule.submodule.update merge && |
| 810 | test_must_fail git submodule update && |
| 811 | (cd submodule2 && |
| 812 | git rev-parse --verify HEAD >../actual |
| 813 | ) && |
| 814 | test_cmp expect actual |
| 815 | ) |
| 816 | ' |
| 817 | |
| 818 | test_expect_success 'submodule update exit immediately after recursive rebase error' ' |
| 819 | (cd super && |
| 820 | git checkout main && |
| 821 | git reset --hard HEAD && |
| 822 | (cd submodule && |
| 823 | git reset --hard HEAD && |
| 824 | git submodule update --recursive |
| 825 | ) && |
| 826 | (cd submodule && |
| 827 | test_commit "update_submodule_3" file |
| 828 | ) && |
| 829 | (cd submodule2 && |
| 830 | test_commit "update_submodule2_3" file |
| 831 | ) && |
| 832 | git add submodule && |
| 833 | git add submodule2 && |
| 834 | git commit -m "two_new_submodule_commits" && |
| 835 | (cd submodule && |
| 836 | git checkout main && |
| 837 | test_commit "conflict2" file && |
| 838 | echo "conflict" > file |
| 839 | ) && |
| 840 | git checkout HEAD^ && |
| 841 | (cd submodule2 && |
| 842 | git rev-parse --verify HEAD >../expect |
| 843 | ) && |
| 844 | git config submodule.submodule.update rebase && |
| 845 | test_must_fail git submodule update && |
| 846 | (cd submodule2 && |
| 847 | git rev-parse --verify HEAD >../actual |
| 848 | ) && |
| 849 | test_cmp expect actual |
| 850 | ) |
| 851 | ' |
| 852 | |
| 853 | test_expect_success 'add different submodules to the same path' ' |
| 854 | (cd super && |
| 855 | git submodule add ../submodule s1 && |
| 856 | test_must_fail git submodule add ../merging s1 |
| 857 | ) |
| 858 | ' |
| 859 | |
| 860 | test_expect_success 'submodule add places git-dir in superprojects git-dir' ' |
| 861 | (cd super && |
| 862 | mkdir deeper && |
| 863 | git submodule add ../submodule deeper/submodule && |
| 864 | (cd deeper/submodule && |
| 865 | git log > ../../expected |
| 866 | ) && |
| 867 | (cd .git/modules/deeper/submodule && |
| 868 | git log > ../../../../actual |
| 869 | ) && |
| 870 | test_cmp expected actual |
| 871 | ) |
| 872 | ' |
| 873 | |
| 874 | test_expect_success 'submodule update places git-dir in superprojects git-dir' ' |
| 875 | (cd super && |
| 876 | git commit -m "added submodule" |
| 877 | ) && |
| 878 | git clone super super2 && |
| 879 | (cd super2 && |
| 880 | git submodule init deeper/submodule && |
| 881 | git submodule update && |
| 882 | (cd deeper/submodule && |
| 883 | git log > ../../expected |
| 884 | ) && |
| 885 | (cd .git/modules/deeper/submodule && |
| 886 | git log > ../../../../actual |
| 887 | ) && |
| 888 | test_cmp expected actual |
| 889 | ) |
| 890 | ' |
| 891 | |
| 892 | test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' ' |
| 893 | (cd super2 && |
| 894 | (cd deeper/submodule && |
| 895 | git submodule add ../submodule subsubmodule && |
| 896 | (cd subsubmodule && |
| 897 | git log > ../../../expected |
| 898 | ) && |
| 899 | git commit -m "added subsubmodule" && |
| 900 | git push origin : |
| 901 | ) && |
| 902 | (cd .git/modules/deeper/submodule/modules/subsubmodule && |
| 903 | git log > ../../../../../actual |
| 904 | ) && |
| 905 | git add deeper/submodule && |
| 906 | git commit -m "update submodule" && |
| 907 | git push origin : && |
| 908 | test_cmp expected actual |
| 909 | ) |
| 910 | ' |
| 911 | |
| 912 | test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' ' |
| 913 | mkdir super_update_r && |
| 914 | (cd super_update_r && |
| 915 | git init --bare |
| 916 | ) && |
| 917 | mkdir subsuper_update_r && |
| 918 | (cd subsuper_update_r && |
| 919 | git init --bare |
| 920 | ) && |
| 921 | mkdir subsubsuper_update_r && |
| 922 | (cd subsubsuper_update_r && |
| 923 | git init --bare |
| 924 | ) && |
| 925 | git clone subsubsuper_update_r subsubsuper_update_r2 && |
| 926 | (cd subsubsuper_update_r2 && |
| 927 | test_commit "update_subsubsuper" file && |
| 928 | git push origin main |
| 929 | ) && |
| 930 | git clone subsuper_update_r subsuper_update_r2 && |
| 931 | (cd subsuper_update_r2 && |
| 932 | test_commit "update_subsuper" file && |
| 933 | git submodule add ../subsubsuper_update_r subsubmodule && |
| 934 | git commit -am "subsubmodule" && |
| 935 | git push origin main |
| 936 | ) && |
| 937 | git clone super_update_r super_update_r2 && |
| 938 | (cd super_update_r2 && |
| 939 | test_commit "update_super" file && |
| 940 | git submodule add ../subsuper_update_r submodule && |
| 941 | git commit -am "submodule" && |
| 942 | git push origin main |
| 943 | ) && |
| 944 | rm -rf super_update_r2 && |
| 945 | git clone super_update_r super_update_r2 && |
| 946 | (cd super_update_r2 && |
| 947 | git submodule update --init --recursive >actual && |
| 948 | test_grep "Submodule path .submodule/subsubmodule.: checked out" actual && |
| 949 | (cd submodule/subsubmodule && |
| 950 | git log > ../../expected |
| 951 | ) && |
| 952 | (cd .git/modules/submodule/modules/subsubmodule && |
| 953 | git log > ../../../../../actual |
| 954 | ) && |
| 955 | test_cmp expected actual |
| 956 | ) |
| 957 | ' |
| 958 | |
| 959 | test_expect_success 'submodule add properly re-creates deeper level submodules' ' |
| 960 | (cd super && |
| 961 | git reset --hard main && |
| 962 | rm -rf deeper/ && |
| 963 | git submodule add --force ../submodule deeper/submodule |
| 964 | ) |
| 965 | ' |
| 966 | |
| 967 | test_expect_success 'submodule update properly revives a moved submodule' ' |
| 968 | (cd super && |
| 969 | H=$(git rev-parse --short HEAD) && |
| 970 | git commit -am "pre move" && |
| 971 | H2=$(git rev-parse --short HEAD) && |
| 972 | git status >out && |
| 973 | sed "s/$H/XXX/" out >expect && |
| 974 | H=$(cd submodule2 && git rev-parse HEAD) && |
| 975 | git rm --cached submodule2 && |
| 976 | rm -rf submodule2 && |
| 977 | mkdir -p "moved/sub module" && |
| 978 | git update-index --add --cacheinfo 160000 $H "moved/sub module" && |
| 979 | git config -f .gitmodules submodule.submodule2.path "moved/sub module" && |
| 980 | git commit -am "post move" && |
| 981 | git submodule update && |
| 982 | git status > out && |
| 983 | sed "s/$H2/XXX/" out >actual && |
| 984 | test_cmp expect actual |
| 985 | ) |
| 986 | ' |
| 987 | |
| 988 | test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' ' |
| 989 | mkdir -p linked/dir && |
| 990 | ln -s linked/dir linkto && |
| 991 | (cd linkto && |
| 992 | git clone "$TRASH_DIRECTORY"/super_update_r2 super && |
| 993 | (cd super && |
| 994 | git submodule update --init --recursive |
| 995 | ) |
| 996 | ) |
| 997 | ' |
| 998 | |
| 999 | test_expect_success 'submodule update clone shallow submodule' ' |
| 1000 | test_when_finished "rm -rf super3" && |
| 1001 | first=$(git -C cloned rev-parse HEAD:submodule) && |
| 1002 | second=$(git -C submodule rev-parse HEAD) && |
| 1003 | commit_count=$(git -C submodule rev-list --count $first^..$second) && |
| 1004 | git clone cloned super3 && |
| 1005 | pwd=$(pwd) && |
| 1006 | ( |
| 1007 | cd super3 && |
| 1008 | sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && |
| 1009 | mv -f .gitmodules.tmp .gitmodules && |
| 1010 | git submodule update --init --depth=$commit_count && |
| 1011 | git -C submodule log --oneline >out && |
| 1012 | test_line_count = 1 out |
| 1013 | ) |
| 1014 | ' |
| 1015 | |
| 1016 | test_expect_success 'submodule update clone shallow submodule outside of depth' ' |
| 1017 | test_when_finished "rm -rf super3" && |
| 1018 | git clone cloned super3 && |
| 1019 | pwd=$(pwd) && |
| 1020 | ( |
| 1021 | cd super3 && |
| 1022 | sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && |
| 1023 | mv -f .gitmodules.tmp .gitmodules && |
| 1024 | # Some protocol versions (e.g. 2) support fetching |
| 1025 | # unadvertised objects, so restrict this test to v0. |
| 1026 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
| 1027 | git submodule update --init --depth=1 2>actual && |
| 1028 | test_grep "Direct fetching of that commit failed." actual && |
| 1029 | git -C ../submodule config uploadpack.allowReachableSHA1InWant true && |
| 1030 | git submodule update --init --depth=1 >actual && |
| 1031 | git -C submodule log --oneline >out && |
| 1032 | test_line_count = 1 out |
| 1033 | ) |
| 1034 | ' |
| 1035 | |
| 1036 | test_expect_success 'submodule update --recursive drops module name before recursing' ' |
| 1037 | (cd super2 && |
| 1038 | (cd deeper/submodule/subsubmodule && |
| 1039 | git checkout HEAD^ |
| 1040 | ) && |
| 1041 | git submodule update --recursive deeper/submodule >actual && |
| 1042 | test_grep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual |
| 1043 | ) |
| 1044 | ' |
| 1045 | |
| 1046 | test_expect_success 'submodule update can be run in parallel' ' |
| 1047 | (cd super2 && |
| 1048 | GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 && |
| 1049 | grep "7 tasks" trace.out && |
| 1050 | git config submodule.fetchJobs 8 && |
| 1051 | GIT_TRACE=$(pwd)/trace.out git submodule update && |
| 1052 | grep "8 tasks" trace.out && |
| 1053 | GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 && |
| 1054 | grep "9 tasks" trace.out |
| 1055 | ) |
| 1056 | ' |
| 1057 | |
| 1058 | test_expect_success 'submodule update honors fetch jobs config from .gitmodules' ' |
| 1059 | test_when_finished "rm -rf super3" && |
| 1060 | git clone cloned super3 && |
| 1061 | git -C super3 config -f .gitmodules submodule.fetchJobs 67 && |
| 1062 | GIT_TRACE="$(pwd)/trace.out" git -C super3 submodule update --init && |
| 1063 | test_grep "67 tasks" trace.out |
| 1064 | ' |
| 1065 | |
| 1066 | test_expect_success 'git clone passes the parallel jobs config on to submodules' ' |
| 1067 | test_when_finished "rm -rf super4" && |
| 1068 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 && |
| 1069 | grep "7 tasks" trace.out && |
| 1070 | rm -rf super4 && |
| 1071 | git config --global submodule.fetchJobs 8 && |
| 1072 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 && |
| 1073 | grep "8 tasks" trace.out && |
| 1074 | rm -rf super4 && |
| 1075 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 && |
| 1076 | grep "9 tasks" trace.out && |
| 1077 | rm -rf super4 |
| 1078 | ' |
| 1079 | |
| 1080 | test_expect_success 'submodule update --quiet passes quietness to merge/rebase' ' |
| 1081 | (cd super && |
| 1082 | test_commit -C rebasing message && |
| 1083 | git submodule update --rebase --quiet >out 2>err && |
| 1084 | test_must_be_empty out && |
| 1085 | test_must_be_empty err && |
| 1086 | git submodule update --rebase >out 2>err && |
| 1087 | test_file_not_empty out && |
| 1088 | test_must_be_empty err |
| 1089 | ) |
| 1090 | ' |
| 1091 | |
| 1092 | test_expect_success 'submodule update --quiet passes quietness to fetch with a shallow clone' ' |
| 1093 | test_when_finished "rm -rf super4 super5 super6" && |
| 1094 | git clone . super4 && |
| 1095 | (cd super4 && |
| 1096 | git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 && |
| 1097 | git commit -am "setup submodule3" |
| 1098 | ) && |
| 1099 | (cd submodule && |
| 1100 | test_commit line6 file |
| 1101 | ) && |
| 1102 | git clone super4 super5 && |
| 1103 | (cd super5 && |
| 1104 | # This test var can mess with the stderr output checked in this test. |
| 1105 | GIT_TEST_NAME_HASH_VERSION=1 \ |
| 1106 | GIT_TEST_PACK_PATH_WALK=0 \ |
| 1107 | git submodule update --quiet --init --depth=1 submodule3 >out 2>err && |
| 1108 | test_must_be_empty out && |
| 1109 | test_must_be_empty err |
| 1110 | ) && |
| 1111 | git clone super4 super6 && |
| 1112 | (cd super6 && |
| 1113 | # This test variable will create a "warning" message to stderr |
| 1114 | GIT_TEST_PACK_PATH_WALK=0 \ |
| 1115 | git submodule update --init --depth=1 submodule3 >out 2>err && |
| 1116 | test_file_not_empty out && |
| 1117 | test_file_not_empty err |
| 1118 | ) |
| 1119 | ' |
| 1120 | |
| 1121 | test_expect_success 'submodule update --filter requires --init' ' |
| 1122 | test_expect_code 129 git -C super submodule update --filter blob:none |
| 1123 | ' |
| 1124 | |
| 1125 | test_expect_success 'submodule update --filter sets partial clone settings' ' |
| 1126 | test_when_finished "rm -rf super-filter" && |
| 1127 | git clone cloned super-filter && |
| 1128 | git -C super-filter submodule update --init --filter blob:none && |
| 1129 | test_cmp_config -C super-filter/submodule true remote.origin.promisor && |
| 1130 | test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter |
| 1131 | ' |
| 1132 | |
| 1133 | # NEEDSWORK: Clean up the tests so that we can reuse the test setup. |
| 1134 | # Don't reuse the existing repos because the earlier tests have |
| 1135 | # intentionally disruptive configurations. |
| 1136 | test_expect_success 'setup clean recursive superproject' ' |
| 1137 | git init bottom && |
| 1138 | test_commit -C bottom "bottom" && |
| 1139 | git init middle && |
| 1140 | git -C middle submodule add ../bottom bottom && |
| 1141 | git -C middle commit -m "middle" && |
| 1142 | git init top && |
| 1143 | git -C top submodule add ../middle middle && |
| 1144 | git -C top commit -m "top" && |
| 1145 | git clone --recurse-submodules top top-clean |
| 1146 | ' |
| 1147 | |
| 1148 | test_expect_success 'submodule update with multiple remotes' ' |
| 1149 | test_when_finished "rm -fr top-cloned" && |
| 1150 | cp -r top-clean top-cloned && |
| 1151 | |
| 1152 | # Create a commit in each repo, starting with bottom |
| 1153 | test_commit -C bottom multiple_remote_commit && |
| 1154 | # Create middle commit |
| 1155 | git -C middle/bottom fetch && |
| 1156 | git -C middle/bottom checkout -f FETCH_HEAD && |
| 1157 | git -C middle add bottom && |
| 1158 | git -C middle commit -m "multiple_remote_commit" && |
| 1159 | # Create top commit |
| 1160 | git -C top/middle fetch && |
| 1161 | git -C top/middle checkout -f FETCH_HEAD && |
| 1162 | git -C top add middle && |
| 1163 | git -C top commit -m "multiple_remote_commit" && |
| 1164 | |
| 1165 | # rename the submodule remote |
| 1166 | git -C top-cloned/middle remote rename origin upstream && |
| 1167 | |
| 1168 | # Add another remote |
| 1169 | git -C top-cloned/middle remote add other bogus && |
| 1170 | |
| 1171 | # Make the update of "middle" a no-op, otherwise we error out |
| 1172 | # because of its unmerged state |
| 1173 | test_config -C top-cloned submodule.middle.update !true && |
| 1174 | git -C top-cloned submodule update --recursive 2>actual.err && |
| 1175 | cat >expect.err <<-\EOF && |
| 1176 | EOF |
| 1177 | test_cmp expect.err actual.err |
| 1178 | ' |
| 1179 | |
| 1180 | test_expect_success 'submodule update with renamed remote' ' |
| 1181 | test_when_finished "rm -fr top-cloned" && |
| 1182 | cp -r top-clean top-cloned && |
| 1183 | |
| 1184 | # Create a commit in each repo, starting with bottom |
| 1185 | test_commit -C bottom rename_commit && |
| 1186 | # Create middle commit |
| 1187 | git -C middle/bottom fetch && |
| 1188 | git -C middle/bottom checkout -f FETCH_HEAD && |
| 1189 | git -C middle add bottom && |
| 1190 | git -C middle commit -m "rename_commit" && |
| 1191 | # Create top commit |
| 1192 | git -C top/middle fetch && |
| 1193 | git -C top/middle checkout -f FETCH_HEAD && |
| 1194 | git -C top add middle && |
| 1195 | git -C top commit -m "rename_commit" && |
| 1196 | |
| 1197 | # rename the submodule remote |
| 1198 | git -C top-cloned/middle remote rename origin upstream && |
| 1199 | |
| 1200 | # Make the update of "middle" a no-op, otherwise we error out |
| 1201 | # because of its unmerged state |
| 1202 | test_config -C top-cloned submodule.middle.update !true && |
| 1203 | git -C top-cloned submodule update --recursive 2>actual.err && |
| 1204 | cat >expect.err <<-\EOF && |
| 1205 | EOF |
| 1206 | test_cmp expect.err actual.err |
| 1207 | ' |
| 1208 | |
| 1209 | test_expect_success 'submodule update should skip unmerged submodules' ' |
| 1210 | test_when_finished "rm -fr top-cloned" && |
| 1211 | cp -r top-clean top-cloned && |
| 1212 | |
| 1213 | # Create an upstream commit in each repo, starting with bottom |
| 1214 | test_commit -C bottom upstream_commit && |
| 1215 | # Create middle commit |
| 1216 | git -C middle/bottom fetch && |
| 1217 | git -C middle/bottom checkout -f FETCH_HEAD && |
| 1218 | git -C middle add bottom && |
| 1219 | git -C middle commit -m "upstream_commit" && |
| 1220 | # Create top commit |
| 1221 | git -C top/middle fetch && |
| 1222 | git -C top/middle checkout -f FETCH_HEAD && |
| 1223 | git -C top add middle && |
| 1224 | git -C top commit -m "upstream_commit" && |
| 1225 | |
| 1226 | # Create a downstream conflict |
| 1227 | test_commit -C top-cloned/middle/bottom downstream_commit && |
| 1228 | git -C top-cloned/middle add bottom && |
| 1229 | git -C top-cloned/middle commit -m "downstream_commit" && |
| 1230 | git -C top-cloned/middle fetch --recurse-submodules origin && |
| 1231 | test_must_fail git -C top-cloned/middle merge origin/main && |
| 1232 | |
| 1233 | # Make the update of "middle" a no-op, otherwise we error out |
| 1234 | # because of its unmerged state |
| 1235 | test_config -C top-cloned submodule.middle.update !true && |
| 1236 | git -C top-cloned submodule update --recursive 2>actual.err && |
| 1237 | cat >expect.err <<-\EOF && |
| 1238 | Skipping unmerged submodule middle/bottom |
| 1239 | EOF |
| 1240 | test_cmp expect.err actual.err |
| 1241 | ' |
| 1242 | |
| 1243 | test_expect_success 'submodule update --recursive skip submodules with strategy=none' ' |
| 1244 | test_when_finished "rm -fr top-cloned" && |
| 1245 | cp -r top-clean top-cloned && |
| 1246 | |
| 1247 | test_commit -C top-cloned/middle/bottom downstream_commit && |
| 1248 | git -C top-cloned/middle config submodule.bottom.update none && |
| 1249 | git -C top-cloned submodule update --recursive 2>actual.err && |
| 1250 | cat >expect.err <<-\EOF && |
| 1251 | Skipping submodule '\''middle/bottom'\'' |
| 1252 | EOF |
| 1253 | test_cmp expect.err actual.err |
| 1254 | ' |
| 1255 | |
| 1256 | add_submodule_commit_and_validate () { |
| 1257 | HASH=$(git rev-parse HEAD) && |
| 1258 | git update-index --add --cacheinfo 160000,$HASH,sub && |
| 1259 | git commit -m "create submodule" && |
| 1260 | echo "160000 commit $HASH sub" >expect && |
| 1261 | git ls-tree HEAD -- sub >actual && |
| 1262 | test_cmp expect actual |
| 1263 | } |
| 1264 | |
| 1265 | test_expect_success 'commit with staged submodule change' ' |
| 1266 | add_submodule_commit_and_validate |
| 1267 | ' |
| 1268 | |
| 1269 | test_expect_success 'commit with staged submodule change with ignoreSubmodules dirty' ' |
| 1270 | test_config diff.ignoreSubmodules dirty && |
| 1271 | add_submodule_commit_and_validate |
| 1272 | ' |
| 1273 | |
| 1274 | test_expect_success 'commit with staged submodule change with ignoreSubmodules all' ' |
| 1275 | test_config diff.ignoreSubmodules all && |
| 1276 | add_submodule_commit_and_validate |
| 1277 | ' |
| 1278 | |
| 1279 | test_expect_success CASE_INSENSITIVE_FS,SYMLINKS \ |
| 1280 | 'submodule paths must not follow symlinks' ' |
| 1281 | |
| 1282 | # This is only needed because we want to run this in a self-contained |
| 1283 | # test without having to spin up an HTTP server; However, it would not |
| 1284 | # be needed in a real-world scenario where the submodule is simply |
| 1285 | # hosted on a public site. |
| 1286 | test_config_global protocol.file.allow always && |
| 1287 | |
| 1288 | # Make sure that Git tries to use symlinks on Windows |
| 1289 | test_config_global core.symlinks true && |
| 1290 | |
| 1291 | tell_tale_path="$PWD/tell.tale" && |
| 1292 | git init hook && |
| 1293 | ( |
| 1294 | cd hook && |
| 1295 | mkdir -p y/hooks && |
| 1296 | write_script y/hooks/post-checkout <<-EOF && |
| 1297 | echo HOOK-RUN >&2 |
| 1298 | echo hook-run >"$tell_tale_path" |
| 1299 | EOF |
| 1300 | git add y/hooks/post-checkout && |
| 1301 | test_tick && |
| 1302 | git commit -m post-checkout |
| 1303 | ) && |
| 1304 | |
| 1305 | hook_repo_path="$(pwd)/hook" && |
| 1306 | git init captain && |
| 1307 | ( |
| 1308 | cd captain && |
| 1309 | git submodule add --name x/y "$hook_repo_path" A/modules/x && |
| 1310 | test_tick && |
| 1311 | git commit -m add-submodule && |
| 1312 | |
| 1313 | printf .git >dotgit.txt && |
| 1314 | git hash-object -w --stdin <dotgit.txt >dot-git.hash && |
| 1315 | printf "120000 %s 0\ta\n" "$(cat dot-git.hash)" >index.info && |
| 1316 | git update-index --index-info <index.info && |
| 1317 | test_tick && |
| 1318 | git commit -m add-symlink |
| 1319 | ) && |
| 1320 | |
| 1321 | test_path_is_missing "$tell_tale_path" && |
| 1322 | git clone --recursive captain hooked 2>err && |
| 1323 | test_grep ! HOOK-RUN err && |
| 1324 | test_path_is_missing "$tell_tale_path" |
| 1325 | ' |
| 1326 | |
| 1327 | test_done |