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