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