3 test_description
='fetch --all works correctly'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
17 git commit
-m "Initial" &&
18 git checkout
-b side
&&
22 git commit
-m "Second" &&
29 git clone one
"$test_dir" &&
30 for r
in one two three
32 git
-C "$test_dir" remote add
"$r" "../$r" ||
return 1
36 test_expect_success setup
'
37 setup_repository one &&
38 setup_repository two &&
40 cd two && git branch another
42 git clone --mirror two three &&
46 cat > test
/expect
<< EOF
50 origin/HEAD -> origin/main
53 three/HEAD -> three/main
63 test_expect_success
'git fetch --all' '
65 git remote add one ../one &&
66 git remote add two ../two &&
67 git remote add three ../three &&
69 git branch -r > output &&
70 test_cmp expect output)
73 test_expect_success
'git fetch --all --no-write-fetch-head' '
75 rm -f .git/FETCH_HEAD &&
76 git fetch --all --no-write-fetch-head &&
77 test_path_is_missing .git/FETCH_HEAD)
80 test_expect_success
'git fetch --all should continue if a remote has errors' '
81 (git clone one 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)
92 test_expect_success
'git fetch --all does not allow non-option arguments' '
94 test_must_fail git fetch --all origin &&
95 test_must_fail git fetch --all origin main)
99 origin/HEAD -> origin/main
102 three/HEAD -> three/main
108 test_expect_success
'git fetch --multiple (but only one remote)' '
109 (git clone one test3 &&
111 git remote add three ../three &&
112 git fetch --multiple three &&
113 git branch -r > output &&
114 test_cmp ../expect output)
127 test_expect_success
'git fetch --multiple (two remotes)' '
128 (git clone one test4 &&
130 git remote rm origin &&
131 git remote add one ../one &&
132 git remote add two ../two &&
133 GIT_TRACE=1 git fetch --multiple one two 2>trace &&
134 git branch -r > output &&
135 test_cmp ../expect output &&
136 grep "built-in: git maintenance" trace >gc &&
137 test_line_count = 1 gc
141 test_expect_success
'git fetch --multiple (bad remote names)' '
143 test_must_fail git fetch --multiple four)
147 test_expect_success
'git fetch --all (skipFetchAll)' '
149 for b in $(git branch -r | grep -v HEAD)
151 git branch -r -d $b || exit 1
153 git remote add three ../three &&
154 git config remote.three.skipFetchAll true &&
156 git branch -r > output &&
157 test_cmp ../expect output)
164 three/HEAD -> three/main
174 test_expect_success
'git fetch --multiple (ignoring skipFetchAll)' '
176 for b in $(git branch -r | grep -v HEAD)
178 git branch -r -d $b || exit 1
180 git fetch --multiple one two three &&
181 git branch -r > output &&
182 test_cmp ../expect output)
185 test_expect_success
'git fetch --all --no-tags' '
186 git clone one test5 &&
187 git clone test5 test6 &&
188 (cd test5 && git tag test-tag) &&
191 git fetch --all --no-tags &&
194 test_must_be_empty test6/output
197 test_expect_success
'git fetch --all --tags' '
198 echo test-tag >expect &&
199 git clone one test7 &&
200 git clone test7 test8 &&
203 test_commit test-tag &&
204 git reset --hard HEAD^
208 git fetch --all --tags &&
211 test_cmp expect test8/output
214 test_expect_success
'parallel' '
215 git remote add one ./bogus1 &&
216 git remote add two ./bogus2 &&
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 &&
221 test_grep "could not fetch .one.*128" err &&
222 test_grep "could not fetch .two.*128" err
225 test_expect_success
'git fetch --multiple --jobs=0 picks a default' '
227 git fetch --multiple --jobs=0)
230 create_fetch_all_expect
() {
235 origin
/HEAD
-> origin
/main
238 three
/HEAD
-> three
/main
249 for fetch_all
in true false
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" &&
256 git config fetch.all $fetch_all &&
258 create_fetch_all_expect &&
259 git branch -r >actual &&
260 test_cmp expect actual
265 test_expect_success
'git fetch (fetch all remotes with fetch.all = true)' '
266 setup_test_clone test9 &&
269 git config fetch.all true &&
271 git branch -r >actual &&
272 create_fetch_all_expect &&
273 test_cmp expect actual
277 create_fetch_one_expect
() {
282 origin
/HEAD
-> origin
/main
288 test_expect_success
'git fetch one (explicit remote overrides fetch.all)' '
289 setup_test_clone test10 &&
292 git config fetch.all true &&
294 create_fetch_one_expect &&
295 git branch -r >actual &&
296 test_cmp expect actual
300 create_fetch_two_as_origin_expect
() {
302 origin/HEAD -> origin
/main
309 test_expect_success
'git config fetch.all false (fetch only default remote)' '
310 setup_test_clone test11 &&
313 git config fetch.all false &&
314 git remote set-url origin ../two &&
316 create_fetch_two_as_origin_expect &&
317 git branch -r >actual &&
318 test_cmp expect actual
322 for fetch_all
in true false
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" &&
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
339 test_expect_success
'git fetch --no-all (fetch only default remote without fetch.all)' '
340 setup_test_clone 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
352 test_expect_success
'git fetch --all --no-all (fetch only default remote)' '
353 setup_test_clone 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
364 test_expect_success
'git fetch --no-all one (fetch only explicit remote)' '
365 setup_test_clone test14 &&
368 git fetch --no-all one &&
369 create_fetch_one_expect &&
370 git branch -r >actual &&
371 test_cmp expect actual
375 test_expect_success
'git fetch --no-all --all (fetch all remotes)' '
376 setup_test_clone test15 &&
379 git fetch --no-all --all &&
380 create_fetch_all_expect &&
381 git branch -r >actual &&
382 test_cmp expect actual