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