The eleventh batch
[git/gitster.git] / t / t5514-fetch-multiple.sh
blob579872c258db40acd35acd9db027eeb123702e00
1 #!/bin/sh
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
9 . ./test-lib.sh
11 setup_repository () {
12 mkdir "$1" && (
13 cd "$1" &&
14 git init &&
15 >file &&
16 git add file &&
17 test_tick &&
18 git commit -m "Initial" &&
19 git checkout -b side &&
20 >elif &&
21 git add elif &&
22 test_tick &&
23 git commit -m "Second" &&
24 git checkout main
28 setup_test_clone () {
29 test_dir="$1" &&
30 git clone one "$test_dir" &&
31 for r in one two three
33 git -C "$test_dir" remote add "$r" "../$r" || return 1
34 done
37 test_expect_success setup '
38 setup_repository one &&
39 setup_repository two &&
41 cd two && git branch another
42 ) &&
43 git clone --mirror two three &&
44 git clone one test
47 cat > test/expect << EOF
48 one/main
49 one/side
50 origin/HEAD -> origin/main
51 origin/main
52 origin/side
53 three/another
54 three/main
55 three/side
56 two/another
57 two/main
58 two/side
59 EOF
61 test_expect_success 'git fetch --all' '
62 (cd test &&
63 git remote add one ../one &&
64 git remote add two ../two &&
65 git remote add three ../three &&
66 git fetch --all &&
67 git branch -r > output &&
68 test_cmp expect output)
71 test_expect_success 'git fetch --all --no-write-fetch-head' '
72 (cd test &&
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 &&
80 cd 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' '
91 (cd test &&
92 test_must_fail git fetch --all origin &&
93 test_must_fail git fetch --all origin main)
96 cat > expect << EOF
97 origin/HEAD -> origin/main
98 origin/main
99 origin/side
100 three/another
101 three/main
102 three/side
105 test_expect_success 'git fetch --multiple (but only one remote)' '
106 (git clone one test3 &&
107 cd test3 &&
108 git remote add three ../three &&
109 git fetch --multiple three &&
110 git branch -r > output &&
111 test_cmp ../expect output)
114 cat > expect << EOF
115 one/main
116 one/side
117 two/another
118 two/main
119 two/side
122 test_expect_success 'git fetch --multiple (two remotes)' '
123 (git clone one test4 &&
124 cd 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)' '
137 (cd test4 &&
138 test_must_fail git fetch --multiple four)
142 test_expect_success 'git fetch --all (skipFetchAll)' '
143 (cd test4 &&
144 for b in $(git branch -r)
146 git branch -r -d $b || exit 1
147 done &&
148 git remote add three ../three &&
149 git config remote.three.skipFetchAll true &&
150 git fetch --all &&
151 git branch -r > output &&
152 test_cmp ../expect output)
155 cat > expect << EOF
156 one/main
157 one/side
158 three/another
159 three/main
160 three/side
161 two/another
162 two/main
163 two/side
166 test_expect_success 'git fetch --multiple (ignoring skipFetchAll)' '
167 (cd test4 &&
168 for b in $(git branch -r)
170 git branch -r -d $b || exit 1
171 done &&
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) &&
182 cd test6 &&
183 git fetch --all --no-tags &&
184 git tag >output
185 ) &&
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 &&
194 cd test7 &&
195 test_commit test-tag &&
196 git reset --hard HEAD^
197 ) &&
199 cd test8 &&
200 git fetch --all --tags &&
201 git tag >output
202 ) &&
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' '
218 (cd test &&
219 git fetch --multiple --jobs=0)
222 create_fetch_all_expect () {
223 cat >expect <<-\EOF
224 one/main
225 one/side
226 origin/HEAD -> origin/main
227 origin/main
228 origin/side
229 three/another
230 three/main
231 three/side
232 two/another
233 two/main
234 two/side
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" &&
244 cd "$test_dir" &&
245 git config fetch.all $fetch_all &&
246 git fetch --all &&
247 create_fetch_all_expect &&
248 git branch -r >actual &&
249 test_cmp expect actual
252 done
254 test_expect_success 'git fetch (fetch all remotes with fetch.all = true)' '
255 setup_test_clone test9 &&
257 cd test9 &&
258 git config fetch.all true &&
259 git fetch &&
260 git branch -r >actual &&
261 create_fetch_all_expect &&
262 test_cmp expect actual
266 create_fetch_one_expect () {
267 cat >expect <<-\EOF
268 one/main
269 one/side
270 origin/HEAD -> origin/main
271 origin/main
272 origin/side
276 test_expect_success 'git fetch one (explicit remote overrides fetch.all)' '
277 setup_test_clone test10 &&
279 cd test10 &&
280 git config fetch.all true &&
281 git fetch one &&
282 create_fetch_one_expect &&
283 git branch -r >actual &&
284 test_cmp expect actual
288 create_fetch_two_as_origin_expect () {
289 cat >expect <<-\EOF
290 origin/HEAD -> origin/main
291 origin/another
292 origin/main
293 origin/side
297 test_expect_success 'git config fetch.all false (fetch only default remote)' '
298 setup_test_clone test11 &&
300 cd test11 &&
301 git config fetch.all false &&
302 git remote set-url origin ../two &&
303 git fetch &&
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" &&
316 cd "$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
325 done
327 test_expect_success 'git fetch --no-all (fetch only default remote without fetch.all)' '
328 setup_test_clone test12 &&
330 cd 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 &&
343 cd 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 &&
355 cd 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 &&
366 cd test15 &&
367 git fetch --no-all --all &&
368 create_fetch_all_expect &&
369 git branch -r >actual &&
370 test_cmp expect actual
374 test_done