Skip to content

Commit edf9793

Browse files
10ne1claude
andcommitted
gix: cover the sha256-only legacy object-hash path
legacy_object_hash() has a feature-gated split: it returns Sha1 when the build supports it and an error otherwise. Add a unit test asserting the branch for the current build, and run the gix lib tests under --no-default-features --features sha256 so the error path is actually exercised in CI. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
1 parent e7488d1 commit edf9793

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

gix/src/config/cache/incubate.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,24 @@ fn load_config(
170170

171171
Ok(config)
172172
}
173+
174+
#[cfg(test)]
175+
mod tests {
176+
/// `legacy_object_hash` has a feature-gated split: Sha1 when this build supports it, an error
177+
/// otherwise. Assert the branch matching the current build so the sha256-only path is covered
178+
/// when the lib tests run under `--no-default-features --features sha256`.
179+
#[test]
180+
fn legacy_object_hash_reflects_build_features() {
181+
let actual = super::legacy_object_hash();
182+
#[cfg(feature = "sha1")]
183+
assert!(
184+
matches!(actual, Ok(gix_hash::Kind::Sha1)),
185+
"with sha1 support a missing objectFormat resolves to the legacy Sha1 layout, got {actual:?}"
186+
);
187+
#[cfg(not(feature = "sha1"))]
188+
assert!(
189+
matches!(actual, Err(super::Error::UnsupportedObjectFormat { .. })),
190+
"without sha1 support a missing objectFormat cannot be opened, got {actual:?}"
191+
);
192+
}
193+
}

justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ unit-tests:
216216
cargo nextest run -p gix --features async-network-client --no-fail-fast
217217
cargo nextest run -p gix --features blocking-network-client --no-fail-fast
218218
env GIX_TEST_FIXTURE_HASH=sha256 cargo nextest run -p gix --no-fail-fast
219+
cargo nextest run -p gix --no-default-features --features sha256 --lib --no-fail-fast
219220
cargo nextest run -p gitoxide-core --lib --no-tests=warn --no-fail-fast
220221

221222
# Run all doctests

0 commit comments

Comments
 (0)