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
=master
12 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
16 test_expect_success setup
'
20 git commit -m upstream &&
22 git clone super submodule &&
25 git submodule add ../submodule sub-submodule &&
27 git commit -m "sub-submodule"
31 git submodule add ../submodule submodule &&
33 git commit -m "submodule"
35 git clone super super-clone &&
38 git submodule update --init --recursive
40 git clone super empty-clone &&
45 git clone super top-only-clone &&
46 git clone super relative-clone &&
49 git submodule update --init --recursive
51 git clone super recursive-clone &&
54 git submodule update --init --recursive
58 test_expect_success
'change submodule' '
61 echo second line >>file &&
63 git commit -a -m "change submodule"
67 reset_submodule_urls
() {
70 cd super-clone
/submodule
&&
71 git config remote.origin.url
"$root/submodule"
75 cd super-clone
/submodule
/sub-submodule
&&
76 git config remote.origin.url
"$root/submodule"
80 test_expect_success
'change submodule url' '
84 git checkout master &&
87 mv submodule moved-submodule &&
90 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
92 git commit -a -m moved-sub-submodule
96 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
98 git commit -a -m moved-submodule
102 test_expect_success
'"git submodule sync" should update submodule URLs' '
105 git pull --no-recurse-submodules &&
109 cd super-clone/submodule &&
110 git config remote.origin.url
113 cd super-clone/submodule/sub-submodule &&
114 git config remote.origin.url
117 cd super-clone/submodule &&
118 git checkout master &&
123 test -d "$(git config submodule.submodule.url)"
127 test_expect_success
'"git submodule sync --recursive" should update all submodule URLs' '
132 git pull --no-recurse-submodules
134 git submodule sync --recursive
137 cd super-clone/submodule &&
138 git config remote.origin.url
141 cd super-clone/submodule/sub-submodule &&
142 git config remote.origin.url
145 cd super-clone/submodule/sub-submodule &&
146 git checkout master &&
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' '
158 git pull --no-recurse-submodules &&
161 git submodule sync >../../output
163 test_i18ngrep "\\.\\./submodule" output &&
165 cd super-clone/submodule &&
166 git config remote.origin.url
169 cd super-clone/submodule/sub-submodule &&
170 git config remote.origin.url
173 cd super-clone/submodule &&
174 git checkout master &&
179 test -d "$(git config submodule.submodule.url)"
183 test_expect_success
'"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
188 git pull --no-recurse-submodules
192 git submodule sync --recursive >../../output
194 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
196 cd super-clone/submodule &&
197 git config remote.origin.url
200 cd super-clone/submodule/sub-submodule &&
201 git config remote.origin.url
204 cd super-clone/submodule/sub-submodule &&
205 git checkout master &&
210 test_expect_success
'"git submodule sync" should update known submodule URLs' '
214 git submodule sync &&
215 test -d "$(git config submodule.submodule.url)"
219 test_expect_success
'"git submodule sync" should not vivify uninteresting submodule' '
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' '
233 git remote set-url origin foo &&
234 git submodule sync &&
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' '
246 git remote set-url origin foo/bar &&
247 git submodule sync &&
250 #actual foo/submodule
251 test "$(git config remote.origin.url)" = "../foo/submodule"
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 &&
267 #actual foo/submodule
268 test "$(git config remote.origin.url)" = "../foo/submodule"
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' '
280 git remote set-url origin ./foo &&
281 git submodule sync &&
285 test "$(git config remote.origin.url)" = "../submodule"
290 test_expect_success
'"git submodule sync" handles origin URL of the form ./foo/bar' '
293 git remote set-url origin ./foo/bar &&
294 git submodule sync &&
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' '
306 git remote set-url origin ../foo &&
307 git submodule sync &&
311 test "$(git config remote.origin.url)" = "../../submodule"
316 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo/bar' '
319 git remote set-url origin ../foo/bar &&
320 git submodule sync &&
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' '
332 git remote set-url origin ../foo/bar &&
338 git add .gitignore &&
340 git commit -m "initial commit"
342 git submodule add ../bar/a/b/c ./a/b/c &&
343 git submodule sync &&
346 #actual ../foo/bar/a/b/c
347 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"