Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gix-refspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ smallvec = "1.15.1"

[dev-dependencies]
gix-testtools = { path = "../tests/tools" }
gix-hash = { path = "../gix-hash", features = ["sha1", "sha256"] }
insta = "1.46.1"

[package.metadata.docs.rs]
Expand Down
Binary file not shown.
24 changes: 18 additions & 6 deletions gix-refspec/tests/fixtures/match_baseline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,24 @@ git clone --shared ./base clone
baseline "main"
baseline "v0.0-f1"
baseline "tags/v0.0-f2"
baseline "78b1c1be9421b33a49a7a8176d93eeeafa112da1"
baseline "9d2fab1a0ba3585d0bc50922bfdd04ebb59361df"
baseline "78b1c1be9421b33a49a7a8176d93eeeafa112da1:special"
baseline "78b1c1be9421b33a49a7a8176d93eeeafa112da1:1111111111111111111111111111111111111111"
baseline "9d2fab1a0ba3585d0bc50922bfdd04ebb59361df:tags/special"
baseline "9d2fab1a0ba3585d0bc50922bfdd04ebb59361df:refs/tags/special"
case ${GIX_TEST_FIXTURE_HASH:-sha1} in
sha1)
baseline "78b1c1be9421b33a49a7a8176d93eeeafa112da1"
baseline "9d2fab1a0ba3585d0bc50922bfdd04ebb59361df"
baseline "78b1c1be9421b33a49a7a8176d93eeeafa112da1:special"
baseline "78b1c1be9421b33a49a7a8176d93eeeafa112da1:1111111111111111111111111111111111111111"
baseline "9d2fab1a0ba3585d0bc50922bfdd04ebb59361df:tags/special"
baseline "9d2fab1a0ba3585d0bc50922bfdd04ebb59361df:refs/tags/special" ;;
sha256)
baseline "b071221ea854da2958fba3a37527ca5cf32c4ebcd71ab0b68b6b8f10f04e93ad"
baseline "ac050883b75422e0d03bfee760c591b292cbc10cee8ad934480ea5fb2ebc44fe"
baseline "b071221ea854da2958fba3a37527ca5cf32c4ebcd71ab0b68b6b8f10f04e93ad:special"
baseline "b071221ea854da2958fba3a37527ca5cf32c4ebcd71ab0b68b6b8f10f04e93ad:1111111111111111111111111111111111111111"
baseline "ac050883b75422e0d03bfee760c591b292cbc10cee8ad934480ea5fb2ebc44fe:tags/special"
baseline "ac050883b75422e0d03bfee760c591b292cbc10cee8ad934480ea5fb2ebc44fe:refs/tags/special" ;;
*)
exit 1 ;;
esac
baseline "f1:origin/f1"
baseline "f1:remotes/origin/f1"
baseline "f1:notes/f1"
Expand Down
43 changes: 29 additions & 14 deletions gix-refspec/tests/refspec/match_group.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,53 @@
mod single {
use crate::matching::baseline;

fn test_hashes() -> (String, String) {
let annotated_tag = match gix_testtools::hash_kind_from_env() {
gix_hash::Kind::Sha1 => "78b1c1be9421b33a49a7a8176d93eeeafa112da1",
gix_hash::Kind::Sha256 => "b071221ea854da2958fba3a37527ca5cf32c4ebcd71ab0b68b6b8f10f04e93ad",
_ => unimplemented!(),
};
let initial_commit = match gix_testtools::hash_kind_from_env() {
gix_hash::Kind::Sha1 => "9d2fab1a0ba3585d0bc50922bfdd04ebb59361df",
gix_hash::Kind::Sha256 => "ac050883b75422e0d03bfee760c591b292cbc10cee8ad934480ea5fb2ebc44fe",
_ => unimplemented!(),
};

(annotated_tag.into(), initial_commit.into())
}

#[test]
fn fetch_only() {
let (annotated_tag, initial_commit) = test_hashes();

baseline::agrees_with_fetch_specs(Some("refs/heads/main"));
baseline::agrees_with_fetch_specs(Some("heads/main"));
baseline::agrees_with_fetch_specs(Some("main"));
baseline::agrees_with_fetch_specs(Some("v0.0-f1"));
baseline::agrees_with_fetch_specs(Some("tags/v0.0-f2"));
baseline::of_objects_always_matches_if_the_server_has_the_object(Some(
"78b1c1be9421b33a49a7a8176d93eeeafa112da1",
));
baseline::of_objects_always_matches_if_the_server_has_the_object(Some(
"9d2fab1a0ba3585d0bc50922bfdd04ebb59361df",
));
baseline::of_objects_always_matches_if_the_server_has_the_object(Some(annotated_tag.as_ref()));
baseline::of_objects_always_matches_if_the_server_has_the_object(Some(initial_commit.as_ref()));
}

#[test]
fn fetch_and_update() {
let (annotated_tag, initial_commit) = test_hashes();

baseline::of_objects_with_destinations_are_written_into_given_local_branches(
Some("78b1c1be9421b33a49a7a8176d93eeeafa112da1:special"),
["78b1c1be9421b33a49a7a8176d93eeeafa112da1:refs/heads/special"],
Some(format!("{annotated_tag}:special").as_ref()),
[format!("{annotated_tag}:refs/heads/special").as_ref()],
);
baseline::of_objects_with_destinations_are_written_into_given_local_branches(
Some("78b1c1be9421b33a49a7a8176d93eeeafa112da1:1111111111111111111111111111111111111111"),
["78b1c1be9421b33a49a7a8176d93eeeafa112da1:refs/heads/1111111111111111111111111111111111111111"],
Some(format!("{annotated_tag}:1111111111111111111111111111111111111111").as_ref()),
[format!("{annotated_tag}:refs/heads/1111111111111111111111111111111111111111").as_ref()],
);
baseline::of_objects_with_destinations_are_written_into_given_local_branches(
Some("9d2fab1a0ba3585d0bc50922bfdd04ebb59361df:tags/special"),
["9d2fab1a0ba3585d0bc50922bfdd04ebb59361df:refs/tags/special"],
Some(format!("{initial_commit}:tags/special").as_ref()),
[format!("{initial_commit}:refs/tags/special").as_ref()],
);
baseline::of_objects_with_destinations_are_written_into_given_local_branches(
Some("9d2fab1a0ba3585d0bc50922bfdd04ebb59361df:refs/tags/special"),
["9d2fab1a0ba3585d0bc50922bfdd04ebb59361df:refs/tags/special"],
Some(format!("{initial_commit}:refs/tags/special").as_ref()),
[format!("{initial_commit}:refs/tags/special").as_ref()],
);

baseline::agrees_but_observable_refs_are_vague(Some("f1:origin/f1"), ["refs/heads/f1:refs/heads/origin/f1"]);
Expand Down
10 changes: 10 additions & 0 deletions gix-refspec/tests/refspec/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ mod prefix {
parse("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391").to_ref().prefix(),
None
);
assert_eq!(
parse("b071221ea854da2958fba3a37527ca5cf32c4ebcd71ab0b68b6b8f10f04e93ad")
.to_ref()
.prefix(),
None
);
}

fn parse(spec: &str) -> RefSpec {
Expand Down Expand Up @@ -117,6 +123,10 @@ mod expand_prefixes {
#[test]
fn object_names_expand_to_nothing() {
assert_eq!(parse("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391").len(), 0);
assert_eq!(
parse("b071221ea854da2958fba3a37527ca5cf32c4ebcd71ab0b68b6b8f10f04e93ad").len(),
0
);
}

fn parse(spec: &str) -> Vec<String> {
Expand Down
9 changes: 8 additions & 1 deletion gix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ comfort = [
#! Support for various hash algorithms is controlled here. The idea is to allow applications to
#! compile in only the ones they need, which is why within the entire `gix` stack there is no
#! crate that sets an algorithm, except for the top-level `gix` crate for convenience.
#!
#!
#! At least one hash algorithm must be enabled for compilation to succeed.

## Enable support for the SHA-1 hash throughout the `gix` stack.
Expand Down Expand Up @@ -120,6 +120,13 @@ sha1 = [
"gix-worktree-stream?/sha1",
]

## Enable support for the SHA-256 hash throughout the `gix` stack.
##
## Note that, as of 2026-03-02, only `gix-hash` offers that flag yet.
sha256 = [
"gix-hash/sha256",
]

#! #### Components
#!
#! A component is a distinct feature which may be comprised of one or more methods around a particular topic.
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ check:
cargo check -p gix --no-default-features --features interrupt --tests
cargo check -p gix --no-default-features --features blame --tests
cargo check -p gix --no-default-features --features sha1
cargo check -p gix --no-default-features --features sha1,sha256
cargo check -p gix --no-default-features 2>&1 >/dev/null | grep 'Please set either the `sha1` or the `sha256` feature flag'
cargo check -p gix-odb --features serde 2>&1 >/dev/null | grep 'Please set either the `sha1` or the `sha256` feature flag'
cargo check -p gix-odb --features sha1,serde
cargo check --no-default-features --features max-control,sha1
Expand Down Expand Up @@ -230,6 +232,8 @@ unit-tests:
cargo nextest run -p gix-protocol --features blocking-client --no-fail-fast
cargo nextest run -p gix-protocol --features async-client --no-fail-fast
cargo nextest run -p gix-blame --no-fail-fast
env GIX_TEST_FIXTURE_HASH=sha1 cargo nextest run -p gix-refspec --no-fail-fast
env GIX_TEST_FIXTURE_HASH=sha256 cargo nextest run -p gix-refspec --no-fail-fast
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ignore sha256 match baseline archive output

Running this newly added sha256 test command causes gix-testtools to look for gix-refspec/tests/fixtures/generated-archives/match_baseline_sha256.tar; when it is missing, the fixture runner creates it, and generated-archives/.gitignore currently excludes only /match_baseline.tar. That means unit-tests now leaves a new untracked binary file behind on normal local runs, which is a regression for workflows that expect a clean worktree after tests.

Useful? React with 👍 / 👎.

cargo nextest run -p gix --no-default-features --no-fail-fast
cargo nextest run -p gix --no-default-features --features basic,comfort,max-performance-safe --no-fail-fast
cargo nextest run -p gix --no-default-features --features basic,extras,comfort,need-more-recent-msrv --no-fail-fast
Expand Down
11 changes: 9 additions & 2 deletions tests/tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,15 +1266,22 @@ where
Ok((script_result_directory, res))
}

fn hash_kind_from_env() -> gix_hash::Kind {
env::var_os("GIX_TEST_FIXTURE_HASH").and_then(|value| value.into_string().ok()).map(|object_kind| {
/// Returns the hash function that is used when creating or loading test fixtures. The value
/// returned is derived from the environment variable `GIX_TEST_FIXTURE_HASH`. Use this, e. g.,
/// when you need to run different assertions depending on the hash function used in a specific
/// fixture.
pub fn hash_kind_from_env() -> gix_hash::Kind {
static FIXTURE_HASH: LazyLock<gix_hash::Kind> = LazyLock::new(|| {
env::var_os("GIX_TEST_FIXTURE_HASH").and_then(|value| value.into_string().ok()).map(|object_kind| {
gix_hash::Kind::from_str(&object_kind).unwrap_or_else(|_| {
panic!(
"GIX_TEST_FIXTURE_HASH was set to {object_kind} which is an invalid value. Valid values are {}. Exiting.",
gix_hash::Kind::all().iter().map(std::string::ToString::to_string).collect::<Vec<_>>().join(", ")
)
})
}).unwrap_or_default()
});
*FIXTURE_HASH
}

#[cfg(windows)]
Expand Down
Loading