The sixteenth batch
[git.git] / t / t7403-submodule-sync.sh
blobea92ef52a5eb9c593039614a6e42fa308a68b852
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 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
12 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14 . ./test-lib.sh
16 test_expect_success setup '
17 git config --global protocol.file.allow always &&
19 echo file >file &&
20 git add file &&
21 test_tick &&
22 git commit -m upstream &&
23 git clone . super &&
24 git clone super submodule &&
26 cd submodule &&
27 git submodule add ../submodule sub-submodule &&
28 test_tick &&
29 git commit -m "sub-submodule"
30 ) &&
32 cd super &&
33 git submodule add ../submodule submodule &&
34 test_tick &&
35 git commit -m "submodule"
36 ) &&
37 git clone super super-clone &&
39 cd super-clone &&
40 git submodule update --init --recursive
41 ) &&
42 git clone super empty-clone &&
44 cd empty-clone &&
45 git submodule init
46 ) &&
47 git clone super top-only-clone &&
48 git clone super relative-clone &&
50 cd relative-clone &&
51 git submodule update --init --recursive
52 ) &&
53 git clone super recursive-clone &&
55 cd recursive-clone &&
56 git submodule update --init --recursive
60 test_expect_success 'change submodule' '
62 cd submodule &&
63 echo second line >>file &&
64 test_tick &&
65 git commit -a -m "change submodule"
69 reset_submodule_urls () {
71 root=$(pwd) &&
72 cd super-clone/submodule &&
73 git config remote.origin.url "$root/submodule"
74 ) &&
76 root=$(pwd) &&
77 cd super-clone/submodule/sub-submodule &&
78 git config remote.origin.url "$root/submodule"
82 test_expect_success 'change submodule url' '
84 cd super &&
85 cd submodule &&
86 git checkout main &&
87 git pull
88 ) &&
89 mv submodule moved-submodule &&
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
95 ) &&
97 cd super &&
98 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
99 test_tick &&
100 git commit -a -m moved-submodule
104 test_expect_success '"git submodule sync" should update submodule URLs' '
106 cd super-clone &&
107 git pull --no-recurse-submodules &&
108 git submodule sync
109 ) &&
110 test -d "$(
111 cd super-clone/submodule &&
112 git config remote.origin.url
113 )" &&
114 test ! -d "$(
115 cd super-clone/submodule/sub-submodule &&
116 git config remote.origin.url
117 )" &&
119 cd super-clone/submodule &&
120 git checkout main &&
121 git pull
122 ) &&
124 cd super-clone &&
125 test -d "$(git config submodule.submodule.url)"
129 test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
131 cd super-clone &&
133 cd submodule &&
134 git pull --no-recurse-submodules
135 ) &&
136 git submodule sync --recursive
137 ) &&
138 test -d "$(
139 cd super-clone/submodule &&
140 git config remote.origin.url
141 )" &&
142 test -d "$(
143 cd super-clone/submodule/sub-submodule &&
144 git config remote.origin.url
145 )" &&
147 cd super-clone/submodule/sub-submodule &&
148 git checkout main &&
149 git pull
153 test_expect_success 'reset submodule URLs' '
154 reset_submodule_urls super-clone
157 test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' '
159 cd super-clone &&
160 git pull --no-recurse-submodules &&
161 mkdir -p sub &&
162 cd sub &&
163 git submodule sync >../../output
164 ) &&
165 test_i18ngrep "\\.\\./submodule" output &&
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 )" &&
175 cd super-clone/submodule &&
176 git checkout main &&
177 git pull
178 ) &&
180 cd super-clone &&
181 test -d "$(git config submodule.submodule.url)"
185 test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
187 cd super-clone &&
189 cd submodule &&
190 git pull --no-recurse-submodules
191 ) &&
192 mkdir -p sub &&
193 cd sub &&
194 git submodule sync --recursive >../../output
195 ) &&
196 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
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 )" &&
206 cd super-clone/submodule/sub-submodule &&
207 git checkout main &&
208 git pull
212 test_expect_success '"git submodule sync" should update known submodule URLs' '
214 cd empty-clone &&
215 git pull &&
216 git submodule sync &&
217 test -d "$(git config submodule.submodule.url)"
221 test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
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)"
232 test_expect_success '"git submodule sync" handles origin URL of the form foo' '
234 cd relative-clone &&
235 git remote set-url origin foo &&
236 git submodule sync &&
238 cd submodule &&
239 #actual fails with: "cannot strip off url foo
240 test "$(git config remote.origin.url)" = "../submodule"
245 test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
247 cd relative-clone &&
248 git remote set-url origin foo/bar &&
249 git submodule sync &&
251 cd submodule &&
252 #actual foo/submodule
253 test "$(git config remote.origin.url)" = "../foo/submodule"
254 ) &&
256 cd submodule/sub-submodule &&
257 test "$(git config remote.origin.url)" != "../../foo/submodule"
262 test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
264 cd recursive-clone &&
265 git remote set-url origin foo/bar &&
266 git submodule sync --recursive &&
268 cd submodule &&
269 #actual foo/submodule
270 test "$(git config remote.origin.url)" = "../foo/submodule"
271 ) &&
273 cd submodule/sub-submodule &&
274 test "$(git config remote.origin.url)" = "../../foo/submodule"
279 test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
281 cd relative-clone &&
282 git remote set-url origin ./foo &&
283 git submodule sync &&
285 cd submodule &&
286 #actual ./submodule
287 test "$(git config remote.origin.url)" = "../submodule"
292 test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
294 cd relative-clone &&
295 git remote set-url origin ./foo/bar &&
296 git submodule sync &&
298 cd submodule &&
299 #actual ./foo/submodule
300 test "$(git config remote.origin.url)" = "../foo/submodule"
305 test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
307 cd relative-clone &&
308 git remote set-url origin ../foo &&
309 git submodule sync &&
311 cd submodule &&
312 #actual ../submodule
313 test "$(git config remote.origin.url)" = "../../submodule"
318 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
320 cd relative-clone &&
321 git remote set-url origin ../foo/bar &&
322 git submodule sync &&
324 cd submodule &&
325 #actual ../foo/submodule
326 test "$(git config remote.origin.url)" = "../../foo/submodule"
331 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
333 cd relative-clone &&
334 git remote set-url origin ../foo/bar &&
335 mkdir -p a/b/c &&
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 &&
347 cd a/b/c &&
348 #actual ../foo/bar/a/b/c
349 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
355 test_done