3 # Copyright (c) 2008 David Aguilar
6 test_description='git submodule sync
8 These tests exercise the "git submodule sync" subcommand.
13 test_expect_success setup '
17 git commit -m upstream &&
19 git clone super submodule &&
22 git submodule add ../submodule sub-submodule &&
24 git commit -m "sub-submodule"
28 git submodule add ../submodule submodule &&
30 git commit -m "submodule"
32 git clone super super-clone &&
35 git submodule update --init --recursive
37 git clone super empty-clone &&
42 git clone super top-only-clone &&
43 git clone super relative-clone &&
46 git submodule update --init --recursive
48 git clone super recursive-clone &&
51 git submodule update --init --recursive
55 test_expect_success 'change submodule' '
58 echo second line >>file &&
60 git commit -a -m "change submodule"
64 reset_submodule_urls () {
68 cd super-clone/submodule &&
69 git config remote.origin.url "$root/submodule"
72 cd super-clone/submodule/sub-submodule &&
73 git config remote.origin.url "$root/submodule"
77 test_expect_success 'change submodule url' '
81 git checkout master &&
84 mv submodule moved-submodule &&
87 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
89 git commit -a -m moved-sub-submodule
93 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
95 git commit -a -m moved-submodule
99 test_expect_success '"git submodule sync" should update submodule URLs' '
102 git pull --no-recurse-submodules &&
106 cd super-clone/submodule &&
107 git config remote.origin.url
110 cd super-clone/submodule/sub-submodule &&
111 git config remote.origin.url
114 cd super-clone/submodule &&
115 git checkout master &&
120 test -d "$(git config submodule.submodule.url)"
124 test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
129 git pull --no-recurse-submodules
131 git submodule sync --recursive
134 cd super-clone/submodule &&
135 git config remote.origin.url
138 cd super-clone/submodule/sub-submodule &&
139 git config remote.origin.url
142 cd super-clone/submodule/sub-submodule &&
143 git checkout master &&
148 test_expect_success 'reset submodule URLs' '
149 reset_submodule_urls super-clone
152 test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' '
155 git pull --no-recurse-submodules &&
158 git submodule sync >../../output
160 grep "\\.\\./submodule" output &&
162 cd super-clone/submodule &&
163 git config remote.origin.url
166 cd super-clone/submodule/sub-submodule &&
167 git config remote.origin.url
170 cd super-clone/submodule &&
171 git checkout master &&
176 test -d "$(git config submodule.submodule.url)"
180 test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
185 git pull --no-recurse-submodules
189 git submodule sync --recursive >../../output
191 grep "\\.\\./submodule/sub-submodule" output &&
193 cd super-clone/submodule &&
194 git config remote.origin.url
197 cd super-clone/submodule/sub-submodule &&
198 git config remote.origin.url
201 cd super-clone/submodule/sub-submodule &&
202 git checkout master &&
207 test_expect_success '"git submodule sync" should update known submodule URLs' '
211 git submodule sync &&
212 test -d "$(git config submodule.submodule.url)"
216 test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
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)"
227 test_expect_success '"git submodule sync" handles origin URL of the form foo' '
230 git remote set-url origin foo &&
231 git submodule sync &&
234 #actual fails with: "cannot strip off url foo
235 test "$(git config remote.origin.url)" = "../submodule"
240 test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
243 git remote set-url origin foo/bar &&
244 git submodule sync &&
247 #actual foo/submodule
248 test "$(git config remote.origin.url)" = "../foo/submodule"
251 cd submodule/sub-submodule &&
252 test "$(git config remote.origin.url)" != "../../foo/submodule"
257 test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
259 cd recursive-clone &&
260 git remote set-url origin foo/bar &&
261 git submodule sync --recursive &&
264 #actual foo/submodule
265 test "$(git config remote.origin.url)" = "../foo/submodule"
268 cd submodule/sub-submodule &&
269 test "$(git config remote.origin.url)" = "../../foo/submodule"
274 test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
277 git remote set-url origin ./foo &&
278 git submodule sync &&
282 test "$(git config remote.origin.url)" = "../submodule"
287 test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
290 git remote set-url origin ./foo/bar &&
291 git submodule sync &&
294 #actual ./foo/submodule
295 test "$(git config remote.origin.url)" = "../foo/submodule"
300 test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
303 git remote set-url origin ../foo &&
304 git submodule sync &&
308 test "$(git config remote.origin.url)" = "../../submodule"
313 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
316 git remote set-url origin ../foo/bar &&
317 git submodule sync &&
320 #actual ../foo/submodule
321 test "$(git config remote.origin.url)" = "../../foo/submodule"
326 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
329 git remote set-url origin ../foo/bar &&
335 git add .gitignore &&
337 git commit -m "initial commit"
339 git submodule add ../bar/a/b/c ./a/b/c &&
340 git submodule sync &&
343 #actual ../foo/bar/a/b/c
344 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"