]>
Commit | Line | Data |
---|---|---|
7be1d62c JH |
1 | #!/bin/sh |
2 | # Copyright (c) 2006, Junio C Hamano. | |
3 | ||
4 | test_description='Per branch config variables affects "git fetch". | |
5 | ||
6 | ' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
10 | D=`pwd` | |
11 | ||
12 | test_expect_success setup ' | |
13 | echo >file original && | |
14 | git add file && | |
15 | git commit -a -m original' | |
16 | ||
17 | test_expect_success "clone and setup child repos" ' | |
18 | git clone . one && | |
19 | cd one && | |
20 | echo >file updated by one && | |
21 | git commit -a -m "updated by one" && | |
22 | cd .. && | |
23 | git clone . two && | |
24 | cd two && | |
e0d10e1c TP |
25 | git config branch.master.remote one && |
26 | git config remote.one.url ../one/.git/ && | |
27 | git config remote.one.fetch refs/heads/master:refs/heads/one && | |
6cc7c36d SB |
28 | cd .. && |
29 | git clone . three && | |
30 | cd three && | |
e0d10e1c TP |
31 | git config branch.master.remote two && |
32 | git config branch.master.merge refs/heads/one && | |
75c384ef | 33 | mkdir -p .git/remotes && |
6cc7c36d SB |
34 | { |
35 | echo "URL: ../two/.git/" | |
36 | echo "Pull: refs/heads/master:refs/heads/two" | |
37 | echo "Pull: refs/heads/one:refs/heads/one" | |
2e0afafe JS |
38 | } >.git/remotes/two && |
39 | cd .. && | |
9a7bbd1d JK |
40 | git clone . bundle && |
41 | git clone . seven | |
7be1d62c JH |
42 | ' |
43 | ||
44 | test_expect_success "fetch test" ' | |
45 | cd "$D" && | |
46 | echo >file updated by origin && | |
47 | git commit -a -m "updated by origin" && | |
48 | cd two && | |
49 | git fetch && | |
50 | test -f .git/refs/heads/one && | |
51 | mine=`git rev-parse refs/heads/one` && | |
52 | his=`cd ../one && git rev-parse refs/heads/master` && | |
53 | test "z$mine" = "z$his" | |
54 | ' | |
55 | ||
6cc7c36d SB |
56 | test_expect_success "fetch test for-merge" ' |
57 | cd "$D" && | |
58 | cd three && | |
59 | git fetch && | |
60 | test -f .git/refs/heads/two && | |
61 | test -f .git/refs/heads/one && | |
62 | master_in_two=`cd ../two && git rev-parse master` && | |
63 | one_in_two=`cd ../two && git rev-parse one` && | |
64 | { | |
65 | echo "$master_in_two not-for-merge" | |
66 | echo "$one_in_two " | |
67 | } >expected && | |
68 | cut -f -2 .git/FETCH_HEAD >actual && | |
69 | diff expected actual' | |
70 | ||
f539d0d6 VJ |
71 | test_expect_success 'fetch tags when there is no tags' ' |
72 | ||
73 | cd "$D" && | |
74 | ||
75 | mkdir notags && | |
76 | cd notags && | |
77 | git init && | |
78 | ||
79 | git fetch -t .. | |
80 | ||
81 | ' | |
82 | ||
6c96c0f1 JH |
83 | test_expect_success 'fetch following tags' ' |
84 | ||
85 | cd "$D" && | |
86 | git tag -a -m 'annotated' anno HEAD && | |
87 | git tag light HEAD && | |
88 | ||
89 | mkdir four && | |
90 | cd four && | |
5c94f87e | 91 | git init && |
6c96c0f1 JH |
92 | |
93 | git fetch .. :track && | |
94 | git show-ref --verify refs/tags/anno && | |
95 | git show-ref --verify refs/tags/light | |
96 | ||
97 | ' | |
98 | ||
41ac414e | 99 | test_expect_success 'fetch must not resolve short tag name' ' |
605b4978 SP |
100 | |
101 | cd "$D" && | |
102 | ||
103 | mkdir five && | |
104 | cd five && | |
105 | git init && | |
106 | ||
d492b31c | 107 | test_must_fail git fetch .. anno:five |
605b4978 SP |
108 | |
109 | ' | |
110 | ||
41ac414e | 111 | test_expect_success 'fetch must not resolve short remote name' ' |
605b4978 SP |
112 | |
113 | cd "$D" && | |
3604e7c5 | 114 | git update-ref refs/remotes/six/HEAD HEAD |
605b4978 SP |
115 | |
116 | mkdir six && | |
117 | cd six && | |
118 | git init && | |
119 | ||
d492b31c | 120 | test_must_fail git fetch .. six:six |
605b4978 SP |
121 | |
122 | ' | |
123 | ||
2e0afafe JS |
124 | test_expect_success 'create bundle 1' ' |
125 | cd "$D" && | |
126 | echo >file updated again by origin && | |
127 | git commit -a -m "tip" && | |
128 | git bundle create bundle1 master^..master | |
129 | ' | |
130 | ||
8315588b JS |
131 | test_expect_success 'header of bundle looks right' ' |
132 | head -n 1 "$D"/bundle1 | grep "^#" && | |
133 | head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " && | |
134 | head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " && | |
135 | head -n 4 "$D"/bundle1 | grep "^$" | |
136 | ' | |
137 | ||
2e0afafe JS |
138 | test_expect_success 'create bundle 2' ' |
139 | cd "$D" && | |
140 | git bundle create bundle2 master~2..master | |
141 | ' | |
142 | ||
41ac414e | 143 | test_expect_success 'unbundle 1' ' |
2e0afafe JS |
144 | cd "$D/bundle" && |
145 | git checkout -b some-branch && | |
d492b31c | 146 | test_must_fail git fetch "$D/bundle1" master:master |
2e0afafe JS |
147 | ' |
148 | ||
8315588b JS |
149 | test_expect_success 'bundle 1 has only 3 files ' ' |
150 | cd "$D" && | |
151 | ( | |
152 | while read x && test -n "$x" | |
153 | do | |
154 | :; | |
155 | done | |
156 | cat | |
157 | ) <bundle1 >bundle.pack && | |
158 | git index-pack bundle.pack && | |
159 | verify=$(git verify-pack -v bundle.pack) && | |
160 | test 4 = $(echo "$verify" | wc -l) | |
161 | ' | |
162 | ||
2e0afafe JS |
163 | test_expect_success 'unbundle 2' ' |
164 | cd "$D/bundle" && | |
165 | git fetch ../bundle2 master:master && | |
166 | test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)" | |
167 | ' | |
168 | ||
18449ab0 JS |
169 | test_expect_success 'bundle does not prerequisite objects' ' |
170 | cd "$D" && | |
171 | touch file2 && | |
172 | git add file2 && | |
173 | git commit -m add.file2 file2 && | |
174 | git bundle create bundle3 -1 HEAD && | |
6016e35b SP |
175 | ( |
176 | while read x && test -n "$x" | |
177 | do | |
178 | :; | |
179 | done | |
180 | cat | |
181 | ) <bundle3 >bundle.pack && | |
18449ab0 JS |
182 | git index-pack bundle.pack && |
183 | test 4 = $(git verify-pack -v bundle.pack | wc -l) | |
184 | ' | |
185 | ||
7fa8254f JH |
186 | test_expect_success 'bundle should be able to create a full history' ' |
187 | ||
188 | cd "$D" && | |
189 | git tag -a -m '1.0' v1.0 master && | |
190 | git bundle create bundle4 v1.0 | |
191 | ||
192 | ' | |
193 | ||
cd547b48 JS |
194 | test "$TEST_RSYNC" && { |
195 | test_expect_success 'fetch via rsync' ' | |
196 | git pack-refs && | |
197 | mkdir rsynced && | |
198 | cd rsynced && | |
199 | git init && | |
200 | git fetch rsync://127.0.0.1$(pwd)/../.git master:refs/heads/master && | |
201 | git gc --prune && | |
202 | test $(git rev-parse master) = $(cd .. && git rev-parse master) && | |
203 | git fsck --full | |
204 | ' | |
205 | ||
206 | test_expect_success 'push via rsync' ' | |
207 | mkdir ../rsynced2 && | |
208 | (cd ../rsynced2 && | |
209 | git init) && | |
210 | git push rsync://127.0.0.1$(pwd)/../rsynced2/.git master && | |
211 | cd ../rsynced2 && | |
212 | git gc --prune && | |
213 | test $(git rev-parse master) = $(cd .. && git rev-parse master) && | |
214 | git fsck --full | |
215 | ' | |
216 | ||
217 | test_expect_success 'push via rsync' ' | |
218 | cd .. && | |
219 | mkdir rsynced3 && | |
220 | (cd rsynced3 && | |
221 | git init) && | |
222 | git push --all rsync://127.0.0.1$(pwd)/rsynced3/.git && | |
223 | cd rsynced3 && | |
224 | test $(git rev-parse master) = $(cd .. && git rev-parse master) && | |
225 | git fsck --full | |
226 | ' | |
227 | } | |
228 | ||
da0204df JS |
229 | test_expect_success 'fetch with a non-applying branch.<name>.merge' ' |
230 | git config branch.master.remote yeti && | |
231 | git config branch.master.merge refs/heads/bigfoot && | |
232 | git config remote.blub.url one && | |
233 | git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" && | |
234 | git fetch blub | |
235 | ' | |
236 | ||
c2015b3a JS |
237 | # the strange name is: a\!'b |
238 | test_expect_success 'quoting of a strangely named repo' ' | |
d492b31c | 239 | test_must_fail git fetch "a\\!'\''b" > result 2>&1 && |
c2015b3a JS |
240 | cat result && |
241 | grep "fatal: '\''a\\\\!'\''b'\''" result | |
242 | ' | |
243 | ||
c5546e88 JS |
244 | test_expect_success 'bundle should record HEAD correctly' ' |
245 | ||
246 | cd "$D" && | |
247 | git bundle create bundle5 HEAD master && | |
248 | git bundle list-heads bundle5 >actual && | |
249 | for h in HEAD refs/heads/master | |
250 | do | |
251 | echo "$(git rev-parse --verify $h) $h" | |
252 | done >expect && | |
82ebb0b6 | 253 | test_cmp expect actual |
c5546e88 JS |
254 | |
255 | ' | |
256 | ||
c7015961 JH |
257 | test_expect_success 'explicit fetch should not update tracking' ' |
258 | ||
259 | cd "$D" && | |
260 | git branch -f side && | |
261 | ( | |
262 | cd three && | |
263 | o=$(git rev-parse --verify refs/remotes/origin/master) && | |
264 | git fetch origin master && | |
265 | n=$(git rev-parse --verify refs/remotes/origin/master) && | |
266 | test "$o" = "$n" && | |
d492b31c | 267 | test_must_fail git rev-parse --verify refs/remotes/origin/side |
c7015961 JH |
268 | ) |
269 | ' | |
270 | ||
271 | test_expect_success 'explicit pull should not update tracking' ' | |
272 | ||
273 | cd "$D" && | |
274 | git branch -f side && | |
275 | ( | |
276 | cd three && | |
277 | o=$(git rev-parse --verify refs/remotes/origin/master) && | |
278 | git pull origin master && | |
279 | n=$(git rev-parse --verify refs/remotes/origin/master) && | |
280 | test "$o" = "$n" && | |
d492b31c | 281 | test_must_fail git rev-parse --verify refs/remotes/origin/side |
c7015961 JH |
282 | ) |
283 | ' | |
284 | ||
285 | test_expect_success 'configured fetch updates tracking' ' | |
286 | ||
287 | cd "$D" && | |
288 | git branch -f side && | |
289 | ( | |
290 | cd three && | |
291 | o=$(git rev-parse --verify refs/remotes/origin/master) && | |
292 | git fetch origin && | |
293 | n=$(git rev-parse --verify refs/remotes/origin/master) && | |
294 | test "$o" != "$n" && | |
295 | git rev-parse --verify refs/remotes/origin/side | |
296 | ) | |
297 | ' | |
298 | ||
9a7bbd1d JK |
299 | test_expect_success 'pushing nonexistent branch by mistake should not segv' ' |
300 | ||
301 | cd "$D" && | |
302 | test_must_fail git push seven no:no | |
303 | ||
304 | ' | |
305 | ||
49420252 JH |
306 | test_expect_success 'auto tag following fetches minimum' ' |
307 | ||
308 | cd "$D" && | |
309 | git clone .git follow && | |
310 | git checkout HEAD^0 && | |
311 | ( | |
312 | for i in 1 2 3 4 5 6 7 | |
313 | do | |
314 | echo $i >>file && | |
315 | git commit -m $i -a && | |
316 | git tag -a -m $i excess-$i || exit 1 | |
317 | done | |
318 | ) && | |
319 | git checkout master && | |
320 | ( | |
321 | cd follow && | |
322 | git fetch | |
323 | ) | |
324 | ' | |
325 | ||
8ee5d731 JS |
326 | test_expect_success 'refuse to fetch into the current branch' ' |
327 | ||
328 | test_must_fail git fetch . side:master | |
329 | ||
330 | ' | |
331 | ||
332 | test_expect_success 'fetch into the current branch with --update-head-ok' ' | |
333 | ||
334 | git fetch --update-head-ok . side:master | |
335 | ||
336 | ' | |
337 | ||
7be1d62c | 338 | test_done |