History

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)

Cameron Esfahani committed 2 years ago

Commit 5fdb4401 parent 9e9c6533 files · +15 −9Browse files

Unified · Split

3 files
  1. gix-fsck/src/lib.rs +2 −4
  2. gix-fsck/tests/connectivity/mod.rs +10 −4
  3. gix-fsck/tests/fixtures/make_test_repos.sh +3 −1
gix-fsck/src/lib.rs+2−4
@@ -80,9 +80,7 @@ where · 79 unmodified lines
80 match entry_ref.mode.kind() {80 match entry_ref.mode.kind() {
81 EntryKind::Tree => {81 EntryKind::Tree => {
82 let tree_id = entry_ref.oid.to_owned();82 let tree_id = entry_ref.oid.to_owned();
83 if self.seen.insert(tree_id) {83 tree_ids.push_back(tree_id);
84 tree_ids.push_back(tree_id);
85 }
86 }84 }
87 EntryKind::Blob | EntryKind::BlobExecutable | EntryKind::Link => {85 EntryKind::Blob | EntryKind::BlobExecutable | EntryKind::Link => {
88 let blob_id = entry_ref.oid.to_owned();86 let blob_id = entry_ref.oid.to_owned();
@@ -91,7 +89,7 @@ where · 2 unmodified lines
91 }89 }
92 }90 }
93 EntryKind::Commit => {91 EntryKind::Commit => {
94 // Skip submodules as it's not in this repository!92 // Skip submodules as they wouldn't be in this repository!
95 }93 }
96 }94 }
97 }95 }
gix-fsck/tests/connectivity/mod.rs+10−4
@@ -42,8 +42,8 @@ fn hex_to_objects<'a>(hex_ids: impl IntoIterator<Item = &'a str>, kind: Kind) -> · 41 unmodified lines
42fn all_commits() -> &'static [ObjectId] {42fn all_commits() -> &'static [ObjectId] {
43 static ALL_COMMITS: Lazy<Vec<ObjectId>> = Lazy::new(|| {43 static ALL_COMMITS: Lazy<Vec<ObjectId>> = Lazy::new(|| {
44 hex_to_ids([44 hex_to_ids([
45 "5d18db2e2aabadf7b914435ef34f2faf8b4546dd",45 "ebed23648b19484cb1f340c4ee04dda08479188a",
46 "3a3dfaa55a515f3fb3a25751107bbb523af6a1b0",46 "8ff6d0f8891c3cb22827be142cc64606121d47b3",
47 "734c926856a328d1168ffd7088532e0d1ad19bbe",47 "734c926856a328d1168ffd7088532e0d1ad19bbe",
48 ])48 ])
49 });49 });
@@ -59,7 +59,13 @@ fn no_missing() { · 9 unmodified lines
59#[test]59#[test]
60fn missing_blobs() {60fn missing_blobs() {
61 // The "blobless" repo is cloned with `--filter=blob:none`, and is missing one blob61 // 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 );
63 assert_eq!(check_missing("blobless", all_commits()), expected);69 assert_eq!(check_missing("blobless", all_commits()), expected);
64}70}
65 71
@@ -69,7 +75,7 @@ fn missing_trees() { · 3 unmodified lines
69 // NOTE: This repo is also missing a blob, but we have no way of knowing that, as the tree referencing it is missing75 // NOTE: This repo is also missing a blob, but we have no way of knowing that, as the tree referencing it is missing
70 let expected = hex_to_objects(76 let expected = hex_to_objects(
71 [77 [
72 "9561cfbae43c5e2accdfcd423378588dd10d827f",78 "20317ffa7614f49b2702a057bf2833918ea9fd24",
73 "fc264b3b6875a46e9031483aeb9994a1b897ffd3",79 "fc264b3b6875a46e9031483aeb9994a1b897ffd3",
74 ],80 ],
75 Kind::Tree,81 Kind::Tree,
gix-fsck/tests/fixtures/make_test_repos.sh+3−1
@@ -18,9 +18,11 @@ git init base · 17 unmodified lines
18 git add -A18 git add -A
19 git commit -m "commit 1"19 git commit -m "commit 1"
20 echo "blob-2" > blob-220 echo "blob-2" > blob-2
21 mkdir tree-1
22 echo "blob-3" > tree-1/blob-3
21 git add -A23 git add -A
22 git commit -m "commit 2"24 git commit -m "commit 2"
23 git rm blob-125 git rm blob-1 tree-1/blob-3
24 git add -A26 git add -A
25 git commit -m "commit 3"27 git commit -m "commit 3"
26)28)