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