]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5514-fetch-multiple.sh
submodule-config.c: strengthen URL fsck check
[thirdparty/git.git] / t / t5514-fetch-multiple.sh
1 #!/bin/sh
2
3 test_description='fetch --all works correctly'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
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" &&
23 git checkout main
24 )
25 }
26
27 test_expect_success setup '
28 setup_repository one &&
29 setup_repository two &&
30 (
31 cd two && git branch another
32 ) &&
33 git clone --mirror two three &&
34 git clone one test
35 '
36
37 cat > test/expect << EOF
38 one/main
39 one/side
40 origin/HEAD -> origin/main
41 origin/main
42 origin/side
43 three/another
44 three/main
45 three/side
46 two/another
47 two/main
48 two/side
49 EOF
50
51 test_expect_success 'git fetch --all' '
52 (cd test &&
53 git remote add one ../one &&
54 git remote add two ../two &&
55 git remote add three ../three &&
56 git fetch --all &&
57 git branch -r > output &&
58 test_cmp expect output)
59 '
60
61 test_expect_success 'git fetch --all --no-write-fetch-head' '
62 (cd test &&
63 rm -f .git/FETCH_HEAD &&
64 git fetch --all --no-write-fetch-head &&
65 test_path_is_missing .git/FETCH_HEAD)
66 '
67
68 test_expect_success 'git fetch --all should continue if a remote has errors' '
69 (git clone one test2 &&
70 cd test2 &&
71 git remote add bad ../non-existing &&
72 git remote add one ../one &&
73 git remote add two ../two &&
74 git remote add three ../three &&
75 test_must_fail git fetch --all &&
76 git branch -r > output &&
77 test_cmp ../test/expect output)
78 '
79
80 test_expect_success 'git fetch --all does not allow non-option arguments' '
81 (cd test &&
82 test_must_fail git fetch --all origin &&
83 test_must_fail git fetch --all origin main)
84 '
85
86 cat > expect << EOF
87 origin/HEAD -> origin/main
88 origin/main
89 origin/side
90 three/another
91 three/main
92 three/side
93 EOF
94
95 test_expect_success 'git fetch --multiple (but only one remote)' '
96 (git clone one test3 &&
97 cd test3 &&
98 git remote add three ../three &&
99 git fetch --multiple three &&
100 git branch -r > output &&
101 test_cmp ../expect output)
102 '
103
104 cat > expect << EOF
105 one/main
106 one/side
107 two/another
108 two/main
109 two/side
110 EOF
111
112 test_expect_success 'git fetch --multiple (two remotes)' '
113 (git clone one test4 &&
114 cd test4 &&
115 git remote rm origin &&
116 git remote add one ../one &&
117 git remote add two ../two &&
118 GIT_TRACE=1 git fetch --multiple one two 2>trace &&
119 git branch -r > output &&
120 test_cmp ../expect output &&
121 grep "built-in: git maintenance" trace >gc &&
122 test_line_count = 1 gc
123 )
124 '
125
126 test_expect_success 'git fetch --multiple (bad remote names)' '
127 (cd test4 &&
128 test_must_fail git fetch --multiple four)
129 '
130
131
132 test_expect_success 'git fetch --all (skipFetchAll)' '
133 (cd test4 &&
134 for b in $(git branch -r)
135 do
136 git branch -r -d $b || exit 1
137 done &&
138 git remote add three ../three &&
139 git config remote.three.skipFetchAll true &&
140 git fetch --all &&
141 git branch -r > output &&
142 test_cmp ../expect output)
143 '
144
145 cat > expect << EOF
146 one/main
147 one/side
148 three/another
149 three/main
150 three/side
151 two/another
152 two/main
153 two/side
154 EOF
155
156 test_expect_success 'git fetch --multiple (ignoring skipFetchAll)' '
157 (cd test4 &&
158 for b in $(git branch -r)
159 do
160 git branch -r -d $b || exit 1
161 done &&
162 git fetch --multiple one two three &&
163 git branch -r > output &&
164 test_cmp ../expect output)
165 '
166
167 test_expect_success 'git fetch --all --no-tags' '
168 git clone one test5 &&
169 git clone test5 test6 &&
170 (cd test5 && git tag test-tag) &&
171 (
172 cd test6 &&
173 git fetch --all --no-tags &&
174 git tag >output
175 ) &&
176 test_must_be_empty test6/output
177 '
178
179 test_expect_success 'git fetch --all --tags' '
180 echo test-tag >expect &&
181 git clone one test7 &&
182 git clone test7 test8 &&
183 (
184 cd test7 &&
185 test_commit test-tag &&
186 git reset --hard HEAD^
187 ) &&
188 (
189 cd test8 &&
190 git fetch --all --tags &&
191 git tag >output
192 ) &&
193 test_cmp expect test8/output
194 '
195
196 test_expect_success 'parallel' '
197 git remote add one ./bogus1 &&
198 git remote add two ./bogus2 &&
199
200 test_must_fail env GIT_TRACE="$PWD/trace" \
201 git fetch --jobs=2 --multiple one two 2>err &&
202 grep "preparing to run up to 2 tasks" trace &&
203 test_grep "could not fetch .one.*128" err &&
204 test_grep "could not fetch .two.*128" err
205 '
206
207 test_expect_success 'git fetch --multiple --jobs=0 picks a default' '
208 (cd test &&
209 git fetch --multiple --jobs=0)
210 '
211
212 test_done