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
17 test_expect_success setup
'
18 git config --global protocol.file.allow always &&
23 git commit -m upstream &&
25 git clone super submodule &&
28 git submodule add ../submodule sub-submodule &&
30 git commit -m "sub-submodule"
34 git submodule add ../submodule submodule &&
36 git commit -m "submodule"
38 git clone super super-clone &&
41 git submodule update --init --recursive
43 git clone super empty-clone &&
48 git clone super top-only-clone &&
49 git clone super relative-clone &&
52 git submodule update --init --recursive
54 git clone super recursive-clone &&
57 git submodule update --init --recursive
61 test_expect_success
'change submodule' '
64 echo second line >>file &&
66 git commit -a -m "change submodule"
70 reset_submodule_urls
() {
73 cd super-clone
/submodule
&&
74 git config remote.origin.url
"$root/submodule"
78 cd super-clone
/submodule
/sub-submodule
&&
79 git config remote.origin.url
"$root/submodule"
83 test_expect_success
'change submodule url' '
90 mv submodule moved-submodule &&
93 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
95 git commit -a -m moved-sub-submodule
99 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
101 git commit -a -m moved-submodule
105 test_expect_success
'"git submodule sync" should update submodule URLs' '
108 git pull --no-recurse-submodules &&
112 cd super-clone/submodule &&
113 git config remote.origin.url
116 cd super-clone/submodule/sub-submodule &&
117 git config remote.origin.url
120 cd super-clone/submodule &&
126 test -d "$(git config submodule.submodule.url)"
130 test_expect_success
'"git submodule sync --recursive" should update all submodule URLs' '
135 git pull --no-recurse-submodules
137 git submodule sync --recursive
140 cd super-clone/submodule &&
141 git config remote.origin.url
144 cd super-clone/submodule/sub-submodule &&
145 git config remote.origin.url
148 cd super-clone/submodule/sub-submodule &&
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' '
161 git pull --no-recurse-submodules &&
164 git submodule sync >../../output
166 test_i18ngrep "\\.\\./submodule" output &&
168 cd super-clone/submodule &&
169 git config remote.origin.url
172 cd super-clone/submodule/sub-submodule &&
173 git config remote.origin.url
176 cd super-clone/submodule &&
182 test -d "$(git config submodule.submodule.url)"
186 test_expect_success
'"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
191 git pull --no-recurse-submodules
195 git submodule sync --recursive >../../output
197 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
199 cd super-clone/submodule &&
200 git config remote.origin.url
203 cd super-clone/submodule/sub-submodule &&
204 git config remote.origin.url
207 cd super-clone/submodule/sub-submodule &&
213 test_expect_success
'"git submodule sync" should update known submodule URLs' '
217 git submodule sync &&
218 test -d "$(git config submodule.submodule.url)"
222 test_expect_success
'"git submodule sync" should not vivify uninteresting submodule' '
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' '
236 git remote set-url origin foo &&
237 git submodule sync &&
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' '
249 git remote set-url origin foo/bar &&
250 git submodule sync &&
253 #actual foo/submodule
254 test "$(git config remote.origin.url)" = "../foo/submodule"
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 &&
270 #actual foo/submodule
271 test "$(git config remote.origin.url)" = "../foo/submodule"
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' '
283 git remote set-url origin ./foo &&
284 git submodule sync &&
288 test "$(git config remote.origin.url)" = "../submodule"
293 test_expect_success
'"git submodule sync" handles origin URL of the form ./foo/bar' '
296 git remote set-url origin ./foo/bar &&
297 git submodule sync &&
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' '
309 git remote set-url origin ../foo &&
310 git submodule sync &&
314 test "$(git config remote.origin.url)" = "../../submodule"
319 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo/bar' '
322 git remote set-url origin ../foo/bar &&
323 git submodule sync &&
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' '
335 git remote set-url origin ../foo/bar &&
341 git add .gitignore &&
343 git commit -m "initial commit"
345 git submodule add ../bar/a/b/c ./a/b/c &&
346 git submodule sync &&
349 #actual ../foo/bar/a/b/c
350 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"