bundle: use OPT_PASSTHRU_ARGV
[git/debian.git] / t / t7403-submodule-sync.sh
blobff09443a0a4b0a5a4fdf1e14adc7e5d964a14dd6
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_PASSES_SANITIZE_LEAK=true
15 . ./test-lib.sh
17 test_expect_success setup '
18 git config --global protocol.file.allow always &&
20 echo file >file &&
21 git add file &&
22 test_tick &&
23 git commit -m upstream &&
24 git clone . super &&
25 git clone super submodule &&
27 cd submodule &&
28 git submodule add ../submodule sub-submodule &&
29 test_tick &&
30 git commit -m "sub-submodule"
31 ) &&
33 cd super &&
34 git submodule add ../submodule submodule &&
35 test_tick &&
36 git commit -m "submodule"
37 ) &&
38 git clone super super-clone &&
40 cd super-clone &&
41 git submodule update --init --recursive
42 ) &&
43 git clone super empty-clone &&
45 cd empty-clone &&
46 git submodule init
47 ) &&
48 git clone super top-only-clone &&
49 git clone super relative-clone &&
51 cd relative-clone &&
52 git submodule update --init --recursive
53 ) &&
54 git clone super recursive-clone &&
56 cd recursive-clone &&
57 git submodule update --init --recursive
61 test_expect_success 'change submodule' '
63 cd submodule &&
64 echo second line >>file &&
65 test_tick &&
66 git commit -a -m "change submodule"
70 reset_submodule_urls () {
72 root=$(pwd) &&
73 cd super-clone/submodule &&
74 git config remote.origin.url "$root/submodule"
75 ) &&
77 root=$(pwd) &&
78 cd super-clone/submodule/sub-submodule &&
79 git config remote.origin.url "$root/submodule"
83 test_expect_success 'change submodule url' '
85 cd super &&
86 cd submodule &&
87 git checkout main &&
88 git pull
89 ) &&
90 mv submodule moved-submodule &&
92 cd moved-submodule &&
93 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
94 test_tick &&
95 git commit -a -m moved-sub-submodule
96 ) &&
98 cd super &&
99 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
100 test_tick &&
101 git commit -a -m moved-submodule
105 test_expect_success '"git submodule sync" should update submodule URLs' '
107 cd super-clone &&
108 git pull --no-recurse-submodules &&
109 git submodule sync
110 ) &&
111 test -d "$(
112 cd super-clone/submodule &&
113 git config remote.origin.url
114 )" &&
115 test ! -d "$(
116 cd super-clone/submodule/sub-submodule &&
117 git config remote.origin.url
118 )" &&
120 cd super-clone/submodule &&
121 git checkout main &&
122 git pull
123 ) &&
125 cd super-clone &&
126 test -d "$(git config submodule.submodule.url)"
130 test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
132 cd super-clone &&
134 cd submodule &&
135 git pull --no-recurse-submodules
136 ) &&
137 git submodule sync --recursive
138 ) &&
139 test -d "$(
140 cd super-clone/submodule &&
141 git config remote.origin.url
142 )" &&
143 test -d "$(
144 cd super-clone/submodule/sub-submodule &&
145 git config remote.origin.url
146 )" &&
148 cd super-clone/submodule/sub-submodule &&
149 git checkout main &&
150 git pull
154 test_expect_success 'reset submodule URLs' '
155 reset_submodule_urls super-clone
158 test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' '
160 cd super-clone &&
161 git pull --no-recurse-submodules &&
162 mkdir -p sub &&
163 cd sub &&
164 git submodule sync >../../output
165 ) &&
166 test_i18ngrep "\\.\\./submodule" output &&
167 test -d "$(
168 cd super-clone/submodule &&
169 git config remote.origin.url
170 )" &&
171 test ! -d "$(
172 cd super-clone/submodule/sub-submodule &&
173 git config remote.origin.url
174 )" &&
176 cd super-clone/submodule &&
177 git checkout main &&
178 git pull
179 ) &&
181 cd super-clone &&
182 test -d "$(git config submodule.submodule.url)"
186 test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
188 cd super-clone &&
190 cd submodule &&
191 git pull --no-recurse-submodules
192 ) &&
193 mkdir -p sub &&
194 cd sub &&
195 git submodule sync --recursive >../../output
196 ) &&
197 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
198 test -d "$(
199 cd super-clone/submodule &&
200 git config remote.origin.url
201 )" &&
202 test -d "$(
203 cd super-clone/submodule/sub-submodule &&
204 git config remote.origin.url
205 )" &&
207 cd super-clone/submodule/sub-submodule &&
208 git checkout main &&
209 git pull
213 test_expect_success '"git submodule sync" should update known submodule URLs' '
215 cd empty-clone &&
216 git pull &&
217 git submodule sync &&
218 test -d "$(git config submodule.submodule.url)"
222 test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
224 cd top-only-clone &&
225 git pull &&
226 git submodule sync &&
227 test -z "$(git config submodule.submodule.url)" &&
228 git submodule sync submodule &&
229 test -z "$(git config submodule.submodule.url)"
233 test_expect_success '"git submodule sync" handles origin URL of the form foo' '
235 cd relative-clone &&
236 git remote set-url origin foo &&
237 git submodule sync &&
239 cd submodule &&
240 #actual fails with: "cannot strip off url foo
241 test "$(git config remote.origin.url)" = "../submodule"
246 test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
248 cd relative-clone &&
249 git remote set-url origin foo/bar &&
250 git submodule sync &&
252 cd submodule &&
253 #actual foo/submodule
254 test "$(git config remote.origin.url)" = "../foo/submodule"
255 ) &&
257 cd submodule/sub-submodule &&
258 test "$(git config remote.origin.url)" != "../../foo/submodule"
263 test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
265 cd recursive-clone &&
266 git remote set-url origin foo/bar &&
267 git submodule sync --recursive &&
269 cd submodule &&
270 #actual foo/submodule
271 test "$(git config remote.origin.url)" = "../foo/submodule"
272 ) &&
274 cd submodule/sub-submodule &&
275 test "$(git config remote.origin.url)" = "../../foo/submodule"
280 test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
282 cd relative-clone &&
283 git remote set-url origin ./foo &&
284 git submodule sync &&
286 cd submodule &&
287 #actual ./submodule
288 test "$(git config remote.origin.url)" = "../submodule"
293 test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
295 cd relative-clone &&
296 git remote set-url origin ./foo/bar &&
297 git submodule sync &&
299 cd submodule &&
300 #actual ./foo/submodule
301 test "$(git config remote.origin.url)" = "../foo/submodule"
306 test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
308 cd relative-clone &&
309 git remote set-url origin ../foo &&
310 git submodule sync &&
312 cd submodule &&
313 #actual ../submodule
314 test "$(git config remote.origin.url)" = "../../submodule"
319 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
321 cd relative-clone &&
322 git remote set-url origin ../foo/bar &&
323 git submodule sync &&
325 cd submodule &&
326 #actual ../foo/submodule
327 test "$(git config remote.origin.url)" = "../../foo/submodule"
332 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
334 cd relative-clone &&
335 git remote set-url origin ../foo/bar &&
336 mkdir -p a/b/c &&
338 cd a/b/c &&
339 git init &&
340 >.gitignore &&
341 git add .gitignore &&
342 test_tick &&
343 git commit -m "initial commit"
344 ) &&
345 git submodule add ../bar/a/b/c ./a/b/c &&
346 git submodule sync &&
348 cd a/b/c &&
349 #actual ../foo/bar/a/b/c
350 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
356 test_done