diff --git a/gix-refspec/Cargo.toml b/gix-refspec/Cargo.toml index f094903805..6000738ae8 100644 --- a/gix-refspec/Cargo.toml +++ b/gix-refspec/Cargo.toml @@ -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.3" [package.metadata.docs.rs] diff --git a/gix-refspec/tests/fixtures/generated-archives/parse_baseline_sha256.tar b/gix-refspec/tests/fixtures/generated-archives/parse_baseline_sha256.tar new file mode 100644 index 0000000000..947fbb4c7a Binary files /dev/null and b/gix-refspec/tests/fixtures/generated-archives/parse_baseline_sha256.tar differ diff --git a/gix-refspec/tests/fixtures/match_baseline.sh b/gix-refspec/tests/fixtures/match_baseline.sh index 74980db9dd..c068b6c0e0 100755 --- a/gix-refspec/tests/fixtures/match_baseline.sh +++ b/gix-refspec/tests/fixtures/match_baseline.sh @@ -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" diff --git a/gix-refspec/tests/refspec/match_group.rs b/gix-refspec/tests/refspec/match_group.rs index 032dc36033..845d68d6d6 100644 --- a/gix-refspec/tests/refspec/match_group.rs +++ b/gix-refspec/tests/refspec/match_group.rs @@ -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"]); diff --git a/gix-refspec/tests/refspec/spec.rs b/gix-refspec/tests/refspec/spec.rs index 4b31a14474..1a17db24e4 100644 --- a/gix-refspec/tests/refspec/spec.rs +++ b/gix-refspec/tests/refspec/spec.rs @@ -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 { @@ -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 { diff --git a/gix/Cargo.toml b/gix/Cargo.toml index ccde5a2270..52fceed453 100644 --- a/gix/Cargo.toml +++ b/gix/Cargo.toml @@ -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. @@ -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. diff --git a/justfile b/justfile index 9e4663c678..8435909f23 100755 --- a/justfile +++ b/justfile @@ -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 @@ -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 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 diff --git a/tests/tools/src/lib.rs b/tests/tools/src/lib.rs index f236f8ea00..5d01e02876 100644 --- a/tests/tools/src/lib.rs +++ b/tests/tools/src/lib.rs @@ -1266,8 +1266,13 @@ 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 = 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.", @@ -1275,6 +1280,8 @@ fn hash_kind_from_env() -> gix_hash::Kind { ) }) }).unwrap_or_default() + }); + *FIXTURE_HASH } #[cfg(windows)]