Skip to content

Commit a26434b

Browse files
committed
Merge branch 'ds/partial-clone-fixes' into next
Fix for a bug revealed by a recent change to make the protocol v2 the default. * ds/partial-clone-fixes: partial-clone: avoid fetching when looking for objects partial-clone: demonstrate bugs in partial fetch
2 parents ba3706c + 3e96c66 commit a26434b

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

builtin/fetch.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ static void find_non_local_tags(const struct ref *refs,
335335
struct string_list_item *remote_ref_item;
336336
const struct ref *ref;
337337
struct refname_hash_entry *item = NULL;
338+
const int quick_flags = OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT;
338339

339340
refname_hash_init(&existing_refs);
340341
refname_hash_init(&remote_refs);
@@ -353,10 +354,9 @@ static void find_non_local_tags(const struct ref *refs,
353354
*/
354355
if (ends_with(ref->name, "^{}")) {
355356
if (item &&
356-
!has_object_file_with_flags(&ref->old_oid,
357-
OBJECT_INFO_QUICK) &&
357+
!has_object_file_with_flags(&ref->old_oid, quick_flags) &&
358358
!oidset_contains(&fetch_oids, &ref->old_oid) &&
359-
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
359+
!has_object_file_with_flags(&item->oid, quick_flags) &&
360360
!oidset_contains(&fetch_oids, &item->oid))
361361
clear_item(item);
362362
item = NULL;
@@ -370,7 +370,7 @@ static void find_non_local_tags(const struct ref *refs,
370370
* fetch.
371371
*/
372372
if (item &&
373-
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
373+
!has_object_file_with_flags(&item->oid, quick_flags) &&
374374
!oidset_contains(&fetch_oids, &item->oid))
375375
clear_item(item);
376376

@@ -391,7 +391,7 @@ static void find_non_local_tags(const struct ref *refs,
391391
* checked to see if it needs fetching.
392392
*/
393393
if (item &&
394-
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
394+
!has_object_file_with_flags(&item->oid, quick_flags) &&
395395
!oidset_contains(&fetch_oids, &item->oid))
396396
clear_item(item);
397397

t/t5616-partial-clone.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,37 @@ test_expect_success 'fetch lazy-fetches only to resolve deltas, protocol v2' '
384384
grep "want $(cat hash)" trace
385385
'
386386

387+
# The following two tests must be in this order, or else
388+
# the first will not fail. It is important that the srv.bare
389+
# repository did not have tags during clone, but has tags
390+
# in the fetch.
391+
392+
test_expect_failure 'verify fetch succeeds when asking for new tags' '
393+
git clone --filter=blob:none "file://$(pwd)/srv.bare" tag-test &&
394+
for i in I J K
395+
do
396+
test_commit -C src $i &&
397+
git -C src branch $i || return 1
398+
done &&
399+
git -C srv.bare fetch --tags origin +refs/heads/*:refs/heads/* &&
400+
git -C tag-test -c protocol.version=2 fetch --tags origin
401+
'
402+
403+
test_expect_success 'verify fetch downloads only one pack when updating refs' '
404+
git clone --filter=blob:none "file://$(pwd)/srv.bare" pack-test &&
405+
ls pack-test/.git/objects/pack/*pack >pack-list &&
406+
test_line_count = 2 pack-list &&
407+
for i in A B C
408+
do
409+
test_commit -C src $i &&
410+
git -C src branch $i || return 1
411+
done &&
412+
git -C srv.bare fetch origin +refs/heads/*:refs/heads/* &&
413+
git -C pack-test fetch origin &&
414+
ls pack-test/.git/objects/pack/*pack >pack-list &&
415+
test_line_count = 3 pack-list
416+
'
417+
387418
. "$TEST_DIRECTORY"/lib-httpd.sh
388419
start_httpd
389420

0 commit comments

Comments
 (0)