Git 2.30.9
[git.git] / t / t7403-submodule-sync.sh
blob3bc904bacbc716528168563fdf63a4305c147941
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 git config --global protocol.file.allow always &&
16 echo file >file &&
17 git add file &&
18 test_tick &&
19 git commit -m upstream &&
20 git clone . super &&
21 git clone super submodule &&
23 cd submodule &&
24 git submodule add ../submodule sub-submodule &&
25 test_tick &&
26 git commit -m "sub-submodule"
27 ) &&
29 cd super &&
30 git submodule add ../submodule submodule &&
31 test_tick &&
32 git commit -m "submodule"
33 ) &&
34 git clone super super-clone &&
36 cd super-clone &&
37 git submodule update --init --recursive
38 ) &&
39 git clone super empty-clone &&
41 cd empty-clone &&
42 git submodule init
43 ) &&
44 git clone super top-only-clone &&
45 git clone super relative-clone &&
47 cd relative-clone &&
48 git submodule update --init --recursive
49 ) &&
50 git clone super recursive-clone &&
52 cd recursive-clone &&
53 git submodule update --init --recursive
57 test_expect_success 'change submodule' '
59 cd submodule &&
60 echo second line >>file &&
61 test_tick &&
62 git commit -a -m "change submodule"
66 reset_submodule_urls () {
68 root=$(pwd) &&
69 cd super-clone/submodule &&
70 git config remote.origin.url "$root/submodule"
71 ) &&
73 root=$(pwd) &&
74 cd super-clone/submodule/sub-submodule &&
75 git config remote.origin.url "$root/submodule"
79 test_expect_success 'change submodule url' '
81 cd super &&
82 cd submodule &&
83 git checkout master &&
84 git pull
85 ) &&
86 mv submodule moved-submodule &&
88 cd moved-submodule &&
89 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
90 test_tick &&
91 git commit -a -m moved-sub-submodule
92 ) &&
94 cd super &&
95 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
96 test_tick &&
97 git commit -a -m moved-submodule
101 test_expect_success '"git submodule sync" should update submodule URLs' '
103 cd super-clone &&
104 git pull --no-recurse-submodules &&
105 git submodule sync
106 ) &&
107 test -d "$(
108 cd super-clone/submodule &&
109 git config remote.origin.url
110 )" &&
111 test ! -d "$(
112 cd super-clone/submodule/sub-submodule &&
113 git config remote.origin.url
114 )" &&
116 cd super-clone/submodule &&
117 git checkout master &&
118 git pull
119 ) &&
121 cd super-clone &&
122 test -d "$(git config submodule.submodule.url)"
126 test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
128 cd super-clone &&
130 cd submodule &&
131 git pull --no-recurse-submodules
132 ) &&
133 git submodule sync --recursive
134 ) &&
135 test -d "$(
136 cd super-clone/submodule &&
137 git config remote.origin.url
138 )" &&
139 test -d "$(
140 cd super-clone/submodule/sub-submodule &&
141 git config remote.origin.url
142 )" &&
144 cd super-clone/submodule/sub-submodule &&
145 git checkout master &&
146 git pull
150 test_expect_success 'reset submodule URLs' '
151 reset_submodule_urls super-clone
154 test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' '
156 cd super-clone &&
157 git pull --no-recurse-submodules &&
158 mkdir -p sub &&
159 cd sub &&
160 git submodule sync >../../output
161 ) &&
162 test_i18ngrep "\\.\\./submodule" output &&
163 test -d "$(
164 cd super-clone/submodule &&
165 git config remote.origin.url
166 )" &&
167 test ! -d "$(
168 cd super-clone/submodule/sub-submodule &&
169 git config remote.origin.url
170 )" &&
172 cd super-clone/submodule &&
173 git checkout master &&
174 git pull
175 ) &&
177 cd super-clone &&
178 test -d "$(git config submodule.submodule.url)"
182 test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
184 cd super-clone &&
186 cd submodule &&
187 git pull --no-recurse-submodules
188 ) &&
189 mkdir -p sub &&
190 cd sub &&
191 git submodule sync --recursive >../../output
192 ) &&
193 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
194 test -d "$(
195 cd super-clone/submodule &&
196 git config remote.origin.url
197 )" &&
198 test -d "$(
199 cd super-clone/submodule/sub-submodule &&
200 git config remote.origin.url
201 )" &&
203 cd super-clone/submodule/sub-submodule &&
204 git checkout master &&
205 git pull
209 test_expect_success '"git submodule sync" should update known submodule URLs' '
211 cd empty-clone &&
212 git pull &&
213 git submodule sync &&
214 test -d "$(git config submodule.submodule.url)"
218 test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
220 cd top-only-clone &&
221 git pull &&
222 git submodule sync &&
223 test -z "$(git config submodule.submodule.url)" &&
224 git submodule sync submodule &&
225 test -z "$(git config submodule.submodule.url)"
229 test_expect_success '"git submodule sync" handles origin URL of the form foo' '
231 cd relative-clone &&
232 git remote set-url origin foo &&
233 git submodule sync &&
235 cd submodule &&
236 #actual fails with: "cannot strip off url foo
237 test "$(git config remote.origin.url)" = "../submodule"
242 test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
244 cd relative-clone &&
245 git remote set-url origin foo/bar &&
246 git submodule sync &&
248 cd submodule &&
249 #actual foo/submodule
250 test "$(git config remote.origin.url)" = "../foo/submodule"
251 ) &&
253 cd submodule/sub-submodule &&
254 test "$(git config remote.origin.url)" != "../../foo/submodule"
259 test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
261 cd recursive-clone &&
262 git remote set-url origin foo/bar &&
263 git submodule sync --recursive &&
265 cd submodule &&
266 #actual foo/submodule
267 test "$(git config remote.origin.url)" = "../foo/submodule"
268 ) &&
270 cd submodule/sub-submodule &&
271 test "$(git config remote.origin.url)" = "../../foo/submodule"
276 test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
278 cd relative-clone &&
279 git remote set-url origin ./foo &&
280 git submodule sync &&
282 cd submodule &&
283 #actual ./submodule
284 test "$(git config remote.origin.url)" = "../submodule"
289 test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
291 cd relative-clone &&
292 git remote set-url origin ./foo/bar &&
293 git submodule sync &&
295 cd submodule &&
296 #actual ./foo/submodule
297 test "$(git config remote.origin.url)" = "../foo/submodule"
302 test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
304 cd relative-clone &&
305 git remote set-url origin ../foo &&
306 git submodule sync &&
308 cd submodule &&
309 #actual ../submodule
310 test "$(git config remote.origin.url)" = "../../submodule"
315 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
317 cd relative-clone &&
318 git remote set-url origin ../foo/bar &&
319 git submodule sync &&
321 cd submodule &&
322 #actual ../foo/submodule
323 test "$(git config remote.origin.url)" = "../../foo/submodule"
328 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
330 cd relative-clone &&
331 git remote set-url origin ../foo/bar &&
332 mkdir -p a/b/c &&
334 cd a/b/c &&
335 git init &&
336 >.gitignore &&
337 git add .gitignore &&
338 test_tick &&
339 git commit -m "initial commit"
340 ) &&
341 git submodule add ../bar/a/b/c ./a/b/c &&
342 git submodule sync &&
344 cd a/b/c &&
345 #actual ../foo/bar/a/b/c
346 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
352 test_done