Skip to content

Commit

Permalink
Merge pull request GitoxideLabs#1332 from cesfahani/fix_fsck_tree_tra…
Browse files Browse the repository at this point in the history
…versal

Fix git-fsck to handle non-root trees
  • Loading branch information
Byron authored Apr 2, 2024
2 parents 9e9c653 + 5fdb440 commit 4bb8ef5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 2 additions & 4 deletions gix-fsck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ where
match entry_ref.mode.kind() {
EntryKind::Tree => {
let tree_id = entry_ref.oid.to_owned();
if self.seen.insert(tree_id) {
tree_ids.push_back(tree_id);
}
tree_ids.push_back(tree_id);
}
EntryKind::Blob | EntryKind::BlobExecutable | EntryKind::Link => {
let blob_id = entry_ref.oid.to_owned();
Expand All @@ -91,7 +89,7 @@ where
}
}
EntryKind::Commit => {
// Skip submodules as it's not in this repository!
// Skip submodules as they wouldn't be in this repository!
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions gix-fsck/tests/connectivity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ fn hex_to_objects<'a>(hex_ids: impl IntoIterator<Item = &'a str>, kind: Kind) ->
fn all_commits() -> &'static [ObjectId] {
static ALL_COMMITS: Lazy<Vec<ObjectId>> = Lazy::new(|| {
hex_to_ids([
"5d18db2e2aabadf7b914435ef34f2faf8b4546dd",
"3a3dfaa55a515f3fb3a25751107bbb523af6a1b0",
"ebed23648b19484cb1f340c4ee04dda08479188a",
"8ff6d0f8891c3cb22827be142cc64606121d47b3",
"734c926856a328d1168ffd7088532e0d1ad19bbe",
])
});
Expand All @@ -59,7 +59,13 @@ fn no_missing() {
#[test]
fn missing_blobs() {
// The "blobless" repo is cloned with `--filter=blob:none`, and is missing one blob
let expected = hex_to_objects(["c18147dc648481eeb65dc5e66628429a64843327"], Kind::Blob);
let expected = hex_to_objects(
[
"4cdeaab5b01f9a9fbbb2fb6c08404cf12b7bdab1",
"c18147dc648481eeb65dc5e66628429a64843327",
],
Kind::Blob,
);
assert_eq!(check_missing("blobless", all_commits()), expected);
}

Expand All @@ -69,7 +75,7 @@ fn missing_trees() {
// NOTE: This repo is also missing a blob, but we have no way of knowing that, as the tree referencing it is missing
let expected = hex_to_objects(
[
"9561cfbae43c5e2accdfcd423378588dd10d827f",
"20317ffa7614f49b2702a057bf2833918ea9fd24",
"fc264b3b6875a46e9031483aeb9994a1b897ffd3",
],
Kind::Tree,
Expand Down
4 changes: 3 additions & 1 deletion gix-fsck/tests/fixtures/make_test_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ git init base
git add -A
git commit -m "commit 1"
echo "blob-2" > blob-2
mkdir tree-1
echo "blob-3" > tree-1/blob-3
git add -A
git commit -m "commit 2"
git rm blob-1
git rm blob-1 tree-1/blob-3
git add -A
git commit -m "commit 3"
)
Expand Down

0 comments on commit 4bb8ef5

Please sign in to comment.