Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 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 |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 9 | submodule and "git submodule update --rebase/--merge" does not detach the HEAD. |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 10 | ' |
| 11 | |
| 12 | . ./test-lib.sh |
| 13 | |
| 14 | |
| 15 | compare_head() |
| 16 | { |
Elia Pinto | 848351b | 2016-01-08 12:06:20 +0100 | [diff] [blame] | 17 | sha_master=$(git rev-list --max-count=1 master) |
| 18 | sha_head=$(git rev-list --max-count=1 HEAD) |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 19 | |
| 20 | test "$sha_master" = "$sha_head" |
| 21 | } |
| 22 | |
| 23 | |
| 24 | test_expect_success 'setup a submodule tree' ' |
| 25 | echo file > file && |
| 26 | git add file && |
| 27 | test_tick && |
Jens Lehmann | 4bf9dd9 | 2010-09-01 23:28:27 +0200 | [diff] [blame] | 28 | git commit -m upstream && |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 29 | git clone . super && |
| 30 | git clone super submodule && |
Stephen Boyd | c9c8c56 | 2010-03-05 00:20:38 -0800 | [diff] [blame] | 31 | git clone super rebasing && |
| 32 | git clone super merging && |
Heiko Voigt | 322bb6e | 2011-08-11 19:51:46 +0200 | [diff] [blame] | 33 | git clone super none && |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 34 | (cd super && |
| 35 | git submodule add ../submodule submodule && |
| 36 | test_tick && |
| 37 | git commit -m "submodule" && |
| 38 | git submodule init submodule |
| 39 | ) && |
| 40 | (cd submodule && |
| 41 | echo "line2" > file && |
| 42 | git add file && |
| 43 | git commit -m "Commit 2" |
| 44 | ) && |
| 45 | (cd super && |
| 46 | (cd submodule && |
| 47 | git pull --rebase origin |
| 48 | ) && |
| 49 | git add submodule && |
| 50 | git commit -m "submodule update" |
Stephen Boyd | c9c8c56 | 2010-03-05 00:20:38 -0800 | [diff] [blame] | 51 | ) && |
| 52 | (cd super && |
| 53 | git submodule add ../rebasing rebasing && |
| 54 | test_tick && |
| 55 | git commit -m "rebasing" |
| 56 | ) && |
| 57 | (cd super && |
| 58 | git submodule add ../merging merging && |
| 59 | test_tick && |
| 60 | git commit -m "rebasing" |
Tay Ray Chuan | d5b99f3 | 2013-09-16 01:38:21 +0800 | [diff] [blame] | 61 | ) && |
Heiko Voigt | 322bb6e | 2011-08-11 19:51:46 +0200 | [diff] [blame] | 62 | (cd super && |
| 63 | git submodule add ../none none && |
| 64 | test_tick && |
| 65 | git commit -m "none" |
Stefan Beller | c1ab00f | 2016-03-29 18:27:42 -0700 | [diff] [blame] | 66 | ) && |
| 67 | git clone . recursivesuper && |
SZEDER Gábor | 8de19d6 | 2018-06-16 22:33:19 +0200 | [diff] [blame] | 68 | ( cd recursivesuper && |
Stefan Beller | c1ab00f | 2016-03-29 18:27:42 -0700 | [diff] [blame] | 69 | git submodule add ../super super |
Heiko Voigt | 322bb6e | 2011-08-11 19:51:46 +0200 | [diff] [blame] | 70 | ) |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 71 | ' |
| 72 | |
| 73 | test_expect_success 'submodule update detaching the HEAD ' ' |
| 74 | (cd super/submodule && |
| 75 | git reset --hard HEAD~1 |
| 76 | ) && |
| 77 | (cd super && |
| 78 | (cd submodule && |
| 79 | compare_head |
| 80 | ) && |
| 81 | git submodule update submodule && |
| 82 | cd submodule && |
| 83 | ! compare_head |
| 84 | ) |
| 85 | ' |
| 86 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 87 | test_expect_success 'submodule update from subdirectory' ' |
| 88 | (cd super/submodule && |
| 89 | git reset --hard HEAD~1 |
| 90 | ) && |
| 91 | mkdir super/sub && |
| 92 | (cd super/sub && |
| 93 | (cd ../submodule && |
| 94 | compare_head |
| 95 | ) && |
| 96 | git submodule update ../submodule && |
| 97 | cd ../submodule && |
| 98 | ! compare_head |
| 99 | ) |
| 100 | ' |
| 101 | |
Stefan Beller | c1ab00f | 2016-03-29 18:27:42 -0700 | [diff] [blame] | 102 | supersha1=$(git -C super rev-parse HEAD) |
| 103 | mergingsha1=$(git -C super/merging rev-parse HEAD) |
| 104 | nonesha1=$(git -C super/none rev-parse HEAD) |
| 105 | rebasingsha1=$(git -C super/rebasing rev-parse HEAD) |
| 106 | submodulesha1=$(git -C super/submodule rev-parse HEAD) |
| 107 | pwd=$(pwd) |
| 108 | |
| 109 | cat <<EOF >expect |
| 110 | Submodule path '../super': checked out '$supersha1' |
Stefan Beller | c1ab00f | 2016-03-29 18:27:42 -0700 | [diff] [blame] | 111 | Submodule path '../super/merging': checked out '$mergingsha1' |
| 112 | Submodule path '../super/none': checked out '$nonesha1' |
| 113 | Submodule path '../super/rebasing': checked out '$rebasingsha1' |
| 114 | Submodule path '../super/submodule': checked out '$submodulesha1' |
| 115 | EOF |
| 116 | |
Stefan Beller | c66410e | 2016-05-02 15:24:04 -0700 | [diff] [blame] | 117 | cat <<EOF >expect2 |
Johannes Schindelin | 0b7d324 | 2018-07-23 06:39:42 -0700 | [diff] [blame] | 118 | Cloning into '$pwd/recursivesuper/super/merging'... |
| 119 | Cloning into '$pwd/recursivesuper/super/none'... |
| 120 | Cloning into '$pwd/recursivesuper/super/rebasing'... |
| 121 | Cloning into '$pwd/recursivesuper/super/submodule'... |
Stefan Beller | c66410e | 2016-05-02 15:24:04 -0700 | [diff] [blame] | 122 | Submodule 'merging' ($pwd/merging) registered for path '../super/merging' |
| 123 | Submodule 'none' ($pwd/none) registered for path '../super/none' |
| 124 | Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing' |
| 125 | Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule' |
Stefan Beller | c66410e | 2016-05-02 15:24:04 -0700 | [diff] [blame] | 126 | done. |
Stefan Beller | c66410e | 2016-05-02 15:24:04 -0700 | [diff] [blame] | 127 | done. |
Stefan Beller | c66410e | 2016-05-02 15:24:04 -0700 | [diff] [blame] | 128 | done. |
Stefan Beller | c66410e | 2016-05-02 15:24:04 -0700 | [diff] [blame] | 129 | done. |
| 130 | EOF |
| 131 | |
Stefan Beller | c1ab00f | 2016-03-29 18:27:42 -0700 | [diff] [blame] | 132 | test_expect_success 'submodule update --init --recursive from subdirectory' ' |
| 133 | git -C recursivesuper/super reset --hard HEAD^ && |
| 134 | (cd recursivesuper && |
| 135 | mkdir tmp && |
| 136 | cd tmp && |
Stefan Beller | c66410e | 2016-05-02 15:24:04 -0700 | [diff] [blame] | 137 | git submodule update --init --recursive ../super >../../actual 2>../../actual2 |
Stefan Beller | c1ab00f | 2016-03-29 18:27:42 -0700 | [diff] [blame] | 138 | ) && |
Vasco Almeida | 1edbaac | 2016-06-17 20:21:07 +0000 | [diff] [blame] | 139 | test_i18ncmp expect actual && |
Johannes Schindelin | 0b7d324 | 2018-07-23 06:39:42 -0700 | [diff] [blame] | 140 | sort actual2 >actual2.sorted && |
| 141 | test_i18ncmp expect2 actual2.sorted |
Stefan Beller | c1ab00f | 2016-03-29 18:27:42 -0700 | [diff] [blame] | 142 | ' |
| 143 | |
Stefan Beller | 6e7c14e | 2017-01-06 16:19:53 -0800 | [diff] [blame] | 144 | cat <<EOF >expect2 |
| 145 | Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub' |
| 146 | EOF |
| 147 | |
| 148 | test_expect_success 'submodule update --init from and of subdirectory' ' |
| 149 | git init withsubs && |
| 150 | (cd withsubs && |
| 151 | mkdir foo && |
| 152 | git submodule add "$(pwd)/../rebasing" foo/sub && |
| 153 | (cd foo && |
| 154 | git submodule deinit -f sub && |
| 155 | git submodule update --init sub 2>../../actual2 |
| 156 | ) |
| 157 | ) && |
| 158 | test_i18ncmp expect2 actual2 |
| 159 | ' |
| 160 | |
Jens Lehmann | e5f522d | 2011-03-06 23:13:36 +0100 | [diff] [blame] | 161 | apos="'"; |
| 162 | test_expect_success 'submodule update does not fetch already present commits' ' |
| 163 | (cd submodule && |
| 164 | echo line3 >> file && |
| 165 | git add file && |
| 166 | test_tick && |
| 167 | git commit -m "upstream line3" |
| 168 | ) && |
| 169 | (cd super/submodule && |
| 170 | head=$(git rev-parse --verify HEAD) && |
| 171 | echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected && |
| 172 | git reset --hard HEAD~1 |
| 173 | ) && |
| 174 | (cd super && |
| 175 | git submodule update > ../actual 2> ../actual.err |
| 176 | ) && |
Ævar Arnfjörð Bjarmason | ee653c8 | 2011-05-21 18:44:02 +0000 | [diff] [blame] | 177 | test_i18ncmp expected actual && |
Elijah Newren | 7e9055b | 2018-08-08 09:31:06 -0700 | [diff] [blame] | 178 | test_must_be_empty actual.err |
Jens Lehmann | e5f522d | 2011-03-06 23:13:36 +0100 | [diff] [blame] | 179 | ' |
| 180 | |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 181 | test_expect_success 'submodule update should fail due to local changes' ' |
| 182 | (cd super/submodule && |
| 183 | git reset --hard HEAD~1 && |
| 184 | echo "local change" > file |
| 185 | ) && |
| 186 | (cd super && |
| 187 | (cd submodule && |
| 188 | compare_head |
| 189 | ) && |
| 190 | test_must_fail git submodule update submodule |
| 191 | ) |
| 192 | ' |
| 193 | test_expect_success 'submodule update should throw away changes with --force ' ' |
| 194 | (cd super && |
| 195 | (cd submodule && |
| 196 | compare_head |
| 197 | ) && |
| 198 | git submodule update --force submodule && |
| 199 | cd submodule && |
| 200 | ! compare_head |
| 201 | ) |
| 202 | ' |
| 203 | |
Stefan Zager | 01d4721 | 2012-07-25 10:41:54 -0700 | [diff] [blame] | 204 | test_expect_success 'submodule update --force forcibly checks out submodules' ' |
| 205 | (cd super && |
| 206 | (cd submodule && |
| 207 | rm -f file |
| 208 | ) && |
| 209 | git submodule update --force submodule && |
| 210 | (cd submodule && |
| 211 | test "$(git status -s file)" = "" |
| 212 | ) |
| 213 | ) |
| 214 | ' |
| 215 | |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 216 | test_expect_success 'submodule update --remote should fetch upstream changes' ' |
| 217 | (cd submodule && |
| 218 | echo line4 >> file && |
| 219 | git add file && |
| 220 | test_tick && |
| 221 | git commit -m "upstream line4" |
| 222 | ) && |
| 223 | (cd super && |
| 224 | git submodule update --remote --force submodule && |
| 225 | cd submodule && |
| 226 | test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)" |
| 227 | ) |
| 228 | ' |
| 229 | |
Stefan Beller | 4d7bc52 | 2016-08-03 13:44:04 -0700 | [diff] [blame] | 230 | test_expect_success 'submodule update --remote should fetch upstream changes with .' ' |
| 231 | ( |
| 232 | cd super && |
| 233 | git config -f .gitmodules submodule."submodule".branch "." && |
| 234 | git add .gitmodules && |
| 235 | git commit -m "submodules: update from the respective superproject branch" |
| 236 | ) && |
| 237 | ( |
| 238 | cd submodule && |
| 239 | echo line4a >> file && |
| 240 | git add file && |
| 241 | test_tick && |
| 242 | git commit -m "upstream line4a" && |
| 243 | git checkout -b test-branch && |
| 244 | test_commit on-test-branch |
| 245 | ) && |
| 246 | ( |
| 247 | cd super && |
| 248 | git submodule update --remote --force submodule && |
SZEDER Gábor | 8de19d6 | 2018-06-16 22:33:19 +0200 | [diff] [blame] | 249 | git -C submodule log -1 --oneline >actual && |
| 250 | git -C ../submodule log -1 --oneline master >expect && |
Stefan Beller | 4d7bc52 | 2016-08-03 13:44:04 -0700 | [diff] [blame] | 251 | test_cmp expect actual && |
| 252 | git checkout -b test-branch && |
| 253 | git submodule update --remote --force submodule && |
SZEDER Gábor | 8de19d6 | 2018-06-16 22:33:19 +0200 | [diff] [blame] | 254 | git -C submodule log -1 --oneline >actual && |
| 255 | git -C ../submodule log -1 --oneline test-branch >expect && |
Stefan Beller | 4d7bc52 | 2016-08-03 13:44:04 -0700 | [diff] [blame] | 256 | test_cmp expect actual && |
| 257 | git checkout master && |
| 258 | git branch -d test-branch && |
| 259 | git reset --hard HEAD^ |
| 260 | ) |
| 261 | ' |
| 262 | |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 263 | test_expect_success 'local config should override .gitmodules branch' ' |
| 264 | (cd submodule && |
Stefan Beller | 4d7bc52 | 2016-08-03 13:44:04 -0700 | [diff] [blame] | 265 | git checkout test-branch && |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 266 | echo line5 >> file && |
| 267 | git add file && |
| 268 | test_tick && |
| 269 | git commit -m "upstream line5" && |
| 270 | git checkout master |
| 271 | ) && |
| 272 | (cd super && |
| 273 | git config submodule.submodule.branch test-branch && |
| 274 | git submodule update --remote --force submodule && |
| 275 | cd submodule && |
| 276 | test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)" |
| 277 | ) |
| 278 | ' |
| 279 | |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 280 | test_expect_success 'submodule update --rebase staying on master' ' |
| 281 | (cd super/submodule && |
| 282 | git checkout master |
| 283 | ) && |
| 284 | (cd super && |
| 285 | (cd submodule && |
| 286 | compare_head |
| 287 | ) && |
| 288 | git submodule update --rebase submodule && |
| 289 | cd submodule && |
| 290 | compare_head |
| 291 | ) |
| 292 | ' |
| 293 | |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 294 | test_expect_success 'submodule update --merge staying on master' ' |
| 295 | (cd super/submodule && |
| 296 | git reset --hard HEAD~1 |
| 297 | ) && |
| 298 | (cd super && |
| 299 | (cd submodule && |
| 300 | compare_head |
| 301 | ) && |
| 302 | git submodule update --merge submodule && |
| 303 | cd submodule && |
| 304 | compare_head |
| 305 | ) |
| 306 | ' |
| 307 | |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 308 | test_expect_success 'submodule update - rebase in .git/config' ' |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 309 | (cd super && |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 310 | git config submodule.submodule.update rebase |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 311 | ) && |
| 312 | (cd super/submodule && |
| 313 | git reset --hard HEAD~1 |
| 314 | ) && |
| 315 | (cd super && |
| 316 | (cd submodule && |
| 317 | compare_head |
| 318 | ) && |
| 319 | git submodule update submodule && |
| 320 | cd submodule && |
| 321 | compare_head |
| 322 | ) |
| 323 | ' |
| 324 | |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 325 | test_expect_success 'submodule update - checkout in .git/config but --rebase given' ' |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 326 | (cd super && |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 327 | git config submodule.submodule.update checkout |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 328 | ) && |
| 329 | (cd super/submodule && |
| 330 | git reset --hard HEAD~1 |
| 331 | ) && |
| 332 | (cd super && |
| 333 | (cd submodule && |
| 334 | compare_head |
| 335 | ) && |
| 336 | git submodule update --rebase submodule && |
| 337 | cd submodule && |
| 338 | compare_head |
| 339 | ) |
| 340 | ' |
| 341 | |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 342 | test_expect_success 'submodule update - merge in .git/config' ' |
| 343 | (cd super && |
| 344 | git config submodule.submodule.update merge |
| 345 | ) && |
| 346 | (cd super/submodule && |
| 347 | git reset --hard HEAD~1 |
| 348 | ) && |
| 349 | (cd super && |
| 350 | (cd submodule && |
| 351 | compare_head |
| 352 | ) && |
| 353 | git submodule update submodule && |
| 354 | cd submodule && |
| 355 | compare_head |
| 356 | ) |
| 357 | ' |
| 358 | |
| 359 | test_expect_success 'submodule update - checkout in .git/config but --merge given' ' |
| 360 | (cd super && |
| 361 | git config submodule.submodule.update checkout |
| 362 | ) && |
| 363 | (cd super/submodule && |
| 364 | git reset --hard HEAD~1 |
| 365 | ) && |
| 366 | (cd super && |
| 367 | (cd submodule && |
| 368 | compare_head |
| 369 | ) && |
| 370 | git submodule update --merge submodule && |
| 371 | cd submodule && |
| 372 | compare_head |
| 373 | ) |
| 374 | ' |
| 375 | |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 376 | test_expect_success 'submodule update - checkout in .git/config' ' |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 377 | (cd super && |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 378 | git config submodule.submodule.update checkout |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 379 | ) && |
| 380 | (cd super/submodule && |
| 381 | git reset --hard HEAD^ |
| 382 | ) && |
| 383 | (cd super && |
| 384 | (cd submodule && |
| 385 | compare_head |
| 386 | ) && |
| 387 | git submodule update submodule && |
| 388 | cd submodule && |
| 389 | ! compare_head |
| 390 | ) |
| 391 | ' |
| 392 | |
Chris Packham | 6cb5728 | 2013-07-03 21:02:02 +1200 | [diff] [blame] | 393 | test_expect_success 'submodule update - command in .git/config' ' |
| 394 | (cd super && |
| 395 | git config submodule.submodule.update "!git checkout" |
| 396 | ) && |
| 397 | (cd super/submodule && |
| 398 | git reset --hard HEAD^ |
| 399 | ) && |
| 400 | (cd super && |
| 401 | (cd submodule && |
| 402 | compare_head |
| 403 | ) && |
| 404 | git submodule update submodule && |
| 405 | cd submodule && |
| 406 | ! compare_head |
| 407 | ) |
| 408 | ' |
| 409 | |
Stefan Beller | 83a17fa | 2017-09-26 12:54:13 -0700 | [diff] [blame] | 410 | test_expect_success 'submodule update - command in .gitmodules is ignored' ' |
| 411 | test_when_finished "git -C super reset --hard HEAD^" && |
| 412 | git -C super config -f .gitmodules submodule.submodule.update "!false" && |
| 413 | git -C super commit -a -m "add command to .gitmodules file" && |
| 414 | git -C super/submodule reset --hard $submodulesha1^ && |
| 415 | git -C super submodule update submodule |
| 416 | ' |
| 417 | |
Stefan Beller | b08238a | 2016-03-29 18:27:44 -0700 | [diff] [blame] | 418 | cat << EOF >expect |
| 419 | Execution of 'false $submodulesha1' failed in submodule path 'submodule' |
| 420 | EOF |
| 421 | |
Chris Packham | 6cb5728 | 2013-07-03 21:02:02 +1200 | [diff] [blame] | 422 | test_expect_success 'submodule update - command in .git/config catches failure' ' |
| 423 | (cd super && |
| 424 | git config submodule.submodule.update "!false" |
| 425 | ) && |
| 426 | (cd super/submodule && |
Stefan Beller | b08238a | 2016-03-29 18:27:44 -0700 | [diff] [blame] | 427 | git reset --hard $submodulesha1^ |
Chris Packham | 6cb5728 | 2013-07-03 21:02:02 +1200 | [diff] [blame] | 428 | ) && |
| 429 | (cd super && |
Stefan Beller | b08238a | 2016-03-29 18:27:44 -0700 | [diff] [blame] | 430 | test_must_fail git submodule update submodule 2>../actual |
| 431 | ) && |
Vasco Almeida | 1edbaac | 2016-06-17 20:21:07 +0000 | [diff] [blame] | 432 | test_i18ncmp actual expect |
Stefan Beller | b08238a | 2016-03-29 18:27:44 -0700 | [diff] [blame] | 433 | ' |
| 434 | |
| 435 | cat << EOF >expect |
| 436 | Execution of 'false $submodulesha1' failed in submodule path '../submodule' |
| 437 | EOF |
| 438 | |
| 439 | test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' ' |
| 440 | (cd super && |
| 441 | git config submodule.submodule.update "!false" |
| 442 | ) && |
| 443 | (cd super/submodule && |
| 444 | git reset --hard $submodulesha1^ |
| 445 | ) && |
| 446 | (cd super && |
| 447 | mkdir tmp && cd tmp && |
| 448 | test_must_fail git submodule update ../submodule 2>../../actual |
| 449 | ) && |
Vasco Almeida | 1edbaac | 2016-06-17 20:21:07 +0000 | [diff] [blame] | 450 | test_i18ncmp actual expect |
Chris Packham | 6cb5728 | 2013-07-03 21:02:02 +1200 | [diff] [blame] | 451 | ' |
| 452 | |
Stefan Beller | e7b37ca | 2017-01-25 15:48:51 -0800 | [diff] [blame] | 453 | test_expect_success 'submodule update - command run for initial population of submodule' ' |
Junio C Hamano | a4dded0 | 2017-03-22 15:12:07 -0700 | [diff] [blame] | 454 | cat >expect <<-EOF && |
Stefan Beller | e7b37ca | 2017-01-25 15:48:51 -0800 | [diff] [blame] | 455 | Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\'' |
Junio C Hamano | a4dded0 | 2017-03-22 15:12:07 -0700 | [diff] [blame] | 456 | EOF |
Stefan Beller | e7b37ca | 2017-01-25 15:48:51 -0800 | [diff] [blame] | 457 | rm -rf super/submodule && |
Junio C Hamano | a4dded0 | 2017-03-22 15:12:07 -0700 | [diff] [blame] | 458 | test_must_fail git -C super submodule update 2>actual && |
Ævar Arnfjörð Bjarmason | 0d75bfe | 2017-05-05 18:19:32 +0000 | [diff] [blame] | 459 | test_i18ncmp expect actual && |
Stefan Beller | e7b37ca | 2017-01-25 15:48:51 -0800 | [diff] [blame] | 460 | git -C super submodule update --checkout |
| 461 | ' |
| 462 | |
Stefan Beller | c1e06d1 | 2016-03-29 18:27:45 -0700 | [diff] [blame] | 463 | cat << EOF >expect |
| 464 | Execution of 'false $submodulesha1' failed in submodule path '../super/submodule' |
| 465 | Failed to recurse into submodule path '../super' |
| 466 | EOF |
| 467 | |
| 468 | test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' ' |
| 469 | (cd recursivesuper && |
| 470 | git submodule update --remote super && |
| 471 | git add super && |
| 472 | git commit -m "update to latest to have more than one commit in submodules" |
| 473 | ) && |
| 474 | git -C recursivesuper/super config submodule.submodule.update "!false" && |
| 475 | git -C recursivesuper/super/submodule reset --hard $submodulesha1^ && |
| 476 | (cd recursivesuper && |
| 477 | mkdir -p tmp && cd tmp && |
| 478 | test_must_fail git submodule update --recursive ../super 2>../../actual |
| 479 | ) && |
Vasco Almeida | 1edbaac | 2016-06-17 20:21:07 +0000 | [diff] [blame] | 480 | test_i18ncmp actual expect |
Spencer E. Olson | b200021 | 2011-02-17 09:18:46 -0700 | [diff] [blame] | 481 | ' |
| 482 | |
Junio C Hamano | ac1fbbd | 2013-12-02 13:31:55 -0800 | [diff] [blame] | 483 | test_expect_success 'submodule init does not copy command into .git/config' ' |
| 484 | (cd super && |
Elijah Newren | 65799fb | 2018-08-08 09:31:05 -0700 | [diff] [blame] | 485 | git ls-files -s submodule >out && |
| 486 | H=$(cut -d" " -f2 out) && |
Junio C Hamano | ac1fbbd | 2013-12-02 13:31:55 -0800 | [diff] [blame] | 487 | mkdir submodule1 && |
| 488 | git update-index --add --cacheinfo 160000 $H submodule1 && |
| 489 | git config -f .gitmodules submodule.submodule1.path submodule1 && |
| 490 | git config -f .gitmodules submodule.submodule1.url ../submodule && |
| 491 | git config -f .gitmodules submodule.submodule1.update !false && |
| 492 | git submodule init submodule1 && |
| 493 | echo "none" >expect && |
| 494 | git config submodule.submodule1.update >actual && |
| 495 | test_cmp expect actual |
| 496 | ) |
| 497 | ' |
| 498 | |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 499 | test_expect_success 'submodule init picks up rebase' ' |
| 500 | (cd super && |
Stephen Boyd | c9c8c56 | 2010-03-05 00:20:38 -0800 | [diff] [blame] | 501 | git config -f .gitmodules submodule.rebasing.update rebase && |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 502 | git submodule init rebasing && |
Stephen Boyd | c9c8c56 | 2010-03-05 00:20:38 -0800 | [diff] [blame] | 503 | test "rebase" = "$(git config submodule.rebasing.update)" |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 504 | ) |
| 505 | ' |
| 506 | |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 507 | test_expect_success 'submodule init picks up merge' ' |
| 508 | (cd super && |
Stephen Boyd | c9c8c56 | 2010-03-05 00:20:38 -0800 | [diff] [blame] | 509 | git config -f .gitmodules submodule.merging.update merge && |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 510 | git submodule init merging && |
Stephen Boyd | c9c8c56 | 2010-03-05 00:20:38 -0800 | [diff] [blame] | 511 | test "merge" = "$(git config submodule.merging.update)" |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 512 | ) |
| 513 | ' |
| 514 | |
Spencer E. Olson | b200021 | 2011-02-17 09:18:46 -0700 | [diff] [blame] | 515 | test_expect_success 'submodule update --merge - ignores --merge for new submodules' ' |
Stefan Beller | e7b37ca | 2017-01-25 15:48:51 -0800 | [diff] [blame] | 516 | test_config -C super submodule.submodule.update checkout && |
Spencer E. Olson | b200021 | 2011-02-17 09:18:46 -0700 | [diff] [blame] | 517 | (cd super && |
| 518 | rm -rf submodule && |
| 519 | git submodule update submodule && |
| 520 | git status -s submodule >expect && |
| 521 | rm -rf submodule && |
| 522 | git submodule update --merge submodule && |
| 523 | git status -s submodule >actual && |
| 524 | test_cmp expect actual |
| 525 | ) |
| 526 | ' |
| 527 | |
| 528 | test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' ' |
Stefan Beller | e7b37ca | 2017-01-25 15:48:51 -0800 | [diff] [blame] | 529 | test_config -C super submodule.submodule.update checkout && |
Spencer E. Olson | b200021 | 2011-02-17 09:18:46 -0700 | [diff] [blame] | 530 | (cd super && |
| 531 | rm -rf submodule && |
| 532 | git submodule update submodule && |
| 533 | git status -s submodule >expect && |
| 534 | rm -rf submodule && |
| 535 | git submodule update --rebase submodule && |
| 536 | git status -s submodule >actual && |
| 537 | test_cmp expect actual |
| 538 | ) |
| 539 | ' |
| 540 | |
| 541 | test_expect_success 'submodule update ignores update=merge config for new submodules' ' |
| 542 | (cd super && |
| 543 | rm -rf submodule && |
| 544 | git submodule update submodule && |
| 545 | git status -s submodule >expect && |
| 546 | rm -rf submodule && |
| 547 | git config submodule.submodule.update merge && |
| 548 | git submodule update submodule && |
| 549 | git status -s submodule >actual && |
| 550 | git config --unset submodule.submodule.update && |
| 551 | test_cmp expect actual |
| 552 | ) |
| 553 | ' |
| 554 | |
| 555 | test_expect_success 'submodule update ignores update=rebase config for new submodules' ' |
| 556 | (cd super && |
| 557 | rm -rf submodule && |
| 558 | git submodule update submodule && |
| 559 | git status -s submodule >expect && |
| 560 | rm -rf submodule && |
| 561 | git config submodule.submodule.update rebase && |
| 562 | git submodule update submodule && |
| 563 | git status -s submodule >actual && |
| 564 | git config --unset submodule.submodule.update && |
| 565 | test_cmp expect actual |
| 566 | ) |
| 567 | ' |
| 568 | |
Heiko Voigt | 322bb6e | 2011-08-11 19:51:46 +0200 | [diff] [blame] | 569 | test_expect_success 'submodule init picks up update=none' ' |
| 570 | (cd super && |
| 571 | git config -f .gitmodules submodule.none.update none && |
| 572 | git submodule init none && |
| 573 | test "none" = "$(git config submodule.none.update)" |
| 574 | ) |
| 575 | ' |
| 576 | |
| 577 | test_expect_success 'submodule update - update=none in .git/config' ' |
| 578 | (cd super && |
| 579 | git config submodule.submodule.update none && |
| 580 | (cd submodule && |
| 581 | git checkout master && |
| 582 | compare_head |
| 583 | ) && |
Elijah Newren | 65799fb | 2018-08-08 09:31:05 -0700 | [diff] [blame] | 584 | git diff --name-only >out && |
| 585 | grep ^submodule$ out && |
Heiko Voigt | 322bb6e | 2011-08-11 19:51:46 +0200 | [diff] [blame] | 586 | git submodule update && |
Elijah Newren | 65799fb | 2018-08-08 09:31:05 -0700 | [diff] [blame] | 587 | git diff --name-only >out && |
| 588 | grep ^submodule$ out && |
Heiko Voigt | 322bb6e | 2011-08-11 19:51:46 +0200 | [diff] [blame] | 589 | (cd submodule && |
| 590 | compare_head |
| 591 | ) && |
| 592 | git config --unset submodule.submodule.update && |
| 593 | git submodule update submodule |
| 594 | ) |
| 595 | ' |
| 596 | |
| 597 | test_expect_success 'submodule update - update=none in .git/config but --checkout given' ' |
| 598 | (cd super && |
| 599 | git config submodule.submodule.update none && |
| 600 | (cd submodule && |
| 601 | git checkout master && |
| 602 | compare_head |
| 603 | ) && |
Elijah Newren | 65799fb | 2018-08-08 09:31:05 -0700 | [diff] [blame] | 604 | git diff --name-only >out && |
| 605 | grep ^submodule$ out && |
Heiko Voigt | 322bb6e | 2011-08-11 19:51:46 +0200 | [diff] [blame] | 606 | git submodule update --checkout && |
Elijah Newren | 602813c | 2018-08-08 09:31:04 -0700 | [diff] [blame] | 607 | git diff --name-only >out && |
| 608 | ! grep ^submodule$ out && |
Heiko Voigt | 322bb6e | 2011-08-11 19:51:46 +0200 | [diff] [blame] | 609 | (cd submodule && |
Elijah Newren | 9fd1080 | 2018-08-08 09:31:07 -0700 | [diff] [blame] | 610 | ! compare_head |
Heiko Voigt | 322bb6e | 2011-08-11 19:51:46 +0200 | [diff] [blame] | 611 | ) && |
| 612 | git config --unset submodule.submodule.update |
| 613 | ) |
| 614 | ' |
| 615 | |
| 616 | test_expect_success 'submodule update --init skips submodule with update=none' ' |
| 617 | (cd super && |
| 618 | git add .gitmodules && |
| 619 | git commit -m ".gitmodules" |
| 620 | ) && |
| 621 | git clone super cloned && |
| 622 | (cd cloned && |
| 623 | git submodule update --init && |
Elijah Newren | 7e9055b | 2018-08-08 09:31:06 -0700 | [diff] [blame] | 624 | test_path_exists submodule/.git && |
| 625 | test_path_is_missing none/.git |
Heiko Voigt | 322bb6e | 2011-08-11 19:51:46 +0200 | [diff] [blame] | 626 | ) |
| 627 | ' |
| 628 | |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 629 | test_expect_success 'submodule update continues after checkout error' ' |
| 630 | (cd super && |
| 631 | git reset --hard HEAD && |
| 632 | git submodule add ../submodule submodule2 && |
| 633 | git submodule init && |
| 634 | git commit -am "new_submodule" && |
| 635 | (cd submodule2 && |
Junio C Hamano | ad6a599 | 2012-07-30 10:51:52 -0700 | [diff] [blame] | 636 | git rev-parse --verify HEAD >../expect |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 637 | ) && |
| 638 | (cd submodule && |
| 639 | test_commit "update_submodule" file |
| 640 | ) && |
| 641 | (cd submodule2 && |
| 642 | test_commit "update_submodule2" file |
| 643 | ) && |
| 644 | git add submodule && |
| 645 | git add submodule2 && |
| 646 | git commit -m "two_new_submodule_commits" && |
| 647 | (cd submodule && |
| 648 | echo "" > file |
| 649 | ) && |
| 650 | git checkout HEAD^ && |
| 651 | test_must_fail git submodule update && |
| 652 | (cd submodule2 && |
Junio C Hamano | ad6a599 | 2012-07-30 10:51:52 -0700 | [diff] [blame] | 653 | git rev-parse --verify HEAD >../actual |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 654 | ) && |
| 655 | test_cmp expect actual |
| 656 | ) |
| 657 | ' |
| 658 | test_expect_success 'submodule update continues after recursive checkout error' ' |
| 659 | (cd super && |
| 660 | git reset --hard HEAD && |
| 661 | git checkout master && |
| 662 | git submodule update && |
| 663 | (cd submodule && |
| 664 | git submodule add ../submodule subsubmodule && |
| 665 | git submodule init && |
| 666 | git commit -m "new_subsubmodule" |
| 667 | ) && |
| 668 | git add submodule && |
| 669 | git commit -m "update_submodule" && |
| 670 | (cd submodule && |
| 671 | (cd subsubmodule && |
| 672 | test_commit "update_subsubmodule" file |
| 673 | ) && |
| 674 | git add subsubmodule && |
| 675 | test_commit "update_submodule_again" file && |
| 676 | (cd subsubmodule && |
| 677 | test_commit "update_subsubmodule_again" file |
| 678 | ) && |
| 679 | test_commit "update_submodule_again_again" file |
| 680 | ) && |
| 681 | (cd submodule2 && |
Junio C Hamano | ad6a599 | 2012-07-30 10:51:52 -0700 | [diff] [blame] | 682 | git rev-parse --verify HEAD >../expect && |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 683 | test_commit "update_submodule2_again" file |
| 684 | ) && |
| 685 | git add submodule && |
| 686 | git add submodule2 && |
| 687 | git commit -m "new_commits" && |
| 688 | git checkout HEAD^ && |
| 689 | (cd submodule && |
| 690 | git checkout HEAD^ && |
| 691 | (cd subsubmodule && |
| 692 | echo "" > file |
| 693 | ) |
| 694 | ) && |
| 695 | test_must_fail git submodule update --recursive && |
| 696 | (cd submodule2 && |
Junio C Hamano | ad6a599 | 2012-07-30 10:51:52 -0700 | [diff] [blame] | 697 | git rev-parse --verify HEAD >../actual |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 698 | ) && |
| 699 | test_cmp expect actual |
| 700 | ) |
| 701 | ' |
| 702 | |
| 703 | test_expect_success 'submodule update exit immediately in case of merge conflict' ' |
| 704 | (cd super && |
| 705 | git checkout master && |
| 706 | git reset --hard HEAD && |
| 707 | (cd submodule && |
| 708 | (cd subsubmodule && |
| 709 | git reset --hard HEAD |
| 710 | ) |
| 711 | ) && |
| 712 | git submodule update --recursive && |
| 713 | (cd submodule && |
| 714 | test_commit "update_submodule_2" file |
| 715 | ) && |
| 716 | (cd submodule2 && |
| 717 | test_commit "update_submodule2_2" file |
| 718 | ) && |
| 719 | git add submodule && |
| 720 | git add submodule2 && |
| 721 | git commit -m "two_new_submodule_commits" && |
| 722 | (cd submodule && |
| 723 | git checkout master && |
| 724 | test_commit "conflict" file && |
| 725 | echo "conflict" > file |
| 726 | ) && |
| 727 | git checkout HEAD^ && |
| 728 | (cd submodule2 && |
Junio C Hamano | ad6a599 | 2012-07-30 10:51:52 -0700 | [diff] [blame] | 729 | git rev-parse --verify HEAD >../expect |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 730 | ) && |
| 731 | git config submodule.submodule.update merge && |
| 732 | test_must_fail git submodule update && |
| 733 | (cd submodule2 && |
Junio C Hamano | ad6a599 | 2012-07-30 10:51:52 -0700 | [diff] [blame] | 734 | git rev-parse --verify HEAD >../actual |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 735 | ) && |
| 736 | test_cmp expect actual |
| 737 | ) |
| 738 | ' |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 739 | |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 740 | test_expect_success 'submodule update exit immediately after recursive rebase error' ' |
| 741 | (cd super && |
| 742 | git checkout master && |
| 743 | git reset --hard HEAD && |
| 744 | (cd submodule && |
| 745 | git reset --hard HEAD && |
| 746 | git submodule update --recursive |
| 747 | ) && |
| 748 | (cd submodule && |
| 749 | test_commit "update_submodule_3" file |
| 750 | ) && |
| 751 | (cd submodule2 && |
| 752 | test_commit "update_submodule2_3" file |
| 753 | ) && |
| 754 | git add submodule && |
| 755 | git add submodule2 && |
| 756 | git commit -m "two_new_submodule_commits" && |
| 757 | (cd submodule && |
| 758 | git checkout master && |
| 759 | test_commit "conflict2" file && |
| 760 | echo "conflict" > file |
| 761 | ) && |
| 762 | git checkout HEAD^ && |
| 763 | (cd submodule2 && |
Junio C Hamano | ad6a599 | 2012-07-30 10:51:52 -0700 | [diff] [blame] | 764 | git rev-parse --verify HEAD >../expect |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 765 | ) && |
| 766 | git config submodule.submodule.update rebase && |
| 767 | test_must_fail git submodule update && |
| 768 | (cd submodule2 && |
Junio C Hamano | ad6a599 | 2012-07-30 10:51:52 -0700 | [diff] [blame] | 769 | git rev-parse --verify HEAD >../actual |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 770 | ) && |
| 771 | test_cmp expect actual |
| 772 | ) |
| 773 | ' |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 774 | |
| 775 | test_expect_success 'add different submodules to the same path' ' |
| 776 | (cd super && |
| 777 | git submodule add ../submodule s1 && |
| 778 | test_must_fail git submodule add ../merging s1 |
| 779 | ) |
| 780 | ' |
| 781 | |
| 782 | test_expect_success 'submodule add places git-dir in superprojects git-dir' ' |
| 783 | (cd super && |
| 784 | mkdir deeper && |
| 785 | git submodule add ../submodule deeper/submodule && |
| 786 | (cd deeper/submodule && |
| 787 | git log > ../../expected |
| 788 | ) && |
| 789 | (cd .git/modules/deeper/submodule && |
| 790 | git log > ../../../../actual |
| 791 | ) && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 792 | test_cmp expected actual |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 793 | ) |
| 794 | ' |
| 795 | |
| 796 | test_expect_success 'submodule update places git-dir in superprojects git-dir' ' |
| 797 | (cd super && |
| 798 | git commit -m "added submodule" |
| 799 | ) && |
| 800 | git clone super super2 && |
| 801 | (cd super2 && |
| 802 | git submodule init deeper/submodule && |
| 803 | git submodule update && |
| 804 | (cd deeper/submodule && |
| 805 | git log > ../../expected |
| 806 | ) && |
| 807 | (cd .git/modules/deeper/submodule && |
| 808 | git log > ../../../../actual |
| 809 | ) && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 810 | test_cmp expected actual |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 811 | ) |
| 812 | ' |
| 813 | |
| 814 | test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' ' |
| 815 | (cd super2 && |
| 816 | (cd deeper/submodule && |
| 817 | git submodule add ../submodule subsubmodule && |
| 818 | (cd subsubmodule && |
| 819 | git log > ../../../expected |
| 820 | ) && |
| 821 | git commit -m "added subsubmodule" && |
Junio C Hamano | ae74f7d | 2013-01-04 16:19:19 -0800 | [diff] [blame] | 822 | git push origin : |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 823 | ) && |
| 824 | (cd .git/modules/deeper/submodule/modules/subsubmodule && |
| 825 | git log > ../../../../../actual |
| 826 | ) && |
| 827 | git add deeper/submodule && |
| 828 | git commit -m "update submodule" && |
Junio C Hamano | ae74f7d | 2013-01-04 16:19:19 -0800 | [diff] [blame] | 829 | git push origin : && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 830 | test_cmp expected actual |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 831 | ) |
| 832 | ' |
| 833 | |
| 834 | test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' ' |
| 835 | mkdir super_update_r && |
| 836 | (cd super_update_r && |
| 837 | git init --bare |
| 838 | ) && |
| 839 | mkdir subsuper_update_r && |
| 840 | (cd subsuper_update_r && |
| 841 | git init --bare |
| 842 | ) && |
| 843 | mkdir subsubsuper_update_r && |
| 844 | (cd subsubsuper_update_r && |
| 845 | git init --bare |
| 846 | ) && |
| 847 | git clone subsubsuper_update_r subsubsuper_update_r2 && |
| 848 | (cd subsubsuper_update_r2 && |
| 849 | test_commit "update_subsubsuper" file && |
| 850 | git push origin master |
| 851 | ) && |
| 852 | git clone subsuper_update_r subsuper_update_r2 && |
| 853 | (cd subsuper_update_r2 && |
| 854 | test_commit "update_subsuper" file && |
| 855 | git submodule add ../subsubsuper_update_r subsubmodule && |
| 856 | git commit -am "subsubmodule" && |
| 857 | git push origin master |
| 858 | ) && |
| 859 | git clone super_update_r super_update_r2 && |
| 860 | (cd super_update_r2 && |
| 861 | test_commit "update_super" file && |
| 862 | git submodule add ../subsuper_update_r submodule && |
| 863 | git commit -am "submodule" && |
| 864 | git push origin master |
| 865 | ) && |
| 866 | rm -rf super_update_r2 && |
| 867 | git clone super_update_r super_update_r2 && |
| 868 | (cd super_update_r2 && |
William Entriken | 75bf5e6 | 2013-03-02 14:44:59 -0500 | [diff] [blame] | 869 | git submodule update --init --recursive >actual && |
Junio C Hamano | d851ffb | 2014-04-02 14:15:36 -0700 | [diff] [blame] | 870 | test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual && |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 871 | (cd submodule/subsubmodule && |
| 872 | git log > ../../expected |
| 873 | ) && |
Eric Sunshine | e974e06 | 2018-07-01 20:24:03 -0400 | [diff] [blame] | 874 | (cd .git/modules/submodule/modules/subsubmodule && |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 875 | git log > ../../../../../actual |
Eric Sunshine | e974e06 | 2018-07-01 20:24:03 -0400 | [diff] [blame] | 876 | ) && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 877 | test_cmp expected actual |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 878 | ) |
| 879 | ' |
| 880 | |
Jens Lehmann | 1017c1a | 2012-01-24 22:49:56 +0100 | [diff] [blame] | 881 | test_expect_success 'submodule add properly re-creates deeper level submodules' ' |
| 882 | (cd super && |
| 883 | git reset --hard master && |
| 884 | rm -rf deeper/ && |
Jens Lehmann | 4b7c286 | 2012-09-30 23:01:29 +0200 | [diff] [blame] | 885 | git submodule add --force ../submodule deeper/submodule |
Jens Lehmann | 1017c1a | 2012-01-24 22:49:56 +0100 | [diff] [blame] | 886 | ) |
| 887 | ' |
| 888 | |
Jens Lehmann | 69c3051 | 2012-03-04 22:15:36 +0100 | [diff] [blame] | 889 | test_expect_success 'submodule update properly revives a moved submodule' ' |
| 890 | (cd super && |
Nguyễn Thái Ngọc Duy | b397ea4 | 2013-03-13 18:42:52 +0700 | [diff] [blame] | 891 | H=$(git rev-parse --short HEAD) && |
Jens Lehmann | 69c3051 | 2012-03-04 22:15:36 +0100 | [diff] [blame] | 892 | git commit -am "pre move" && |
Nguyễn Thái Ngọc Duy | b397ea4 | 2013-03-13 18:42:52 +0700 | [diff] [blame] | 893 | H2=$(git rev-parse --short HEAD) && |
Elijah Newren | 65799fb | 2018-08-08 09:31:05 -0700 | [diff] [blame] | 894 | git status >out && |
| 895 | sed "s/$H/XXX/" out >expect && |
Eric Sunshine | e974e06 | 2018-07-01 20:24:03 -0400 | [diff] [blame] | 896 | H=$(cd submodule2 && git rev-parse HEAD) && |
Jens Lehmann | 69c3051 | 2012-03-04 22:15:36 +0100 | [diff] [blame] | 897 | git rm --cached submodule2 && |
| 898 | rm -rf submodule2 && |
| 899 | mkdir -p "moved/sub module" && |
| 900 | git update-index --add --cacheinfo 160000 $H "moved/sub module" && |
SZEDER Gábor | 8de19d6 | 2018-06-16 22:33:19 +0200 | [diff] [blame] | 901 | git config -f .gitmodules submodule.submodule2.path "moved/sub module" && |
Jens Lehmann | 69c3051 | 2012-03-04 22:15:36 +0100 | [diff] [blame] | 902 | git commit -am "post move" && |
| 903 | git submodule update && |
Elijah Newren | 65799fb | 2018-08-08 09:31:05 -0700 | [diff] [blame] | 904 | git status > out && |
| 905 | sed "s/$H2/XXX/" out >actual && |
Jens Lehmann | 69c3051 | 2012-03-04 22:15:36 +0100 | [diff] [blame] | 906 | test_cmp expect actual |
| 907 | ) |
| 908 | ' |
| 909 | |
Jens Lehmann | 6eafa6d | 2012-07-12 19:45:32 +0200 | [diff] [blame] | 910 | test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' ' |
| 911 | mkdir -p linked/dir && |
| 912 | ln -s linked/dir linkto && |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 913 | (cd linkto && |
| 914 | git clone "$TRASH_DIRECTORY"/super_update_r2 super && |
| 915 | (cd super && |
| 916 | git submodule update --init --recursive |
| 917 | ) |
Jens Lehmann | 6eafa6d | 2012-07-12 19:45:32 +0200 | [diff] [blame] | 918 | ) |
| 919 | ' |
| 920 | |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 921 | test_expect_success 'submodule update clone shallow submodule' ' |
Stefan Beller | d4470c5 | 2016-07-28 17:44:03 -0700 | [diff] [blame] | 922 | test_when_finished "rm -rf super3" && |
Elijah Newren | 65799fb | 2018-08-08 09:31:05 -0700 | [diff] [blame] | 923 | first=$(git -C cloned rev-parse HEAD:submodule) && |
Stefan Beller | d4470c5 | 2016-07-28 17:44:03 -0700 | [diff] [blame] | 924 | second=$(git -C submodule rev-parse HEAD) && |
Stefan Beller | 967d7f8 | 2016-08-10 10:56:07 -0700 | [diff] [blame] | 925 | commit_count=$(git -C submodule rev-list --count $first^..$second) && |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 926 | git clone cloned super3 && |
Jeff King | 99094a7 | 2015-03-20 06:07:15 -0400 | [diff] [blame] | 927 | pwd=$(pwd) && |
Stefan Beller | d4470c5 | 2016-07-28 17:44:03 -0700 | [diff] [blame] | 928 | ( |
| 929 | cd super3 && |
| 930 | sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && |
| 931 | mv -f .gitmodules.tmp .gitmodules && |
| 932 | git submodule update --init --depth=$commit_count && |
Elijah Newren | 65799fb | 2018-08-08 09:31:05 -0700 | [diff] [blame] | 933 | git -C submodule log --oneline >out && |
| 934 | test_line_count = 1 out |
Stefan Beller | d4470c5 | 2016-07-28 17:44:03 -0700 | [diff] [blame] | 935 | ) |
Jens Lehmann | 3614128 | 2013-11-11 21:55:52 +0100 | [diff] [blame] | 936 | ' |
| 937 | |
Stefan Beller | 6cbf454 | 2016-07-28 17:44:04 -0700 | [diff] [blame] | 938 | test_expect_success 'submodule update clone shallow submodule outside of depth' ' |
| 939 | test_when_finished "rm -rf super3" && |
| 940 | git clone cloned super3 && |
| 941 | pwd=$(pwd) && |
| 942 | ( |
| 943 | cd super3 && |
| 944 | sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && |
| 945 | mv -f .gitmodules.tmp .gitmodules && |
Jonathan Tan | ab0c5f5 | 2019-02-25 13:54:08 -0800 | [diff] [blame] | 946 | # Some protocol versions (e.g. 2) support fetching |
| 947 | # unadvertised objects, so restrict this test to v0. |
| 948 | test_must_fail env GIT_TEST_PROTOCOL_VERSION= \ |
| 949 | git submodule update --init --depth=1 2>actual && |
Stefan Beller | 6cbf454 | 2016-07-28 17:44:04 -0700 | [diff] [blame] | 950 | test_i18ngrep "Direct fetching of that commit failed." actual && |
| 951 | git -C ../submodule config uploadpack.allowReachableSHA1InWant true && |
| 952 | git submodule update --init --depth=1 >actual && |
Elijah Newren | 65799fb | 2018-08-08 09:31:05 -0700 | [diff] [blame] | 953 | git -C submodule log --oneline >out && |
| 954 | test_line_count = 1 out |
Stefan Beller | 6cbf454 | 2016-07-28 17:44:04 -0700 | [diff] [blame] | 955 | ) |
| 956 | ' |
| 957 | |
Jens Lehmann | 3614128 | 2013-11-11 21:55:52 +0100 | [diff] [blame] | 958 | test_expect_success 'submodule update --recursive drops module name before recursing' ' |
| 959 | (cd super2 && |
| 960 | (cd deeper/submodule/subsubmodule && |
| 961 | git checkout HEAD^ |
| 962 | ) && |
| 963 | git submodule update --recursive deeper/submodule >actual && |
| 964 | test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 965 | ) |
| 966 | ' |
Stefan Beller | 2335b87 | 2016-02-29 18:07:19 -0800 | [diff] [blame] | 967 | |
| 968 | test_expect_success 'submodule update can be run in parallel' ' |
| 969 | (cd super2 && |
| 970 | GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 && |
| 971 | grep "7 tasks" trace.out && |
| 972 | git config submodule.fetchJobs 8 && |
| 973 | GIT_TRACE=$(pwd)/trace.out git submodule update && |
| 974 | grep "8 tasks" trace.out && |
| 975 | GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 && |
| 976 | grep "9 tasks" trace.out |
| 977 | ) |
| 978 | ' |
Stefan Beller | 72290d6 | 2016-02-29 18:07:20 -0800 | [diff] [blame] | 979 | |
| 980 | test_expect_success 'git clone passes the parallel jobs config on to submodules' ' |
| 981 | test_when_finished "rm -rf super4" && |
| 982 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 && |
| 983 | grep "7 tasks" trace.out && |
| 984 | rm -rf super4 && |
| 985 | git config --global submodule.fetchJobs 8 && |
| 986 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 && |
| 987 | grep "8 tasks" trace.out && |
| 988 | rm -rf super4 && |
| 989 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 && |
| 990 | grep "9 tasks" trace.out && |
| 991 | rm -rf super4 |
| 992 | ' |
| 993 | |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 994 | test_done |