msysGit-based Git for Windows 1.x was superseded by Git for Windows 2.x
[git/mingw/4msysgit.git] / t / t7403-submodule-sync.sh
blob79bc135bf69ea5813f0a372db6bbefa0f9a92753
1 #!/bin/sh
3 # Copyright (c) 2008 David Aguilar
6 test_description='git submodule sync
8 These tests exercise the "git submodule sync" subcommand.
11 . ./test-lib.sh
13 test_expect_success setup '
14 echo file >file &&
15 git add file &&
16 test_tick &&
17 git commit -m upstream &&
18 git clone . super &&
19 git clone super submodule &&
21 cd submodule &&
22 git submodule add ../submodule sub-submodule &&
23 test_tick &&
24 git commit -m "sub-submodule"
25 ) &&
27 cd super &&
28 git submodule add ../submodule submodule &&
29 test_tick &&
30 git commit -m "submodule"
31 ) &&
32 git clone super super-clone &&
34 cd super-clone &&
35 git submodule update --init --recursive
36 ) &&
37 git clone super empty-clone &&
39 cd empty-clone &&
40 git submodule init
41 ) &&
42 git clone super top-only-clone &&
43 git clone super relative-clone &&
45 cd relative-clone &&
46 git submodule update --init --recursive
47 ) &&
48 git clone super recursive-clone &&
50 cd recursive-clone &&
51 git submodule update --init --recursive
55 test_expect_success 'change submodule' '
57 cd submodule &&
58 echo second line >>file &&
59 test_tick &&
60 git commit -a -m "change submodule"
64 reset_submodule_urls () {
65 local root
66 root=$(pwd) &&
68 cd super-clone/submodule &&
69 git config remote.origin.url "$root/submodule"
70 ) &&
72 cd super-clone/submodule/sub-submodule &&
73 git config remote.origin.url "$root/submodule"
77 test_expect_success 'change submodule url' '
79 cd super &&
80 cd submodule &&
81 git checkout master &&
82 git pull
83 ) &&
84 mv submodule moved-submodule &&
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
90 ) &&
92 cd super &&
93 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
94 test_tick &&
95 git commit -a -m moved-submodule
99 test_expect_success '"git submodule sync" should update submodule URLs' '
101 cd super-clone &&
102 git pull --no-recurse-submodules &&
103 git submodule sync
104 ) &&
105 test -d "$(
106 cd super-clone/submodule &&
107 git config remote.origin.url
108 )" &&
109 test ! -d "$(
110 cd super-clone/submodule/sub-submodule &&
111 git config remote.origin.url
112 )" &&
114 cd super-clone/submodule &&
115 git checkout master &&
116 git pull
117 ) &&
119 cd super-clone &&
120 test -d "$(git config submodule.submodule.url)"
124 test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
126 cd super-clone &&
128 cd submodule &&
129 git pull --no-recurse-submodules
130 ) &&
131 git submodule sync --recursive
132 ) &&
133 test -d "$(
134 cd super-clone/submodule &&
135 git config remote.origin.url
136 )" &&
137 test -d "$(
138 cd super-clone/submodule/sub-submodule &&
139 git config remote.origin.url
140 )" &&
142 cd super-clone/submodule/sub-submodule &&
143 git checkout master &&
144 git pull
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' '
154 cd super-clone &&
155 git pull --no-recurse-submodules &&
156 mkdir -p sub &&
157 cd sub &&
158 git submodule sync >../../output
159 ) &&
160 grep "\\.\\./submodule" output &&
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 )" &&
170 cd super-clone/submodule &&
171 git checkout master &&
172 git pull
173 ) &&
175 cd super-clone &&
176 test -d "$(git config submodule.submodule.url)"
180 test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
182 cd super-clone &&
184 cd submodule &&
185 git pull --no-recurse-submodules
186 ) &&
187 mkdir -p sub &&
188 cd sub &&
189 git submodule sync --recursive >../../output
190 ) &&
191 grep "\\.\\./submodule/sub-submodule" output &&
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 )" &&
201 cd super-clone/submodule/sub-submodule &&
202 git checkout master &&
203 git pull
207 test_expect_success '"git submodule sync" should update known submodule URLs' '
209 cd empty-clone &&
210 git pull &&
211 git submodule sync &&
212 test -d "$(git config submodule.submodule.url)"
216 test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
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)"
227 test_expect_success '"git submodule sync" handles origin URL of the form foo' '
229 cd relative-clone &&
230 git remote set-url origin foo &&
231 git submodule sync &&
233 cd submodule &&
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' '
242 cd relative-clone &&
243 git remote set-url origin foo/bar &&
244 git submodule sync &&
246 cd submodule &&
247 #actual foo/submodule
248 test "$(git config remote.origin.url)" = "../foo/submodule"
249 ) &&
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 &&
263 cd submodule &&
264 #actual foo/submodule
265 test "$(git config remote.origin.url)" = "../foo/submodule"
266 ) &&
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' '
276 cd relative-clone &&
277 git remote set-url origin ./foo &&
278 git submodule sync &&
280 cd submodule &&
281 #actual ./submodule
282 test "$(git config remote.origin.url)" = "../submodule"
287 test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
289 cd relative-clone &&
290 git remote set-url origin ./foo/bar &&
291 git submodule sync &&
293 cd submodule &&
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' '
302 cd relative-clone &&
303 git remote set-url origin ../foo &&
304 git submodule sync &&
306 cd submodule &&
307 #actual ../submodule
308 test "$(git config remote.origin.url)" = "../../submodule"
313 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
315 cd relative-clone &&
316 git remote set-url origin ../foo/bar &&
317 git submodule sync &&
319 cd submodule &&
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' '
328 cd relative-clone &&
329 git remote set-url origin ../foo/bar &&
330 mkdir -p a/b/c &&
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 &&
342 cd a/b/c &&
343 #actual ../foo/bar/a/b/c
344 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
350 test_done