211
grep "ERR upload-pack: not our ref" err
212
'
213
214
+test_expect_success 'server is initially ahead - ref in want' '
215
+ git -C "$REPO" config uploadpack.allowRefInWant true &&
216
+ rm -rf local &&
217
+ cp -r "$LOCAL_PRISTINE" local &&
218
+ inconsistency master 1234567890123456789012345678901234567890 &&
219
+ git -C local fetch &&
220
+
221
+ git -C "$REPO" rev-parse --verify master >expected &&
222
+ git -C local rev-parse --verify refs/remotes/origin/master >actual &&
223
+ test_cmp expected actual
224
+'
225
+
226
test_expect_success 'server is initially behind - no ref in want' '
227
git -C "$REPO" config uploadpack.allowRefInWant false &&
228
rm -rf local &&
235
test_cmp expected actual
236
'
237
238
+test_expect_success 'server is initially behind - ref in want' '
239
+ git -C "$REPO" config uploadpack.allowRefInWant true &&
240
+ rm -rf local &&
241
+ cp -r "$LOCAL_PRISTINE" local &&
242
+ inconsistency master "master^" &&
243
+ git -C local fetch &&
244
+
245
+ git -C "$REPO" rev-parse --verify "master" >expected &&
246
+ git -C local rev-parse --verify refs/remotes/origin/master >actual &&
247
+ test_cmp expected actual
248
+'
249
+
250
+test_expect_success 'server loses a ref - ref in want' '
251
+ git -C "$REPO" config uploadpack.allowRefInWant true &&
252
+ rm -rf local &&
253
+ cp -r "$LOCAL_PRISTINE" local &&
254
+ echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-sed" &&
255
+ test_must_fail git -C local fetch 2>err &&
256
+
257
+ grep "ERR unknown ref refs/heads/raster" err
258
+'
259
+
260
stop_httpd
261
262
+REPO="$(pwd)/repo"
263
+LOCAL_PRISTINE="$(pwd)/local_pristine"
264
+
265
+# $REPO
266
+# c(o/foo) d(o/bar)
267
+# \ /
268
+# b e(baz) f(master)
269
+# \__ | __/
270
+# \ | /
271
+# a
272
+#
273
+# $LOCAL_PRISTINE
274
+# s32(side)
275
+# |
276
+# .
277
+# .
278
+# |
279
+# a(master)
280
+test_expect_success 'setup repos for fetching with ref-in-want tests' '
281
+ (
282
+ git init "$REPO" &&
283
+ cd "$REPO" &&
284
+ test_commit a &&
285
+
286
+ # Local repo with many commits (so that negotiation will take
287
+ # more than 1 request/response pair)
288
+ rm -rf "$LOCAL_PRISTINE" &&
289
+ git clone "file://$REPO" "$LOCAL_PRISTINE" &&
290
+ cd "$LOCAL_PRISTINE" &&
291
+ git checkout -b side &&
292
+ for i in $(seq 1 33); do test_commit s$i; done &&
293
+
294
+ # Add novel commits to upstream
295
+ git checkout master &&
296
+ cd "$REPO" &&
297
+ git checkout -b o/foo &&
298
+ test_commit b &&
299
+ test_commit c &&
300
+ git checkout -b o/bar b &&
301
+ test_commit d &&
302
+ git checkout -b baz a &&
303
+ test_commit e &&
304
+ git checkout master &&
305
+ test_commit f
306
+ ) &&
307
+ git -C "$REPO" config uploadpack.allowRefInWant true &&
308
+ git -C "$LOCAL_PRISTINE" config protocol.version 2
309
+'
310
+
311
+test_expect_success 'fetching with exact OID' '
312
+ test_when_finished "rm -f log" &&
313
+
314
+ rm -rf local &&
315
+ cp -r "$LOCAL_PRISTINE" local &&
316
+ GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
317
+ $(git -C "$REPO" rev-parse d):refs/heads/actual &&
318
+
319
+ git -C "$REPO" rev-parse "d" >expected &&
320
+ git -C local rev-parse refs/heads/actual >actual &&
321
+ test_cmp expected actual &&
322
+ grep "want $(git -C "$REPO" rev-parse d)" log
323
+'
324
+
325
+test_expect_success 'fetching multiple refs' '
326
+ test_when_finished "rm -f log" &&
327
+
328
+ rm -rf local &&
329
+ cp -r "$LOCAL_PRISTINE" local &&
330
+ GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin master baz &&
331
+
332
+ git -C "$REPO" rev-parse "master" "baz" >expected &&
333
+ git -C local rev-parse refs/remotes/origin/master refs/remotes/origin/baz >actual &&
334
+ test_cmp expected actual &&
335
+ grep "want-ref refs/heads/master" log &&
336
+ grep "want-ref refs/heads/baz" log
337
+'
338
+
339
+test_expect_success 'fetching ref and exact OID' '
340
+ test_when_finished "rm -f log" &&
341
+
342
+ rm -rf local &&
343
+ cp -r "$LOCAL_PRISTINE" local &&
344
+ GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
345
+ master $(git -C "$REPO" rev-parse b):refs/heads/actual &&
346
+
347
+ git -C "$REPO" rev-parse "master" "b" >expected &&
348
+ git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
349
+ test_cmp expected actual &&
350
+ grep "want $(git -C "$REPO" rev-parse b)" log &&
351
+ grep "want-ref refs/heads/master" log
352
+'
353
+
354
+test_expect_success 'fetching with wildcard that does not match any refs' '
355
+ test_when_finished "rm -f log" &&
356
+
357
+ rm -rf local &&
358
+ cp -r "$LOCAL_PRISTINE" local &&
359
+ git -C local fetch origin refs/heads/none*:refs/heads/* >out &&
360
+ test_must_be_empty out
361
+'
362
+
363
+test_expect_success 'fetching with wildcard that matches multiple refs' '
364
+ test_when_finished "rm -f log" &&
365
+
366
+ rm -rf local &&
367
+ cp -r "$LOCAL_PRISTINE" local &&
368
+ GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin refs/heads/o*:refs/heads/o* &&
369
+
370
+ git -C "$REPO" rev-parse "o/foo" "o/bar" >expected &&
371
+ git -C local rev-parse "o/foo" "o/bar" >actual &&
372
+ test_cmp expected actual &&
373
+ grep "want-ref refs/heads/o/foo" log &&
374
+ grep "want-ref refs/heads/o/bar" log
375
+'
376
+
377
test_done