]>
Commit | Line | Data |
---|---|---|
9c4a036b BG |
1 | #!/bin/sh |
2 | ||
3 | test_description='fetch --all works correctly' | |
4 | ||
bc925ce3 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
9c4a036b BG |
8 | . ./test-lib.sh |
9 | ||
10 | setup_repository () { | |
11 | mkdir "$1" && ( | |
12 | cd "$1" && | |
13 | git init && | |
14 | >file && | |
15 | git add file && | |
16 | test_tick && | |
17 | git commit -m "Initial" && | |
18 | git checkout -b side && | |
19 | >elif && | |
20 | git add elif && | |
21 | test_tick && | |
22 | git commit -m "Second" && | |
bc925ce3 | 23 | git checkout main |
9c4a036b BG |
24 | ) |
25 | } | |
26 | ||
39487a15 TB |
27 | setup_test_clone () { |
28 | test_dir="$1" && | |
29 | git clone one "$test_dir" && | |
30 | for r in one two three | |
31 | do | |
32 | git -C "$test_dir" remote add "$r" "../$r" || return 1 | |
33 | done | |
34 | } | |
35 | ||
9c4a036b BG |
36 | test_expect_success setup ' |
37 | setup_repository one && | |
38 | setup_repository two && | |
39 | ( | |
40 | cd two && git branch another | |
41 | ) && | |
a48fcd83 | 42 | git clone --mirror two three && |
9c4a036b BG |
43 | git clone one test |
44 | ' | |
45 | ||
46 | cat > test/expect << EOF | |
bc925ce3 | 47 | one/main |
9c4a036b | 48 | one/side |
bc925ce3 JS |
49 | origin/HEAD -> origin/main |
50 | origin/main | |
9c4a036b BG |
51 | origin/side |
52 | three/another | |
bc925ce3 | 53 | three/main |
9c4a036b BG |
54 | three/side |
55 | two/another | |
bc925ce3 | 56 | two/main |
9c4a036b BG |
57 | two/side |
58 | EOF | |
59 | ||
60 | test_expect_success 'git fetch --all' ' | |
61 | (cd test && | |
62 | git remote add one ../one && | |
63 | git remote add two ../two && | |
64 | git remote add three ../three && | |
65 | git fetch --all && | |
66 | git branch -r > output && | |
67 | test_cmp expect output) | |
68 | ' | |
69 | ||
15184ae9 EW |
70 | test_expect_success 'git fetch --all --no-write-fetch-head' ' |
71 | (cd test && | |
72 | rm -f .git/FETCH_HEAD && | |
73 | git fetch --all --no-write-fetch-head && | |
74 | test_path_is_missing .git/FETCH_HEAD) | |
75 | ' | |
76 | ||
9c4a036b BG |
77 | test_expect_success 'git fetch --all should continue if a remote has errors' ' |
78 | (git clone one test2 && | |
79 | cd test2 && | |
80 | git remote add bad ../non-existing && | |
81 | git remote add one ../one && | |
82 | git remote add two ../two && | |
83 | git remote add three ../three && | |
84 | test_must_fail git fetch --all && | |
85 | git branch -r > output && | |
86 | test_cmp ../test/expect output) | |
87 | ' | |
88 | ||
89 | test_expect_success 'git fetch --all does not allow non-option arguments' ' | |
90 | (cd test && | |
91 | test_must_fail git fetch --all origin && | |
bc925ce3 | 92 | test_must_fail git fetch --all origin main) |
9c4a036b BG |
93 | ' |
94 | ||
16679e37 | 95 | cat > expect << EOF |
bc925ce3 JS |
96 | origin/HEAD -> origin/main |
97 | origin/main | |
16679e37 BG |
98 | origin/side |
99 | three/another | |
bc925ce3 | 100 | three/main |
16679e37 BG |
101 | three/side |
102 | EOF | |
103 | ||
104 | test_expect_success 'git fetch --multiple (but only one remote)' ' | |
105 | (git clone one test3 && | |
106 | cd test3 && | |
107 | git remote add three ../three && | |
108 | git fetch --multiple three && | |
109 | git branch -r > output && | |
110 | test_cmp ../expect output) | |
111 | ' | |
112 | ||
113 | cat > expect << EOF | |
bc925ce3 | 114 | one/main |
16679e37 | 115 | one/side |
16679e37 | 116 | two/another |
bc925ce3 | 117 | two/main |
16679e37 BG |
118 | two/side |
119 | EOF | |
120 | ||
121 | test_expect_success 'git fetch --multiple (two remotes)' ' | |
122 | (git clone one test4 && | |
123 | cd test4 && | |
7cc91a2f | 124 | git remote rm origin && |
16679e37 BG |
125 | git remote add one ../one && |
126 | git remote add two ../two && | |
c3d6b703 | 127 | GIT_TRACE=1 git fetch --multiple one two 2>trace && |
16679e37 | 128 | git branch -r > output && |
c3d6b703 | 129 | test_cmp ../expect output && |
916d0626 | 130 | grep "built-in: git maintenance" trace >gc && |
c3d6b703 NTND |
131 | test_line_count = 1 gc |
132 | ) | |
16679e37 BG |
133 | ' |
134 | ||
135 | test_expect_success 'git fetch --multiple (bad remote names)' ' | |
136 | (cd test4 && | |
137 | test_must_fail git fetch --multiple four) | |
138 | ' | |
139 | ||
7cc91a2f BG |
140 | |
141 | test_expect_success 'git fetch --all (skipFetchAll)' ' | |
142 | (cd test4 && | |
143 | for b in $(git branch -r) | |
144 | do | |
e6821d09 | 145 | git branch -r -d $b || exit 1 |
7cc91a2f BG |
146 | done && |
147 | git remote add three ../three && | |
148 | git config remote.three.skipFetchAll true && | |
149 | git fetch --all && | |
150 | git branch -r > output && | |
151 | test_cmp ../expect output) | |
152 | ' | |
153 | ||
154 | cat > expect << EOF | |
bc925ce3 | 155 | one/main |
7cc91a2f BG |
156 | one/side |
157 | three/another | |
bc925ce3 | 158 | three/main |
7cc91a2f BG |
159 | three/side |
160 | two/another | |
bc925ce3 | 161 | two/main |
7cc91a2f BG |
162 | two/side |
163 | EOF | |
164 | ||
165 | test_expect_success 'git fetch --multiple (ignoring skipFetchAll)' ' | |
166 | (cd test4 && | |
167 | for b in $(git branch -r) | |
168 | do | |
e6821d09 | 169 | git branch -r -d $b || exit 1 |
7cc91a2f BG |
170 | done && |
171 | git fetch --multiple one two three && | |
172 | git branch -r > output && | |
173 | test_cmp ../expect output) | |
174 | ' | |
175 | ||
85566460 | 176 | test_expect_success 'git fetch --all --no-tags' ' |
85566460 DJ |
177 | git clone one test5 && |
178 | git clone test5 test6 && | |
179 | (cd test5 && git tag test-tag) && | |
180 | ( | |
181 | cd test6 && | |
182 | git fetch --all --no-tags && | |
183 | git tag >output | |
184 | ) && | |
d3c6751b | 185 | test_must_be_empty test6/output |
85566460 DJ |
186 | ' |
187 | ||
188 | test_expect_success 'git fetch --all --tags' ' | |
189 | echo test-tag >expect && | |
190 | git clone one test7 && | |
191 | git clone test7 test8 && | |
192 | ( | |
193 | cd test7 && | |
194 | test_commit test-tag && | |
195 | git reset --hard HEAD^ | |
196 | ) && | |
197 | ( | |
198 | cd test8 && | |
199 | git fetch --all --tags && | |
200 | git tag >output | |
201 | ) && | |
202 | test_cmp expect test8/output | |
203 | ' | |
204 | ||
d54dea77 JS |
205 | test_expect_success 'parallel' ' |
206 | git remote add one ./bogus1 && | |
207 | git remote add two ./bogus2 && | |
208 | ||
209 | test_must_fail env GIT_TRACE="$PWD/trace" \ | |
210 | git fetch --jobs=2 --multiple one two 2>err && | |
211 | grep "preparing to run up to 2 tasks" trace && | |
6789275d JH |
212 | test_grep "could not fetch .one.*128" err && |
213 | test_grep "could not fetch .two.*128" err | |
d54dea77 JS |
214 | ' |
215 | ||
c39952b9 MA |
216 | test_expect_success 'git fetch --multiple --jobs=0 picks a default' ' |
217 | (cd test && | |
218 | git fetch --multiple --jobs=0) | |
219 | ' | |
220 | ||
39487a15 TB |
221 | create_fetch_all_expect () { |
222 | cat >expect <<-\EOF | |
223 | one/main | |
224 | one/side | |
225 | origin/HEAD -> origin/main | |
226 | origin/main | |
227 | origin/side | |
228 | three/another | |
229 | three/main | |
230 | three/side | |
231 | two/another | |
232 | two/main | |
233 | two/side | |
234 | EOF | |
235 | } | |
236 | ||
237 | for fetch_all in true false | |
238 | do | |
239 | test_expect_success "git fetch --all (works with fetch.all = $fetch_all)" ' | |
240 | test_dir="test_fetch_all_$fetch_all" && | |
241 | setup_test_clone "$test_dir" && | |
242 | ( | |
243 | cd "$test_dir" && | |
244 | git config fetch.all $fetch_all && | |
245 | git fetch --all && | |
246 | create_fetch_all_expect && | |
247 | git branch -r >actual && | |
248 | test_cmp expect actual | |
249 | ) | |
250 | ' | |
251 | done | |
252 | ||
253 | test_expect_success 'git fetch (fetch all remotes with fetch.all = true)' ' | |
254 | setup_test_clone test9 && | |
255 | ( | |
256 | cd test9 && | |
257 | git config fetch.all true && | |
258 | git fetch && | |
259 | git branch -r >actual && | |
260 | create_fetch_all_expect && | |
261 | test_cmp expect actual | |
262 | ) | |
263 | ' | |
264 | ||
265 | create_fetch_one_expect () { | |
266 | cat >expect <<-\EOF | |
267 | one/main | |
268 | one/side | |
269 | origin/HEAD -> origin/main | |
270 | origin/main | |
271 | origin/side | |
272 | EOF | |
273 | } | |
274 | ||
275 | test_expect_success 'git fetch one (explicit remote overrides fetch.all)' ' | |
276 | setup_test_clone test10 && | |
277 | ( | |
278 | cd test10 && | |
279 | git config fetch.all true && | |
280 | git fetch one && | |
281 | create_fetch_one_expect && | |
282 | git branch -r >actual && | |
283 | test_cmp expect actual | |
284 | ) | |
285 | ' | |
286 | ||
287 | create_fetch_two_as_origin_expect () { | |
288 | cat >expect <<-\EOF | |
289 | origin/HEAD -> origin/main | |
290 | origin/another | |
291 | origin/main | |
292 | origin/side | |
293 | EOF | |
294 | } | |
295 | ||
296 | test_expect_success 'git config fetch.all false (fetch only default remote)' ' | |
297 | setup_test_clone test11 && | |
298 | ( | |
299 | cd test11 && | |
300 | git config fetch.all false && | |
301 | git remote set-url origin ../two && | |
302 | git fetch && | |
303 | create_fetch_two_as_origin_expect && | |
304 | git branch -r >actual && | |
305 | test_cmp expect actual | |
306 | ) | |
307 | ' | |
308 | ||
309 | for fetch_all in true false | |
310 | do | |
311 | test_expect_success "git fetch --no-all (fetch only default remote with fetch.all = $fetch_all)" ' | |
312 | test_dir="test_no_all_fetch_all_$fetch_all" && | |
313 | setup_test_clone "$test_dir" && | |
314 | ( | |
315 | cd "$test_dir" && | |
316 | git config fetch.all $fetch_all && | |
317 | git remote set-url origin ../two && | |
318 | git fetch --no-all && | |
319 | create_fetch_two_as_origin_expect && | |
320 | git branch -r >actual && | |
321 | test_cmp expect actual | |
322 | ) | |
323 | ' | |
324 | done | |
325 | ||
326 | test_expect_success 'git fetch --no-all (fetch only default remote without fetch.all)' ' | |
327 | setup_test_clone test12 && | |
328 | ( | |
329 | cd test12 && | |
330 | git config --unset-all fetch.all || true && | |
331 | git remote set-url origin ../two && | |
332 | git fetch --no-all && | |
333 | create_fetch_two_as_origin_expect && | |
334 | git branch -r >actual && | |
335 | test_cmp expect actual | |
336 | ) | |
337 | ' | |
338 | ||
339 | test_expect_success 'git fetch --all --no-all (fetch only default remote)' ' | |
340 | setup_test_clone test13 && | |
341 | ( | |
342 | cd test13 && | |
343 | git remote set-url origin ../two && | |
344 | git fetch --all --no-all && | |
345 | create_fetch_two_as_origin_expect && | |
346 | git branch -r >actual && | |
347 | test_cmp expect actual | |
348 | ) | |
349 | ' | |
350 | ||
351 | test_expect_success 'git fetch --no-all one (fetch only explicit remote)' ' | |
352 | setup_test_clone test14 && | |
353 | ( | |
354 | cd test14 && | |
355 | git fetch --no-all one && | |
356 | create_fetch_one_expect && | |
357 | git branch -r >actual && | |
358 | test_cmp expect actual | |
359 | ) | |
360 | ' | |
361 | ||
362 | test_expect_success 'git fetch --no-all --all (fetch all remotes)' ' | |
363 | setup_test_clone test15 && | |
364 | ( | |
365 | cd test15 && | |
366 | git fetch --no-all --all && | |
367 | create_fetch_all_expect && | |
368 | git branch -r >actual && | |
369 | test_cmp expect actual | |
370 | ) | |
371 | ' | |
372 | ||
9c4a036b | 373 | test_done |