Skip to content

Commit e15ef66

Browse files
committed
fsck: check loose objects from alternate object stores by default
"git fsck" used to validate only loose objects that are local and nothing else by default. This is not just too little when a repository is borrowing objects from other object stores, but also caused the connectivity check to mistakenly declare loose objects borrowed from them to be missing. The rationale behind the default mode that validates only loose objects is because these objects are still young and more unlikely to have been pushed to other repositories yet. That holds for loose objects borrowed from alternate object stores as well. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 469e2eb commit e15ef66

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

builtin-fsck.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ static struct option fsck_opts[] = {
586586
int cmd_fsck(int argc, const char **argv, const char *prefix)
587587
{
588588
int i, heads;
589+
struct alternate_object_database *alt;
589590

590591
errors_found = 0;
591592

@@ -597,17 +598,19 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
597598

598599
fsck_head_link();
599600
fsck_object_dir(get_object_directory());
601+
602+
prepare_alt_odb();
603+
for (alt = alt_odb_list; alt; alt = alt->next) {
604+
char namebuf[PATH_MAX];
605+
int namelen = alt->name - alt->base;
606+
memcpy(namebuf, alt->base, namelen);
607+
namebuf[namelen - 1] = 0;
608+
fsck_object_dir(namebuf);
609+
}
610+
600611
if (check_full) {
601-
struct alternate_object_database *alt;
602612
struct packed_git *p;
603-
prepare_alt_odb();
604-
for (alt = alt_odb_list; alt; alt = alt->next) {
605-
char namebuf[PATH_MAX];
606-
int namelen = alt->name - alt->base;
607-
memcpy(namebuf, alt->base, namelen);
608-
namebuf[namelen - 1] = 0;
609-
fsck_object_dir(namebuf);
610-
}
613+
611614
prepare_packed_git();
612615
for (p = packed_git; p; p = p->next)
613616
/* verify gives error messages itself */

t/t1450-fsck.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,16 @@ test_expect_success 'HEAD is part of refs' '
1616
test 0 = $(git fsck | wc -l)
1717
'
1818

19+
test_expect_success 'loose objects borrowed from alternate are not missing' '
20+
mkdir another &&
21+
(
22+
cd another &&
23+
git init &&
24+
echo ../../../.git/objects >.git/objects/info/alternates &&
25+
test_commit C fileC one &&
26+
git fsck >out &&
27+
! grep "missing blob" out
28+
)
29+
'
30+
1931
test_done

0 commit comments

Comments
 (0)