Skip to content

Commit fbb2e6e

Browse files
authored
Merge pull request #2542 from cruessler/run-gix-blame-tests-with-sha-256
Use `GIX_TEST_FIXTURE_HASH` for `gix-blame`
2 parents 0771cb2 + e20122a commit fbb2e6e

6 files changed

Lines changed: 25 additions & 9 deletions

File tree

gix-blame/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ smallvec = "1.15.1"
3939
thiserror = "2.0.18"
4040

4141
[dev-dependencies]
42-
gix-ref = { path = "../gix-ref" }
42+
gix-hash = { path = "../gix-hash", features = ["sha1", "sha256"] }
43+
gix-ref = { path = "../gix-ref", features = ["sha1", "sha256"] }
4344
gix-filter = { path = "../gix-filter" }
4445
gix-fs = { path = "../gix-fs" }
45-
gix-index = { path = "../gix-index" }
46-
gix-odb = { path = "../gix-odb" }
46+
gix-index = { path = "../gix-index", features = ["sha1"] }
47+
gix-odb = { path = "../gix-odb", features = ["sha1"] }
4748
gix-testtools = { path = "../tests/tools" }
4849
pretty_assertions = "1.4.0"
4950

gix-blame/tests/blame.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use gix_blame::BlameRanges;
44
use gix_hash::ObjectId;
55
use gix_object::bstr;
66

7+
fn fixture_hash_kind() -> gix_hash::Kind {
8+
gix_testtools::hash_kind_from_env().unwrap_or_default()
9+
}
10+
711
struct Baseline<'a> {
812
lines: bstr::Lines<'a>,
913
filenames: BTreeMap<ObjectId, bstr::BString>,
@@ -16,7 +20,7 @@ mod baseline {
1620
use gix_hash::ObjectId;
1721
use gix_ref::bstr::ByteSlice;
1822

19-
use super::Baseline;
23+
use super::{fixture_hash_kind, Baseline};
2024

2125
// These fields are used by `git` in its porcelain output.
2226
const HEADER_FIELDS: [&str; 12] = [
@@ -73,7 +77,7 @@ mod baseline {
7377

7478
fn next(&mut self) -> Option<Self::Item> {
7579
let mut ranges = None;
76-
let mut commit_id = gix_hash::Kind::Sha1.null();
80+
let mut commit_id = fixture_hash_kind().null();
7781
let mut skip_lines: u32 = 0;
7882
let mut source_file_name: Option<gix_object::bstr::BString> = None;
7983

@@ -155,14 +159,23 @@ impl Fixture {
155159
fn for_worktree_path(worktree_path: PathBuf) -> gix_testtools::Result<Fixture> {
156160
use gix_ref::store::WriteReflog;
157161

162+
let object_hash = fixture_hash_kind();
158163
let store = gix_ref::file::Store::at(
159164
worktree_path.join(".git"),
160165
gix_ref::store::init::Options {
161166
write_reflog: WriteReflog::Disable,
167+
object_hash,
162168
..Default::default()
163169
},
164170
);
165-
let odb = gix_odb::at(worktree_path.join(".git/objects"))?;
171+
let odb = gix_odb::at_opts(
172+
worktree_path.join(".git/objects"),
173+
Vec::new(),
174+
gix_odb::store::init::Options {
175+
object_hash,
176+
..Default::default()
177+
},
178+
)?;
166179

167180
let mut reference = gix_ref::file::Store::find(&store, "HEAD")?;
168181

@@ -172,7 +185,7 @@ impl Fixture {
172185
let head_id = reference.peel_to_id(&store, &odb)?;
173186

174187
let git_dir = worktree_path.join(".git");
175-
let index = gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, false, Default::default())?;
188+
let index = gix_index::File::at(git_dir.join("index"), object_hash, false, Default::default())?;
176189
let stack = gix_worktree::Stack::from_state_and_ignore_case(
177190
worktree_path.clone(),
178191
false,
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
make_blame_repo.tar
1+
make_blame_repo.tar
2+
make_blame_repo_sha256.tar
Binary file not shown.
Binary file not shown.

justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ unit-tests:
241241
cargo nextest run -p gix-transport --features async-client --no-fail-fast
242242
cargo nextest run -p gix-protocol --features blocking-client --no-fail-fast
243243
cargo nextest run -p gix-protocol --features async-client --no-fail-fast
244-
cargo nextest run -p gix-blame --no-fail-fast
244+
env GIX_TEST_FIXTURE_HASH=sha1 cargo nextest run -p gix-blame --no-fail-fast
245+
env GIX_TEST_FIXTURE_HASH=sha256 cargo nextest run -p gix-blame --no-fail-fast
245246
env GIX_TEST_FIXTURE_HASH=sha1 cargo nextest run -p gix-refspec --no-fail-fast
246247
env GIX_TEST_FIXTURE_HASH=sha256 cargo nextest run -p gix-refspec --no-fail-fast
247248
cargo nextest run -p gix --no-default-features --no-fail-fast

0 commit comments

Comments
 (0)