summaryrefslogtreecommitdiffstats
path: root/t/t5514-fetch-multiple.sh
blob: 25772c85c5a9a89bf247cfa41cf9d8b127572cd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/bin/sh

test_description='fetch --all works correctly'

GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME

. ./test-lib.sh

setup_repository () {
	mkdir "$1" && (
	cd "$1" &&
	git init &&
	>file &&
	git add file &&
	test_tick &&
	git commit -m "Initial" &&
	git checkout -b side &&
	>elif &&
	git add elif &&
	test_tick &&
	git commit -m "Second" &&
	git checkout main
	)
}

setup_test_clone () {
	test_dir="$1" &&
	git clone one "$test_dir" &&
	for r in one two three
	do
		git -C "$test_dir" remote add "$r" "../$r" || return 1
	done
}

test_expect_success setup '
	setup_repository one &&
	setup_repository two &&
	(
		cd two && git branch another
	) &&
	git clone --mirror two three &&
	git clone one test
'

cat > test/expect << EOF
  one/main
  one/side
  origin/HEAD -> origin/main
  origin/main
  origin/side
  three/another
  three/main
  three/side
  two/another
  two/main
  two/side
EOF

test_expect_success 'git fetch --all' '
	(cd test &&
	 git remote add one ../one &&
	 git remote add two ../two &&
	 git remote add three ../three &&
	 git fetch --all &&
	 git branch -r > output &&
	 test_cmp expect output)
'

test_expect_success 'git fetch --all --no-write-fetch-head' '
	(cd test &&
	rm -f .git/FETCH_HEAD &&
	git fetch --all --no-write-fetch-head &&
	test_path_is_missing .git/FETCH_HEAD)
'

test_expect_success 'git fetch --all should continue if a remote has errors' '
	(git clone one test2 &&
	 cd test2 &&
	 git remote add bad ../non-existing &&
	 git remote add one ../one &&
	 git remote add two ../two &&
	 git remote add three ../three &&
	 test_must_fail git fetch --all &&
	 git branch -r > output &&
	 test_cmp ../test/expect output)
'

test_expect_success 'git fetch --all does not allow non-option arguments' '
	(cd test &&
	 test_must_fail git fetch --all origin &&
	 test_must_fail git fetch --all origin main)
'

cat > expect << EOF
  origin/HEAD -> origin/main
  origin/main
  origin/side
  three/another
  three/main
  three/side
EOF

test_expect_success 'git fetch --multiple (but only one remote)' '
	(git clone one test3 &&
	 cd test3 &&
	 git remote add three ../three &&
	 git fetch --multiple three &&
	 git branch -r > output &&
	 test_cmp ../expect output)
'

cat > expect << EOF
  one/main
  one/side
  two/another
  two/main
  two/side
EOF

test_expect_success 'git fetch --multiple (two remotes)' '
	(git clone one test4 &&
	 cd test4 &&
	 git remote rm origin &&
	 git remote add one ../one &&
	 git remote add two ../two &&
	 GIT_TRACE=1 git fetch --multiple one two 2>trace &&
	 git branch -r > output &&
	 test_cmp ../expect output &&
	 grep "built-in: git maintenance" trace >gc &&
	 test_line_count = 1 gc
	)
'

test_expect_success 'git fetch --multiple (bad remote names)' '
	(cd test4 &&
	 test_must_fail git fetch --multiple four)
'


test_expect_success 'git fetch --all (skipFetchAll)' '
	(cd test4 &&
	 for b in $(git branch -r)
	 do
		git branch -r -d $b || exit 1
	 done &&
	 git remote add three ../three &&
	 git config remote.three.skipFetchAll true &&
	 git fetch --all &&
	 git branch -r > output &&
	 test_cmp ../expect output)
'

cat > expect << EOF
  one/main
  one/side
  three/another
  three/main
  three/side
  two/another
  two/main
  two/side
EOF

test_expect_success 'git fetch --multiple (ignoring skipFetchAll)' '
	(cd test4 &&
	 for b in $(git branch -r)
	 do
		git branch -r -d $b || exit 1
	 done &&
	 git fetch --multiple one two three &&
	 git branch -r > output &&
	 test_cmp ../expect output)
'

test_expect_success 'git fetch --all --no-tags' '
	git clone one test5 &&
	git clone test5 test6 &&
	(cd test5 && git tag test-tag) &&
	(
		cd test6 &&
		git fetch --all --no-tags &&
		git tag >output
	) &&
	test_must_be_empty test6/output
'

