]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7403-submodule-sync.sh
rev-parse: add --prefix option
[thirdparty/git.git] / t / t7403-submodule-sync.sh
CommitLineData
52e8370b
DA
1#!/bin/sh
2#
3# Copyright (c) 2008 David Aguilar
4#
5
6test_description='git submodule sync
7
8These tests exercise the "git submodule sync" subcommand.
9'
10
11. ./test-lib.sh
12
13test_expect_success setup '
031129cb 14 echo file >file &&
52e8370b
DA
15 git add file &&
16 test_tick &&
0eb032d8 17 git commit -m upstream &&
52e8370b
DA
18 git clone . super &&
19 git clone super submodule &&
031129cb
JK
20 (
21 cd submodule &&
22 git submodule add ../submodule sub-submodule &&
23 test_tick &&
24 git commit -m "sub-submodule"
44fa0ef5 25 ) &&
031129cb
JK
26 (
27 cd super &&
28 git submodule add ../submodule submodule &&
29 test_tick &&
30 git commit -m "submodule"
52e8370b
DA
31 ) &&
32 git clone super super-clone &&
031129cb
JK
33 (
34 cd super-clone &&
35 git submodule update --init --recursive
36 ) &&
33f072f8 37 git clone super empty-clone &&
031129cb
JK
38 (
39 cd empty-clone &&
40 git submodule init
41 ) &&
49301c64
JS
42 git clone super top-only-clone &&
43 git clone super relative-clone &&
031129cb
JK
44 (
45 cd relative-clone &&
46 git submodule update --init --recursive
47 ) &&
44fa0ef5 48 git clone super recursive-clone &&
031129cb
JK
49 (
50 cd recursive-clone &&
51 git submodule update --init --recursive
52 )
52e8370b
DA
53'
54
55test_expect_success 'change submodule' '
031129cb
JK
56 (
57 cd submodule &&
58 echo second line >>file &&
59 test_tick &&
60 git commit -a -m "change submodule"
52e8370b
DA
61 )
62'
63
64test_expect_success 'change submodule url' '
031129cb
JK
65 (
66 cd super &&
67 cd submodule &&
68 git checkout master &&
69 git pull
52e8370b
DA
70 ) &&
71 mv submodule moved-submodule &&
031129cb
JK
72 (
73 cd moved-submodule &&
74 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
75 test_tick &&
76 git commit -a -m moved-sub-submodule
44fa0ef5 77 ) &&
031129cb
JK
78 (
79 cd super &&
80 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
81 test_tick &&
82 git commit -a -m moved-submodule
52e8370b
DA
83 )
84'
85
86test_expect_success '"git submodule sync" should update submodule URLs' '
031129cb
JK
87 (
88 cd super-clone &&
89 git pull --no-recurse-submodules &&
90 git submodule sync
52e8370b 91 ) &&
031129cb
JK
92 test -d "$(
93 cd super-clone/submodule &&
94 git config remote.origin.url
abc06822 95 )" &&
031129cb
JK
96 test ! -d "$(
97 cd super-clone/submodule/sub-submodule &&
98 git config remote.origin.url
44fa0ef5 99 )" &&
031129cb
JK
100 (
101 cd super-clone/submodule &&
102 git checkout master &&
103 git pull
0b9dca43 104 ) &&
031129cb
JK
105 (
106 cd super-clone &&
107 test -d "$(git config submodule.submodule.url)"
52e8370b
DA
108 )
109'
110
44fa0ef5 111test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
031129cb
JK
112 (
113 cd super-clone &&
114 (
115 cd submodule &&
116 git pull --no-recurse-submodules
117 ) &&
118 git submodule sync --recursive
44fa0ef5 119 ) &&
031129cb
JK
120 test -d "$(
121 cd super-clone/submodule &&
122 git config remote.origin.url
44fa0ef5 123 )" &&
031129cb
JK
124 test -d "$(
125 cd super-clone/submodule/sub-submodule &&
126 git config remote.origin.url
44fa0ef5 127 )" &&
031129cb
JK
128 (
129 cd super-clone/submodule/sub-submodule &&
130 git checkout master &&
131 git pull
44fa0ef5
PH
132 )
133'
134
ccee6086 135test_expect_success '"git submodule sync" should update known submodule URLs' '
031129cb
JK
136 (
137 cd empty-clone &&
138 git pull &&
139 git submodule sync &&
140 test -d "$(git config submodule.submodule.url)"
33f072f8
AK
141 )
142'
143
ccee6086 144test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
031129cb
JK
145 (
146 cd top-only-clone &&
147 git pull &&
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)"
ccee6086
JH
152 )
153'
154
758615e2 155test_expect_success '"git submodule sync" handles origin URL of the form foo' '
031129cb
JK
156 (
157 cd relative-clone &&
158 git remote set-url origin foo &&
159 git submodule sync &&
160 (
161 cd submodule &&
162 #actual fails with: "cannot strip off url foo
163 test "$(git config remote.origin.url)" = "../submodule"
164 )
49301c64
JS
165 )
166'
167
967b2c66 168test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
031129cb
JK
169 (
170 cd relative-clone &&
171 git remote set-url origin foo/bar &&
172 git submodule sync &&
173 (
174 cd submodule &&
175 #actual foo/submodule
176 test "$(git config remote.origin.url)" = "../foo/submodule"
a82af054 177 ) &&
031129cb
JK
178 (
179 cd submodule/sub-submodule &&
180 test "$(git config remote.origin.url)" != "../../foo/submodule"
181 )
44fa0ef5
PH
182 )
183'
184
185test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
031129cb
JK
186 (
187 cd recursive-clone &&
188 git remote set-url origin foo/bar &&
189 git submodule sync --recursive &&
190 (
191 cd submodule &&
192 #actual foo/submodule
193 test "$(git config remote.origin.url)" = "../foo/submodule"
a82af054 194 ) &&
031129cb
JK
195 (
196 cd submodule/sub-submodule &&
197 test "$(git config remote.origin.url)" = "../../foo/submodule"
198 )
49301c64
JS
199 )
200'
201
758615e2 202test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
031129cb
JK
203 (
204 cd relative-clone &&
205 git remote set-url origin ./foo &&
206 git submodule sync &&
207 (
208 cd submodule &&
209 #actual ./submodule
210 test "$(git config remote.origin.url)" = "../submodule"
211 )
49301c64
JS
212 )
213'
214
758615e2 215test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
031129cb
JK
216 (
217 cd relative-clone &&
218 git remote set-url origin ./foo/bar &&
219 git submodule sync &&
220 (
221 cd submodule &&
222 #actual ./foo/submodule
223 test "$(git config remote.origin.url)" = "../foo/submodule"
224 )
49301c64
JS
225 )
226'
227
967b2c66 228test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
031129cb
JK
229 (
230 cd relative-clone &&
231 git remote set-url origin ../foo &&
232 git submodule sync &&
233 (
234 cd submodule &&
235 #actual ../submodule
236 test "$(git config remote.origin.url)" = "../../submodule"
237 )
49301c64
JS
238 )
239'
240
967b2c66 241test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
031129cb
JK
242 (
243 cd relative-clone &&
244 git remote set-url origin ../foo/bar &&
245 git submodule sync &&
246 (
247 cd submodule &&
248 #actual ../foo/submodule
249 test "$(git config remote.origin.url)" = "../../foo/submodule"
250 )
49301c64
JS
251 )
252'
253
967b2c66 254test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
031129cb
JK
255 (
256 cd relative-clone &&
257 git remote set-url origin ../foo/bar &&
258 mkdir -p a/b/c &&
259 (
260 cd a/b/c &&
261 git init &&
262 >.gitignore &&
263 git add .gitignore &&
264 test_tick &&
265 git commit -m "initial commit"
266 ) &&
267 git submodule add ../bar/a/b/c ./a/b/c &&
268 git submodule sync &&
269 (
270 cd a/b/c &&
271 #actual ../foo/bar/a/b/c
272 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
273 )
49301c64
JS
274 )
275'
276
277
52e8370b 278test_done