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
'
17 git commit -m upstream &&
19 git clone super submodule &&
22 git submodule add ../submodule sub-submodule &&
24 git commit -m "sub-submodule"
28 git submodule add ../submodule submodule &&
30 git commit -m "submodule"
32 git clone super super-clone &&
35 git submodule update --init --recursive
37 git clone super empty-clone &&
42 git clone super top-only-clone &&
43 git clone super relative-clone &&
46 git submodule update --init --recursive
48 git clone super recursive-clone &&
51 git submodule update --init --recursive
55 test_expect_success
'change submodule' '
58 echo second line >>file &&
60 git commit -a -m "change submodule"
64 test_expect_success
'change submodule url' '
68 git checkout master &&
71 mv submodule moved-submodule &&
74 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
76 git commit -a -m moved-sub-submodule
80 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
82 git commit -a -m moved-submodule
86 test_expect_success
'"git submodule sync" should update submodule URLs' '
89 git pull --no-recurse-submodules &&
93 cd super-clone/submodule &&
94 git config remote.origin.url
97 cd super-clone/submodule/sub-submodule &&
98 git config remote.origin.url
101 cd super-clone/submodule &&
102 git checkout master &&
107 test -d "$(git config submodule.submodule.url)"
111 test_expect_success
'"git submodule sync --recursive" should update all submodule URLs' '
116 git pull --no-recurse-submodules
118 git submodule sync --recursive
121 cd super-clone/submodule &&
122 git config remote.origin.url
125 cd super-clone/submodule/sub-submodule &&
126 git config remote.origin.url
129 cd super-clone/submodule/sub-submodule &&
130 git checkout master &&
135 test_expect_success
'"git submodule sync" should update known submodule URLs' '
139 git submodule sync &&
140 test -d "$(git config submodule.submodule.url)"
144 test_expect_success
'"git submodule sync" should not vivify uninteresting submodule' '
148 git submodule sync &&
149 test -z "$(git config submodule.submodule.url)" &&
150 git submodule sync submodule &&
151 test -z "$(git config submodule.submodule.url)"
155 test_expect_success
'"git submodule sync" handles origin URL of the form foo' '
158 git remote set-url origin foo &&
159 git submodule sync &&
162 #actual fails with: "cannot strip off url foo
163 test "$(git config remote.origin.url)" = "../submodule"
168 test_expect_success
'"git submodule sync" handles origin URL of the form foo/bar' '
171 git remote set-url origin foo/bar &&
172 git submodule sync &&
175 #actual foo/submodule
176 test "$(git config remote.origin.url)" = "../foo/submodule"
179 cd submodule/sub-submodule &&
180 test "$(git config remote.origin.url)" != "../../foo/submodule"
185 test_expect_success
'"git submodule sync --recursive" propagates changes in origin' '
187 cd recursive-clone &&
188 git remote set-url origin foo/bar &&
189 git submodule sync --recursive &&
192 #actual foo/submodule
193 test "$(git config remote.origin.url)" = "../foo/submodule"
196 cd submodule/sub-submodule &&
197 test "$(git config remote.origin.url)" = "../../foo/submodule"
202 test_expect_success
'"git submodule sync" handles origin URL of the form ./foo' '
205 git remote set-url origin ./foo &&
206 git submodule sync &&
210 test "$(git config remote.origin.url)" = "../submodule"
215 test_expect_success
'"git submodule sync" handles origin URL of the form ./foo/bar' '
218 git remote set-url origin ./foo/bar &&
219 git submodule sync &&
222 #actual ./foo/submodule
223 test "$(git config remote.origin.url)" = "../foo/submodule"
228 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo' '
231 git remote set-url origin ../foo &&
232 git submodule sync &&
236 test "$(git config remote.origin.url)" = "../../submodule"
241 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo/bar' '
244 git remote set-url origin ../foo/bar &&
245 git submodule sync &&
248 #actual ../foo/submodule
249 test "$(git config remote.origin.url)" = "../../foo/submodule"
254 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
257 git remote set-url origin ../foo/bar &&
263 git add .gitignore &&
265 git commit -m "initial commit"
267 git submodule add ../bar/a/b/c ./a/b/c &&
268 git submodule sync &&
271 #actual ../foo/bar/a/b/c
272 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"