3 test_description
='fetch --all works correctly'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
18 git commit
-m "Initial" &&
19 git checkout
-b side
&&
23 git commit
-m "Second" &&
30 git clone one
"$test_dir" &&
31 for r
in one two three
33 git
-C "$test_dir" remote add
"$r" "../$r" ||
return 1
37 test_expect_success setup
'
38 setup_repository one &&
39 setup_repository two &&
41 cd two && git branch another
43 git clone --mirror two three &&
47 cat > test
/expect
<< EOF
50 origin/HEAD -> origin/main
61 test_expect_success
'git fetch --all' '
63 git remote add one ../one &&
64 git remote add two ../two &&
65 git remote add three ../three &&
67 git branch -r > output &&
68 test_cmp expect output)
71 test_expect_success
'git fetch --all --no-write-fetch-head' '
73 rm -f .git/FETCH_HEAD &&
74 git fetch --all --no-write-fetch-head &&
75 test_path_is_missing .git/FETCH_HEAD)
78 test_expect_success
'git fetch --all should continue if a remote has errors' '
79 (git clone one test2 &&
81 git remote add bad ../non-existing &&
82 git remote add one ../one &&
83 git remote add two ../two &&
84 git remote add three ../three &&
85 test_must_fail git fetch --all &&
86 git branch -r > output &&
87 test_cmp ../test/expect output)
90 test_expect_success
'git fetch --all does not allow non-option arguments' '
92 test_must_fail git fetch --all origin &&
93 test_must_fail git fetch --all origin main)
97 origin/HEAD -> origin/main
105 test_expect_success
'git fetch --multiple (but only one remote)' '
106 (git clone one test3 &&
108 git remote add three ../three &&
109 git fetch --multiple three &&
110 git branch -r > output &&
111 test_cmp ../expect output)
122 test_expect_success
'git fetch --multiple (two remotes)' '
123 (git clone one test4 &&
125 git remote rm origin &&
126 git remote add one ../one &&
127 git remote add two ../two &&
128 GIT_TRACE=1 git fetch --multiple one two 2>trace &&
129 git branch -r > output &&
130 test_cmp ../expect output &&
131 grep "built-in: git maintenance" trace >gc &&
132 test_line_count = 1 gc
136 test_expect_success
'git fetch --multiple (bad remote names)' '
138 test_must_fail git fetch --multiple four)
142 test_expect_success
'git fetch --all (skipFetchAll)' '
144 for b in $(git branch -r)
146 git branch -r -d $b || exit 1
148 git remote add three ../three &&
149 git config remote.three.skipFetchAll true &&
151 git branch -r > output &&
152 test_cmp ../expect output)
166 test_expect_success
'git fetch --multiple (ignoring skipFetchAll)' '
168 for b in $(git branch -r)
170 git branch -r -d $b || exit 1
172 git fetch --multiple one two three &&
173 git branch -r > output &&
174 test_cmp ../expect output)
177 test_expect_success
'git fetch --all --no-tags' '
178 git clone one test5 &&
179 git clone test5 test6 &&
180 (cd test5 && git tag test-tag) &&
183 git fetch --all --no-tags &&
186 test_must_be_empty test6/output
189 test_expect_success
'git fetch --all --tags' '
190 echo test-tag >expect &&
191 git clone one test7 &&
192 git clone test7 test8 &&
195 test_commit test-tag &&
196 git reset --hard HEAD^
200 git fetch --all --tags &&
203 test_cmp expect test8/output
206 test_expect_success
'parallel' '
207 git remote add one ./bogus1 &&
208 git remote add two ./bogus2 &&
210 test_must_fail env GIT_TRACE="$PWD/trace" \
211 git fetch --jobs=2 --multiple one two 2>err &&
212 grep "preparing to run up to 2 tasks" trace &&
213 test_grep "could not fetch .one.*128" err &&
214 test_grep "could not fetch .two.*128" err
217 test_expect_success
'git fetch --multiple --jobs=0 picks a default' '
219 git fetch --multiple --jobs=0)
222 create_fetch_all_expect
() {
226 origin/HEAD -> origin
/main
238 for fetch_all
in true false
240 test_expect_success
"git fetch --all (works with fetch.all = $fetch_all)" '
241 test_dir="test_fetch_all_$fetch_all" &&
242 setup_test_clone "$test_dir" &&
245 git config fetch.all $fetch_all &&
247 create_fetch_all_expect &&
248 git branch -r >actual &&
249 test_cmp expect actual
254 test_expect_success
'git fetch (fetch all remotes with fetch.all = true)' '
255 setup_test_clone test9 &&
258 git config fetch.all true &&
260 git branch -r >actual &&
261 create_fetch_all_expect &&
262 test_cmp expect actual
266 create_fetch_one_expect
() {
270 origin/HEAD -> origin
/main
276 test_expect_success
'git fetch one (explicit remote overrides fetch.all)' '
277 setup_test_clone test10 &&
280 git config fetch.all true &&
282 create_fetch_one_expect &&
283 git branch -r >actual &&
284 test_cmp expect actual
288 create_fetch_two_as_origin_expect
() {
290 origin/HEAD -> origin
/main
297 test_expect_success
'git config fetch.all false (fetch only default remote)' '
298 setup_test_clone test11 &&
301 git config fetch.all false &&
302 git remote set-url origin ../two &&
304 create_fetch_two_as_origin_expect &&
305 git branch -r >actual &&
306 test_cmp expect actual
310 for fetch_all
in true false
312 test_expect_success
"git fetch --no-all (fetch only default remote with fetch.all = $fetch_all)" '
313 test_dir="test_no_all_fetch_all_$fetch_all" &&
314 setup_test_clone "$test_dir" &&
317 git config fetch.all $fetch_all &&
318 git remote set-url origin ../two &&
319 git fetch --no-all &&
320 create_fetch_two_as_origin_expect &&
321 git branch -r >actual &&
322 test_cmp expect actual
327 test_expect_success
'git fetch --no-all (fetch only default remote without fetch.all)' '
328 setup_test_clone test12 &&
331 git config --unset-all fetch.all || true &&
332 git remote set-url origin ../two &&
333 git fetch --no-all &&
334 create_fetch_two_as_origin_expect &&
335 git branch -r >actual &&
336 test_cmp expect actual
340 test_expect_success
'git fetch --all --no-all (fetch only default remote)' '
341 setup_test_clone test13 &&
344 git remote set-url origin ../two &&
345 git fetch --all --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 --no-all one (fetch only explicit remote)' '
353 setup_test_clone test14 &&
356 git fetch --no-all one &&
357 create_fetch_one_expect &&
358 git branch -r >actual &&
359 test_cmp expect actual
363 test_expect_success
'git fetch --no-all --all (fetch all remotes)' '
364 setup_test_clone test15 &&
367 git fetch --no-all --all &&
368 create_fetch_all_expect &&
369 git branch -r >actual &&
370 test_cmp expect actual