git-bundle.txt: add missing words and punctuation
[git/debian.git] / t / t7403-submodule-sync.sh
blob7d2ac3322b50cc580d2212f40658cdda66204a16
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 echo file >file &&
18 git add file &&
19 test_tick &&
20 git commit -m upstream &&
21 git clone . super &&
22 git clone super submodule &&
24 cd submodule &&
25 git submodule add ../submodule sub-submodule &&
26 test_tick &&
27 git commit -m "sub-submodule"
28 ) &&
30 cd super &&
31 git submodule add ../submodule submodule &&
32 test_tick &&
33 git commit -m "submodule"
34 ) &&
35 git clone super super-clone &&
37 cd super-clone &&
38 git submodule update --init --recursive
39 ) &&
40 git clone super empty-clone &&
42 cd empty-clone &&
43 git submodule init
44 ) &&
45 git clone super top-only-clone &&
46 git clone super relative-clone &&
48 cd relative-clone &&
49 git submodule update --init --recursive
50 ) &&
51 git clone super recursive-clone &&
53 cd recursive-clone &&
54 git submodule update --init --recursive
58 test_expect_success 'change submodule' '
60 cd submodule &&
61 echo second line >>file &&
62 test_tick &&
63 git commit -a -m "change submodule"
67 reset_submodule_urls () {
69 root=$(pwd) &&
70 cd super-clone/submodule &&
71 git config remote.origin.url "$root/submodule"
72 ) &&
74 root=$(pwd) &&
75 cd super-clone/submodule/sub-submodule &&
76 git config remote.origin.url "$root/submodule"
80 test_expect_success 'change submodule url' '
82 cd super &&
83 cd submodule &&
84 git checkout main &&
85 git pull
86 ) &&
87 mv submodule moved-submodule &&
89 cd moved-submodule &&
90 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
91 test_tick &&
92 git commit -a -m moved-sub-submodule
93 ) &&
95 cd super &&
96 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
97 test_tick &&
98 git commit -a -m moved-submodule
102 test_expect_success '"git submodule sync" should update submodule URLs' '
104 cd super-clone &&
105 git pull --no-recurse-submodules &&
106 git submodule sync
107 ) &&
108 test -d "$(
109 cd super-clone/submodule &&
110 git config remote.origin.url
111 )" &&
112 test ! -d "$(
113 cd super-clone/submodule/sub-submodule &&
114 git config remote.origin.url
115 )" &&
117 cd super-clone/submodule &&
118 git checkout main &&
119 git pull
120 ) &&
122 cd super-clone &&
123 test -d "$(git config submodule.submodule.url)"
127 test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
129 cd super-clone &&
131 cd submodule &&
132 git pull --no-recurse-submodules
133 ) &&
134 git submodule sync --recursive
135 ) &&
136 test -d "$(
137 cd super-clone/submodule &&
138 git config remote.origin.url
139 )" &&
140 test -d "$(
141 cd super-clone/submodule/sub-submodule &&
142 git config remote.origin.url
143 )" &&
145 cd super-clone/submodule/sub-submodule &&
146 git checkout main &&
147 git pull
151 test_expect_success 'reset submodule URLs' '
152 reset_submodule_urls super-clone
155 test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' '
157 cd super-clone &&
158 git pull --no-recurse-submodules &&
159 mkdir -p sub &&
160 cd sub &&
161 git submodule sync >../../output
162 ) &&
163 test_i18ngrep "\\.\\./submodule" output &&
164 test -d "$(
165 cd super-clone/submodule &&
166 git config remote.origin.url
167 )" &&
168 test ! -d "$(
169 cd super-clone/submodule/sub-submodule &&
170 git config remote.origin.url
171 )" &&
173 cd super-clone/submodule &&
174 git checkout main &&
175 git pull
176 ) &&
178 cd super-clone &&
179 test -d "$(git config submodule.submodule.url)"
183 test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
185 cd super-clone &&
187 cd submodule &&
188 git pull --no-recurse-submodules
189 ) &&
190 mkdir -p sub &&
191 cd sub &&
192 git submodule sync --recursive >../../output
193 ) &&
194 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
195 test -d "$(
196 cd super-clone/submodule &&
197 git config remote.origin.url
198 )" &&
199 test -d "$(
200 cd super-clone/submodule/sub-submodule &&
201 git config remote.origin.url
202 )" &&
204 cd super-clone/submodule/sub-submodule &&
205 git checkout main &&
206 git pull
210 test_expect_success '"git submodule sync" should update known submodule URLs' '
212 cd empty-clone &&
213 git pull &&
214 git submodule sync &&
215 test -d "$(git config submodule.submodule.url)"
219 test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
221 cd top-only-clone &&
222 git pull &&
223 git submodule sync &&
224 test -z "$(git config submodule.submodule.url)" &&
225 git submodule sync submodule &&
226 test -z "$(git config submodule.submodule.url)"
230 test_expect_success '"git submodule sync" handles origin URL of the form foo' '
232 cd relative-clone &&
233 git remote set-url origin foo &&
234 git submodule sync &&
236 cd submodule &&
237 #actual fails with: "cannot strip off url foo
238 test "$(git config remote.origin.url)" = "../submodule"
243 test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
245 cd relative-clone &&
246 git remote set-url origin foo/bar &&
247 git submodule sync &&
249 cd submodule &&
250 #actual foo/submodule
251 test "$(git config remote.origin.url)" = "../foo/submodule"
252 ) &&
254 cd submodule/sub-submodule &&
255 test "$(git config remote.origin.url)" != "../../foo/submodule"
260 test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
262 cd recursive-clone &&
263 git remote set-url origin foo/bar &&
264 git submodule sync --recursive &&
266 cd submodule &&
267 #actual foo/submodule
268 test "$(git config remote.origin.url)" = "../foo/submodule"
269 ) &&
271 cd submodule/sub-submodule &&
272 test "$(git config remote.origin.url)" = "../../foo/submodule"
277 test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
279 cd relative-clone &&
280 git remote set-url origin ./foo &&
281 git submodule sync &&
283 cd submodule &&
284 #actual ./submodule
285 test "$(git config remote.origin.url)" = "../submodule"
290 test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
292 cd relative-clone &&
293 git remote set-url origin ./foo/bar &&
294 git submodule sync &&
296 cd submodule &&
297 #actual ./foo/submodule
298 test "$(git config remote.origin.url)" = "../foo/submodule"
303 test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
305 cd relative-clone &&
306 git remote set-url origin ../foo &&
307 git submodule sync &&
309 cd submodule &&
310 #actual ../submodule
311 test "$(git config remote.origin.url)" = "../../submodule"
316 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
318 cd relative-clone &&
319 git remote set-url origin ../foo/bar &&
320 git submodule sync &&
322 cd submodule &&
323 #actual ../foo/submodule
324 test "$(git config remote.origin.url)" = "../../foo/submodule"
329 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
331 cd relative-clone &&
332 git remote set-url origin ../foo/bar &&
333 mkdir -p a/b/c &&
335 cd a/b/c &&
336 git init &&
337 >.gitignore &&
338 git add .gitignore &&
339 test_tick &&
340 git commit -m "initial commit"
341 ) &&
342 git submodule add ../bar/a/b/c ./a/b/c &&
343 git submodule sync &&
345 cd a/b/c &&
346 #actual ../foo/bar/a/b/c
347 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
353 test_done