3 # Copyright (c) 2008 David Aguilar
6 test_description
='git submodule sync
8 These tests exercise the "git submodule sync" subcommand.
13 test_expect_success setup
'
14 git config --global protocol.file.allow always &&
19 git commit -m upstream &&
21 git clone super submodule &&
24 git submodule add ../submodule sub-submodule &&
26 git commit -m "sub-submodule"
30 git submodule add ../submodule submodule &&
32 git commit -m "submodule"
34 git clone super super-clone &&
37 git submodule update --init --recursive
39 git clone super empty-clone &&
44 git clone super top-only-clone &&
45 git clone super relative-clone &&
48 git submodule update --init --recursive
50 git clone super recursive-clone &&
53 git submodule update --init --recursive
57 test_expect_success
'change submodule' '
60 echo second line >>file &&
62 git commit -a -m "change submodule"
66 reset_submodule_urls
() {
69 cd super-clone
/submodule
&&
70 git config remote.origin.url
"$root/submodule"
74 cd super-clone
/submodule
/sub-submodule
&&
75 git config remote.origin.url
"$root/submodule"
79 test_expect_success
'change submodule url' '
83 git checkout master &&
86 mv submodule moved-submodule &&
89 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
91 git commit -a -m moved-sub-submodule
95 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
97 git commit -a -m moved-submodule
101 test_expect_success
'"git submodule sync" should update submodule URLs' '
104 git pull --no-recurse-submodules &&
108 cd super-clone/submodule &&
109 git config remote.origin.url
112 cd super-clone/submodule/sub-submodule &&
113 git config remote.origin.url
116 cd super-clone/submodule &&
117 git checkout master &&
122 test -d "$(git config submodule.submodule.url)"
126 test_expect_success
'"git submodule sync --recursive" should update all submodule URLs' '
131 git pull --no-recurse-submodules
133 git submodule sync --recursive
136 cd super-clone/submodule &&
137 git config remote.origin.url
140 cd super-clone/submodule/sub-submodule &&
141 git config remote.origin.url
144 cd super-clone/submodule/sub-submodule &&
145 git checkout master &&
150 test_expect_success
'reset submodule URLs' '
151 reset_submodule_urls super-clone
154 test_expect_success
'"git submodule sync" should update submodule URLs - subdirectory' '
157 git pull --no-recurse-submodules &&
160 git submodule sync >../../output
162 test_i18ngrep "\\.\\./submodule" output &&
164 cd super-clone/submodule &&
165 git config remote.origin.url
168 cd super-clone/submodule/sub-submodule &&
169 git config remote.origin.url
172 cd super-clone/submodule &&
173 git checkout master &&
178 test -d "$(git config submodule.submodule.url)"
182 test_expect_success
'"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
187 git pull --no-recurse-submodules
191 git submodule sync --recursive >../../output
193 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
195 cd super-clone/submodule &&
196 git config remote.origin.url
199 cd super-clone/submodule/sub-submodule &&
200 git config remote.origin.url
203 cd super-clone/submodule/sub-submodule &&
204 git checkout master &&
209 test_expect_success
'"git submodule sync" should update known submodule URLs' '
213 git submodule sync &&
214 test -d "$(git config submodule.submodule.url)"
218 test_expect_success
'"git submodule sync" should not vivify uninteresting submodule' '
222 git submodule sync &&
223 test -z "$(git config submodule.submodule.url)" &&
224 git submodule sync submodule &&
225 test -z "$(git config submodule.submodule.url)"
229 test_expect_success
'"git submodule sync" handles origin URL of the form foo' '
232 git remote set-url origin foo &&
233 git submodule sync &&
236 #actual fails with: "cannot strip off url foo
237 test "$(git config remote.origin.url)" = "../submodule"
242 test_expect_success
'"git submodule sync" handles origin URL of the form foo/bar' '
245 git remote set-url origin foo/bar &&
246 git submodule sync &&
249 #actual foo/submodule
250 test "$(git config remote.origin.url)" = "../foo/submodule"
253 cd submodule/sub-submodule &&
254 test "$(git config remote.origin.url)" != "../../foo/submodule"
259 test_expect_success
'"git submodule sync --recursive" propagates changes in origin' '
261 cd recursive-clone &&
262 git remote set-url origin foo/bar &&
263 git submodule sync --recursive &&
266 #actual foo/submodule
267 test "$(git config remote.origin.url)" = "../foo/submodule"
270 cd submodule/sub-submodule &&
271 test "$(git config remote.origin.url)" = "../../foo/submodule"
276 test_expect_success
'"git submodule sync" handles origin URL of the form ./foo' '
279 git remote set-url origin ./foo &&
280 git submodule sync &&
284 test "$(git config remote.origin.url)" = "../submodule"
289 test_expect_success
'"git submodule sync" handles origin URL of the form ./foo/bar' '
292 git remote set-url origin ./foo/bar &&
293 git submodule sync &&
296 #actual ./foo/submodule
297 test "$(git config remote.origin.url)" = "../foo/submodule"
302 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo' '
305 git remote set-url origin ../foo &&
306 git submodule sync &&
310 test "$(git config remote.origin.url)" = "../../submodule"
315 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo/bar' '
318 git remote set-url origin ../foo/bar &&
319 git submodule sync &&
322 #actual ../foo/submodule
323 test "$(git config remote.origin.url)" = "../../foo/submodule"
328 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
331 git remote set-url origin ../foo/bar &&
337 git add .gitignore &&
339 git commit -m "initial commit"
341 git submodule add ../bar/a/b/c ./a/b/c &&
342 git submodule sync &&
345 #actual ../foo/bar/a/b/c
346 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"