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
16 test_expect_success setup
'
17 git config --global protocol.file.allow always &&
22 git commit -m upstream &&
24 git clone super submodule &&
27 git submodule add ../submodule sub-submodule &&
29 git commit -m "sub-submodule"
33 git submodule add ../submodule submodule &&
35 git commit -m "submodule"
37 git clone super super-clone &&
40 git submodule update --init --recursive
42 git clone super empty-clone &&
47 git clone super top-only-clone &&
48 git clone super relative-clone &&
51 git submodule update --init --recursive
53 git clone super recursive-clone &&
56 git submodule update --init --recursive
60 test_expect_success
'change submodule' '
63 echo second line >>file &&
65 git commit -a -m "change submodule"
69 reset_submodule_urls
() {
72 cd super-clone
/submodule
&&
73 git config remote.origin.url
"$root/submodule"
77 cd super-clone
/submodule
/sub-submodule
&&
78 git config remote.origin.url
"$root/submodule"
82 test_expect_success
'change submodule url' '
89 mv submodule moved-submodule &&
92 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
94 git commit -a -m moved-sub-submodule
98 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
100 git commit -a -m moved-submodule
104 test_expect_success
'"git submodule sync" should update submodule URLs' '
107 git pull --no-recurse-submodules &&
111 cd super-clone/submodule &&
112 git config remote.origin.url
115 cd super-clone/submodule/sub-submodule &&
116 git config remote.origin.url
119 cd super-clone/submodule &&
125 test -d "$(git config submodule.submodule.url)"
129 test_expect_success
'"git submodule sync --recursive" should update all submodule URLs' '
134 git pull --no-recurse-submodules
136 git submodule sync --recursive
139 cd super-clone/submodule &&
140 git config remote.origin.url
143 cd super-clone/submodule/sub-submodule &&
144 git config remote.origin.url
147 cd super-clone/submodule/sub-submodule &&
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' '
160 git pull --no-recurse-submodules &&
163 git submodule sync >../../output
165 test_i18ngrep "\\.\\./submodule" output &&
167 cd super-clone/submodule &&
168 git config remote.origin.url
171 cd super-clone/submodule/sub-submodule &&
172 git config remote.origin.url
175 cd super-clone/submodule &&
181 test -d "$(git config submodule.submodule.url)"
185 test_expect_success
'"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
190 git pull --no-recurse-submodules
194 git submodule sync --recursive >../../output
196 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
198 cd super-clone/submodule &&
199 git config remote.origin.url
202 cd super-clone/submodule/sub-submodule &&
203 git config remote.origin.url
206 cd super-clone/submodule/sub-submodule &&
212 test_expect_success
'"git submodule sync" should update known submodule URLs' '
216 git submodule sync &&
217 test -d "$(git config submodule.submodule.url)"
221 test_expect_success
'"git submodule sync" should not vivify uninteresting submodule' '
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' '
235 git remote set-url origin foo &&
236 git submodule sync &&
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' '
248 git remote set-url origin foo/bar &&
249 git submodule sync &&
252 #actual foo/submodule
253 test "$(git config remote.origin.url)" = "../foo/submodule"
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 &&
269 #actual foo/submodule
270 test "$(git config remote.origin.url)" = "../foo/submodule"
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' '
282 git remote set-url origin ./foo &&
283 git submodule sync &&
287 test "$(git config remote.origin.url)" = "../submodule"
292 test_expect_success
'"git submodule sync" handles origin URL of the form ./foo/bar' '
295 git remote set-url origin ./foo/bar &&
296 git submodule sync &&
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' '
308 git remote set-url origin ../foo &&
309 git submodule sync &&
313 test "$(git config remote.origin.url)" = "../../submodule"
318 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo/bar' '
321 git remote set-url origin ../foo/bar &&
322 git submodule sync &&
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' '
334 git remote set-url origin ../foo/bar &&
340 git add .gitignore &&
342 git commit -m "initial commit"
344 git submodule add ../bar/a/b/c ./a/b/c &&
345 git submodule sync &&
348 #actual ../foo/bar/a/b/c
349 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"