Skip to content

Commit 5fdb440

Browse files
committed
Fix git-fsck to handle non-root trees
- Trees except the commit's root tree were being skipped - Make `check_commit()` the only functioning marking trees as "seen" - Update unit tests to catch the failure (add a directory to test repo)
1 parent 9e9c653 commit 5fdb440

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

gix-fsck/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ where
8080
match entry_ref.mode.kind() {
8181
EntryKind::Tree => {
8282
let tree_id = entry_ref.oid.to_owned();
83-
if self.seen.insert(tree_id) {
84-
tree_ids.push_back(tree_id);
85-
}
83+
tree_ids.push_back(tree_id);
8684
}
8785
EntryKind::Blob | EntryKind::BlobExecutable | EntryKind::Link => {
8886
let blob_id = entry_ref.oid.to_owned();
@@ -91,7 +89,7 @@ where
9189
}
9290
}
9391
EntryKind::Commit => {
94-
// Skip submodules as it's not in this repository!
92+
// Skip submodules as they wouldn't be in this repository!
9593
}
9694
}
9795
}

gix-fsck/tests/connectivity/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ fn hex_to_objects<'a>(hex_ids: impl IntoIterator<Item = &'a str>, kind: Kind) ->
4242
fn all_commits() -> &'static [ObjectId] {
4343
static ALL_COMMITS: Lazy<Vec<ObjectId>> = Lazy::new(|| {
4444
hex_to_ids([
45-
"5d18db2e2aabadf7b914435ef34f2faf8b4546dd",
46-
"3a3dfaa55a515f3fb3a25751107bbb523af6a1b0",
45+
"ebed23648b19484cb1f340c4ee04dda08479188a",
46+
"8ff6d0f8891c3cb22827be142cc64606121d47b3",
4747
"734c926856a328d1168ffd7088532e0d1ad19bbe",
4848
])
4949
});
@@ -59,7 +59,13 @@ fn no_missing() {
5959
#[test]
6060
fn missing_blobs() {
6161
// The "blobless" repo is cloned with `--filter=blob:none`, and is missing one blob
62-
let expected = hex_to_objects(["c18147dc648481eeb65dc5e66628429a64843327"], Kind::Blob);
62+
let expected = hex_to_objects(
63+
[
64+
"4cdeaab5b01f9a9fbbb2fb6c08404cf12b7bdab1",
65+
"c18147dc648481eeb65dc5e66628429a64843327",
66+
],
67+
Kind::Blob,
68+
);
6369
assert_eq!(check_missing("blobless", all_commits()), expected);
6470
}
6571

@@ -69,7 +75,7 @@ fn missing_trees() {
6975
// NOTE: This repo is also missing a blob, but we have no way of knowing that, as the tree referencing it is missing
7076
let expected = hex_to_objects(
7177
[
72-
"9561cfbae43c5e2accdfcd423378588dd10d827f",
78+
"20317ffa7614f49b2702a057bf2833918ea9fd24",
7379
"fc264b3b6875a46e9031483aeb9994a1b897ffd3",
7480
],
7581
Kind::Tree,

gix-fsck/tests/fixtures/make_test_repos.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ git init base
1818
git add -A
1919
git commit -m "commit 1"
2020
echo "blob-2" > blob-2
21+
mkdir tree-1
22+
echo "blob-3" > tree-1/blob-3
2123
git add -A
2224
git commit -m "commit 2"
23-
git rm blob-1
25+
git rm blob-1 tree-1/blob-3
2426
git add -A
2527
git commit -m "commit 3"
2628
)

0 commit comments

Comments
 (0)