Skip to content
Merged
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-index/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
# range (e.g., ext4 vs HFS+/APFS vs NTFS), so they cannot be round-tripped
# through a committed tar — the fixture must be regenerated per host.
file_metadata.tar
file_metadata_sha256.tar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified gix-index/tests/fixtures/generated-archives/v2_empty.tar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 10 additions & 1 deletion gix-index/tests/fixtures/make_index/v2_empty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
set -eu -o pipefail

git init -q
git read-tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904

# Create an empty index.
case ${GIX_TEST_FIXTURE_HASH:-sha1} in
sha1)
git read-tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 ;;
sha256)
git read-tree 6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321 ;;
*)
Comment thread
Byron marked this conversation as resolved.
exit 1 ;;
esac
22 changes: 18 additions & 4 deletions gix-index/tests/index/file/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod at_or_new {
fn opens_existing() {
gix_index::File::at_or_default(
Generated("v4_more_files_IEOT").to_path(),
gix_hash::Kind::Sha1,
gix_testtools::object_hash(),
false,
Default::default(),
)
Expand All @@ -16,13 +16,17 @@ mod at_or_new {
fn create_empty_in_memory_state_if_file_does_not_exist() {
let index = gix_index::File::at_or_default(
"__definitely no file that exists ever__",
gix_hash::Kind::Sha1,
gix_testtools::object_hash(),
false,
Default::default(),
)
.expect("file is defaulting to a new one");
assert!(!index.path().is_file(), "the file wasn't created yet");
assert_eq!(index.object_hash(), gix_hash::Kind::Sha1, "object hash is respected");
assert_eq!(
index.object_hash(),
gix_testtools::object_hash(),
"object hash is respected"
);
assert_eq!(index.entries().len(), 0, "index is empty");
}
}
Expand All @@ -44,11 +48,21 @@ mod from_state {
];

for (fixture, expected_version) in fixtures {
// Loose fixtures are pre-created and only exist as SHA-1 variants.
if gix_testtools::object_hash() != gix_hash::Kind::Sha1 && matches!(fixture, Loose(_)) {
continue;
}

let tmp = gix_testtools::tempfile::TempDir::new()?;
let new_index_path = tmp.path().join(fixture.to_name());
assert!(!new_index_path.exists());

let index = gix_index::File::at(fixture.to_path(), gix_hash::Kind::Sha1, false, Default::default())?;
let index = gix_index::File::at(
fixture.to_path(),
gix_testtools::object_hash(),
false,
Default::default(),
)?;
let mut index = gix_index::File::from_state(index.into(), new_index_path.clone());
assert!(index.checksum().is_none());
assert_eq!(index.path(), new_index_path);
Expand Down
77 changes: 49 additions & 28 deletions gix-index/tests/index/file/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use gix_index::{
Version,
entry::{self, Flags, Mode},
};
use gix_testtools::normalize_debug_snapshot;

use crate::{Fixture, hex_to_id, loose_file_path};

Expand All @@ -20,25 +21,36 @@ pub(crate) fn loose_file(name: &str) -> gix_index::File {
let file = gix_index::File::at(path, gix_hash::Kind::Sha1, false, Default::default()).unwrap();
verify(file)
}

pub(crate) fn try_file(name: &str, needs_archive: bool) -> Result<gix_index::File, gix_index::file::init::Error> {
let path = if needs_archive {
crate::fixture_index_path_needs_archive(name)
} else {
crate::fixture_index_path(name)
};
let file = gix_index::File::at(path, gix_hash::Kind::Sha1, false, Default::default())?;
let object_hash = gix_testtools::object_hash();
let file = gix_index::File::at(path, object_hash, false, Default::default())?;
Ok(verify(file))
}

pub(crate) fn file(name: &str) -> gix_index::File {
try_file(name, false).unwrap()
}

/// Needed if we have to freeze the fixture if contents depends on filesystem traversal order
/// This is Ok and similar to our manual copies of indices, except that it can be regenerated.
fn file_needs_archive(name: &str) -> gix_index::File {
try_file(name, true).unwrap()
}

fn file_opt(name: &str, opts: gix_index::decode::Options) -> gix_index::File {
let file = gix_index::File::at(crate::fixture_index_path(name), gix_hash::Kind::Sha1, false, opts).unwrap();
let file = gix_index::File::at(
crate::fixture_index_path(name),
gix_testtools::object_hash(),
false,
opts,
)
.unwrap();
verify(file)
}

Expand All @@ -58,6 +70,7 @@ fn with_index_file_snapshot_filters(has_stable_mtimes: bool, run: impl FnOnce())
let mut filters = vec![
(r#"(path: )"[^"]*""#, r#"$1"[redacted]""#),
(r#"(identifier: )"[^"]*""#, r#"$1"[redacted]""#),
(r"(object_hash: )Sha(1|256)", "$1[redacted]"),
Comment thread
Byron marked this conversation as resolved.
(
r"(?s)FileTime \{\s+seconds: \d+,\s+nanos: \d+,\s+\}",
"FileTime { ... }",
Expand Down Expand Up @@ -117,6 +130,10 @@ fn v2_empty() {

#[test]
fn v2_empty_skip_hash() {
if gix_testtools::object_hash() != gix_hash::Kind::Sha1 {
return;
}
Comment thread
Byron marked this conversation as resolved.

let file = loose_file("skip_hash");
assert_eq!(file.version(), Version::V2);
assert_eq!(file.entries().len(), 0);
Expand All @@ -134,6 +151,10 @@ fn v2_empty_skip_hash() {

#[test]
fn v2_with_multiple_entries_without_eoie_ext() {
if gix_testtools::object_hash() != gix_hash::Kind::Sha1 {
return;
}

let file = file_needs_archive("v2_more_files");
with_index_file_snapshot_filters(true, || {
insta::assert_snapshot!(format!("{file:#?}"), @r#"
Expand All @@ -142,7 +163,7 @@ fn v2_with_multiple_entries_without_eoie_ext() {
checksum: Some(
Sha1(43bcf12743f506ab5fefaf13f8f5a7eed3d747fe),
),
object_hash: Sha1,
object_hash: [redacted],
timestamp: FileTime { ... },
version: V2,
entries: [
Expand Down Expand Up @@ -201,7 +222,7 @@ fn find_shared_index_for(index: impl AsRef<Path>) -> PathBuf {
fn split_index_without_any_extension() {
let file = gix_index::File::at(
find_shared_index_for(crate::fixture_index_path("v2_split_index")),
gix_hash::Kind::Sha1,
gix_testtools::object_hash(),
false,
Default::default(),
)
Expand Down Expand Up @@ -267,19 +288,19 @@ fn untr_extension_empty() {
let file = file_needs_archive("untracked_cache_empty");

with_index_file_snapshot_filters(false, || {
insta::assert_debug_snapshot!(&file, @r#"
insta::assert_snapshot!(normalize_debug_snapshot(&file).0, @r#"
Comment thread
Byron marked this conversation as resolved.
File {
path: "[redacted]",
checksum: Some(
Sha1(e6e8bff2dab8feaa4cf41fd352248b0fc10acb56),
Oid(1),
),
object_hash: Sha1,
object_hash: [redacted],
timestamp: FileTime { ... },
version: V2,
entries: [
Mode(FILE) e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 tracked-dir/tracked-file,
Mode(FILE) e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 tracked-root-one,
Mode(FILE) e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 tracked-root-two,
Mode(FILE) Oid(2) tracked-dir/tracked-file,
Mode(FILE) Oid(2) tracked-root-one,
Mode(FILE) Oid(2) tracked-root-two,
],
path_backing_size_bytes: 56,
is_sparse: false,
Expand Down Expand Up @@ -309,19 +330,19 @@ fn untr_extension_populated() {
let file = file_needs_archive("untracked_cache_populated");

with_index_file_snapshot_filters(true, || {
insta::assert_debug_snapshot!(&file, @r#"
insta::assert_snapshot!(normalize_debug_snapshot(&file).0, @r#"
File {
path: "[redacted]",
checksum: Some(
Sha1(dabefe909b6858676ca56f46db0d9a30ad0d2a97),
Oid(1),
),
object_hash: Sha1,
object_hash: [redacted],
timestamp: FileTime { ... },
version: V2,
entries: [
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 tracked-dir/tracked-file,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 tracked-root-one,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 tracked-root-two,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } Oid(2) tracked-dir/tracked-file,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } Oid(2) tracked-root-one,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } Oid(2) tracked-root-two,
],
path_backing_size_bytes: 56,
is_sparse: false,
Expand All @@ -336,7 +357,7 @@ fn untr_extension_populated() {
info_exclude: Some(
OidStat {
stat: Stat { mtime: Time { secs: 2147483647, nsecs: 123456789 }, ctime: Time { ... }, ... },
id: Sha1(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391),
id: Oid(2),
},
),
excludes_file: None,
Expand Down Expand Up @@ -413,20 +434,20 @@ fn untr_extension_nested() {
let file = file_needs_archive("untracked_cache_nested");

with_index_file_snapshot_filters(true, || {
insta::assert_debug_snapshot!(&file, @r#"
insta::assert_snapshot!(normalize_debug_snapshot(&file).0, @r#"
File {
path: "[redacted]",
checksum: Some(
Sha1(bf50cd966cc718b67d3a326d01aa111f78901c1e),
Oid(1),
),
object_hash: Sha1,
object_hash: [redacted],
timestamp: FileTime { ... },
version: V2,
entries: [
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } 55535cdccae965cd0ea191aa22df1145a983b2f9 tracked-dir-with-ignore/.gitignore,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 tracked-dir-with-ignore/tracked-file,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 tracked-root-one,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 tracked-root-two,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } Oid(2) tracked-dir-with-ignore/.gitignore,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } Oid(3) tracked-dir-with-ignore/tracked-file,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } Oid(3) tracked-root-one,
Mode(FILE) mtime: Time { secs: 2147483647, nsecs: 123456789 } Oid(3) tracked-root-two,
],
path_backing_size_bytes: 102,
is_sparse: false,
Expand All @@ -441,7 +462,7 @@ fn untr_extension_nested() {
info_exclude: Some(
OidStat {
stat: Stat { mtime: Time { secs: 2147483647, nsecs: 123456789 }, ctime: Time { ... }, ... },
id: Sha1(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391),
id: Oid(3),
},
),
excludes_file: None,
Expand Down Expand Up @@ -479,7 +500,7 @@ fn untr_extension_nested() {
Stat { mtime: Time { secs: 2147483647, nsecs: 123456789 }, ctime: Time { ... }, ... },
),
exclude_file_oid: Some(
Sha1(55535cdccae965cd0ea191aa22df1145a983b2f9),
Oid(2),
),
check_only: false,
},
Expand Down Expand Up @@ -681,7 +702,7 @@ fn split_index_and_regular_index_of_same_content_are_indeed_the_same() {
let split = verify(
gix_index::File::at(
base.join("split/.git/index"),
gix_hash::Kind::Sha1,
gix_testtools::object_hash(),
false,
Default::default(),
)
Expand All @@ -696,7 +717,7 @@ fn split_index_and_regular_index_of_same_content_are_indeed_the_same() {
let regular = verify(
gix_index::File::at(
base.join("regular/.git/index"),
gix_hash::Kind::Sha1,
gix_testtools::object_hash(),
false,
Default::default(),
)
Expand Down
29 changes: 25 additions & 4 deletions gix-index/tests/index/file/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ fn roundtrips() -> crate::Result {
];

for (fixture, options) in input {
// Loose fixtures only exist as SHA-1 version.
if gix_testtools::object_hash() != gix_hash::Kind::Sha1 && matches!(fixture, Loose(_)) {
continue;
}

let expected = fixture.open();
let expected_bytes = std::fs::read(fixture.to_path())?;
let mut out_bytes = Vec::new();

let (actual_version, _digest) = expected.write_to(&mut out_bytes, options)?;
let (actual, _) = State::from_bytes(&out_bytes, FileTime::now(), gix_hash::Kind::Sha1, Default::default())?;
let (actual, _) = State::from_bytes(
&out_bytes,
FileTime::now(),
gix_testtools::object_hash(),
Default::default(),
)?;

let name = fixture.to_name();
compare_states_against_baseline(&actual, actual_version, &expected, options, name);
Expand Down Expand Up @@ -109,7 +119,12 @@ fn roundtrips_sparse_index() -> crate::Result {
let mut out_bytes = Vec::new();

let (actual_version, _) = expected.write_to(&mut out_bytes, options)?;
let (actual, _) = State::from_bytes(&out_bytes, FileTime::now(), gix_hash::Kind::Sha1, Default::default())?;
let (actual, _) = State::from_bytes(
&out_bytes,
FileTime::now(),
gix_testtools::object_hash(),
Default::default(),
)?;

compare_states_against_baseline(&actual, actual_version, &expected, options, fixture.to_name());
// TODO: make this work and re-enable it, once this is done the fixtures can be merged into the main "roundtrip" test
Expand Down Expand Up @@ -143,6 +158,11 @@ fn state_comparisons_with_various_extension_configurations() {
// TODO: this fails because git writes the sdir extension in this case while gitoxide doesn't
// Generated("v2_sparse_index_no_dirs"),
] {
// Loose fixtures only exist as SHA-1 version.
if gix_testtools::object_hash() != gix_hash::Kind::Sha1 && matches!(fixture, Loose(_)) {
continue;
}

for options in [
options_with(write::Extensions::None),
options_with(write::Extensions::All),
Expand All @@ -162,7 +182,7 @@ fn state_comparisons_with_various_extension_configurations() {
let (actual_version, _digest) = expected.write_to(&mut out, options).unwrap();

let (actual, _) =
State::from_bytes(&out, FileTime::now(), gix_hash::Kind::Sha1, Default::default()).unwrap();
State::from_bytes(&out, FileTime::now(), gix_testtools::object_hash(), Default::default()).unwrap();
compare_states(&actual, actual_version, &expected, options, fixture);
}
}
Expand Down Expand Up @@ -193,7 +213,8 @@ fn remove_flag_is_respected() -> crate::Result {
let mut buf = Vec::<u8>::new();
index.write_to(&mut buf, Default::default())?;

let (state, _checksum) = State::from_bytes(&buf, FileTime::now(), gix_hash::Kind::Sha1, Default::default())?;
let (state, _checksum) =
State::from_bytes(&buf, FileTime::now(), gix_testtools::object_hash(), Default::default())?;
assert_eq!(
state.entries().len(),
total_entries - entries_to_remove,
Expand Down
Loading
Loading