test_expect_success 'git fetch --all --tags' '
	echo test-tag >expect &&
	git clone one test7 &&
	git clone test7 test8 &&
	(
		cd test7 &&
		test_commit test-tag &&
		git reset --hard HEAD^
	) &&
	(
		cd test8 &&
		git fetch --all --tags &&
		git tag >output
	) &&
	test_cmp expect test8/output
'

test_expect_success 'parallel' '
	git remote add one ./bogus1 &&
	git remote add two ./bogus2 &&

	test_must_fail env GIT_TRACE="$PWD/trace" \
		git fetch --jobs=2 --multiple one two 2>err &&
	grep "preparing to run up to 2 tasks" trace &&
	test_grep "could not fetch .one.*128" err &&
	test_grep "could not fetch .two.*128" err
'

test_expect_success 'git fetch --multiple --jobs=0 picks a default' '
	(cd test &&
	 git fetch --multiple --jobs=0)
'

create_fetch_all_expect () {
	cat >expect <<-\EOF
	  one/main
	  one/side
	  origin/HEAD -> origin/main
	  origin/main
	  origin/side
	  three/another
	  three/main
	  three/side
	  two/another
	  two/main
	  two/side
	EOF
}

for fetch_all in true false
do
	test_expect_success "git fetch --all (works with fetch.all = $fetch_all)" '
		test_dir="test_fetch_all_$fetch_all" &&
		setup_test_clone "$test_dir" &&
		(
			cd "$test_dir" &&
			git config fetch.all $fetch_all &&
			git fetch --all &&
			create_fetch_all_expect &&
			git branch -r >actual &&
			test_cmp expect actual
		)
	'
done

test_expect_success 'git fetch (fetch all remotes with fetch.all = true)' '
	setup_test_clone test9 &&
	(
		cd test9 &&
		git config fetch.all true &&
		git fetch &&
		git branch -r >actual &&
		create_fetch_all_expect &&
		test_cmp expect actual
	)
'

create_fetch_one_expect () {
	cat >expect <<-\EOF
	  one/main
	  one/side
	  origin/HEAD -> origin/main
	  origin/main
	  origin/side
	EOF
}

test_expect_success 'git fetch one (explicit remote overrides fetch.all)' '
	setup_test_clone test10 &&
	(
		cd test10 &&
		git config fetch.all true &&
		git fetch one &&
		create_fetch_one_expect &&
		git branch -r >actual &&
		test_cmp expect actual
	)
'

create_fetch_two_as_origin_expect () {
	cat >expect <<-\EOF
	  origin/HEAD -> origin/main
	  origin/another
	  origin/main
	  origin/side
	EOF
}

test_expect_success 'git config fetch.all false (fetch only default remote)' '
	setup_test_clone test11 &&
	(
		cd test11 &&
		git config fetch.all false &&
		git remote set-url origin ../two &&
		git fetch &&
		create_fetch_two_as_origin_expect &&
		git branch -r >actual &&
		test_cmp expect actual
	)
'

for fetch_all in true false
do
	test_expect_success "git fetch --no-all (fetch only default remote with fetch.all = $fetch_all)" '
		test_dir="test_no_all_fetch_all_$fetch_all" &&
		setup_test_clone "$test_dir" &&
		(
			cd "$test_dir" &&
			git config fetch.all $fetch_all &&
			git remote set-url origin ../two &&
			git fetch --no-all &&
			create_fetch_two_as_origin_expect &&
			git branch -r >actual &&
			test_cmp expect actual
		)
	'
done

test_expect_success 'git fetch --no-all (fetch only default remote without fetch.all)' '
	setup_test_clone test12 &&
	(
		cd test12 &&
		git config --unset-all fetch.all || true &&
		git remote set-url origin ../two &&
		git fetch --no-all &&
		create_fetch_two_as_origin_expect &&
		git branch -r >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'git fetch --all --no-all (fetch only default remote)' '
	setup_test_clone test13 &&
	(
		cd test13 &&
		git remote set-url origin ../two &&
		git fetch --all --no-all &&
		create_fetch_two_as_origin_expect &&
		git branch -r >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'git fetch --no-all one (fetch only explicit remote)' '
	setup_test_clone test14 &&
	(
		cd test14 &&
		git fetch --no-all one &&
		create_fetch_one_expect &&
		git branch -r >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'git fetch --no-all --all (fetch all remotes)' '
	setup_test_clone test15 &&
	(
		cd test15 &&
		git fetch --no-all --all &&
		create_fetch_all_expect &&
		git branch -r >actual &&
		test_cmp expect actual
	)
'

test_done