Skip to content

gix-testtools - tar only #1415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2024
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gix-archive/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
basic.tar.xz
basic.tar
Original file line number Diff line number Diff line change
@@ -1 +1 @@
make_attributes_baseline.tar.xz
make_attributes_baseline.tar
2 changes: 1 addition & 1 deletion gix-command/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
win_path_lookup.tar.xz
win_path_lookup.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.
2 changes: 1 addition & 1 deletion gix-config/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/make_config_repo.tar.xz
/make_config_repo.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.
4 changes: 2 additions & 2 deletions gix-dir/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
many.tar.xz
many-symlinks.tar.xz
many.tar
many-symlinks.tar
2 changes: 1 addition & 1 deletion gix-discover/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/make_basic_repo.tar.xz
/make_basic_repo.tar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion gix-filter/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/baseline.tar.xz
/baseline.tar
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion gix-fsck/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
make_test_repos.tar.xz
make_test_repos.tar
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion gix-ignore/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
make_global_and_external_and_dir_ignores.tar.xz
make_global_and_external_and_dir_ignores.tar
2 changes: 1 addition & 1 deletion gix-index/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
file_metadata.tar.xz
file_metadata.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.
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.
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.
4 changes: 2 additions & 2 deletions gix-odb/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
repo_with_loose_objects.tar.xz
make_alternates_odb.tar.xz
repo_with_loose_objects.tar
make_alternates_odb.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.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion gix-ref/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
make_worktree_repo.tar.xz
make_worktree_repo.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.
2 changes: 1 addition & 1 deletion gix-refspec/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/match_baseline.tar.xz
/match_baseline.tar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions gix-status/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
status_unchanged.tar.xz
status_changed.tar.xz
symlink_stack.tar.xz
status_unchanged.tar
status_changed.tar
symlink_stack.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.
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.
2 changes: 1 addition & 1 deletion gix-url/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
make_baseline.tar.xz
make_baseline.tar
14 changes: 7 additions & 7 deletions gix-worktree-state/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
make_ignore_and_attributes_setup.tar.xz
make_mixed_without_submodules.tar.xz
make_mixed.tar.xz
make_mixed_without_submodules_and_symlinks.tar.xz
make_attributes_baseline.tar.xz
make_dangerous_symlink.tar.xz
make_ignorecase_collisions.tar.xz
make_ignore_and_attributes_setup.tar
make_mixed_without_submodules.tar
make_mixed.tar
make_mixed_without_submodules_and_symlinks.tar
make_attributes_baseline.tar
make_dangerous_symlink.tar
make_ignorecase_collisions.tar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
basic.tar.xz
basic.tar
6 changes: 3 additions & 3 deletions gix-worktree/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
make_ignore_and_attributes_setup.tar.xz
make_attributes_baseline.tar.xz
symlink_stack.tar.xz
make_ignore_and_attributes_setup.tar
make_attributes_baseline.tar
symlink_stack.tar
Binary file not shown.
Binary file not shown.
14 changes: 7 additions & 7 deletions gix/tests/fixtures/generated-archives/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/make_worktree_repo.tar.xz
/make_worktree_repo_with_configs.tar.xz
/make_remote_repos.tar.xz
/make_complex_shallow_repo.tar.xz
/make_fetch_repos.tar.xz
/make_core_worktree_repo.tar.xz
/make_signatures_repo.tar.xz
/make_worktree_repo.tar
/make_worktree_repo_with_configs.tar
/make_remote_repos.tar
/make_complex_shallow_repo.tar
/make_fetch_repos.tar
/make_core_worktree_repo.tar
/make_signatures_repo.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.
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.
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ doc $RUSTDOCFLAGS="-D warnings":
# run all unit tests
unit-tests:
cargo test --all
cargo test -p gix-testtools
cargo test -p gix-testtools --features xz
cargo test -p gix-archive --no-default-features
cargo test -p gix-archive --features tar
cargo test -p gix-archive --features tar_gz
Expand Down
15 changes: 14 additions & 1 deletion tests/tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ path = "src/main.rs"
[lib]
doctest = false

[features]
default = []
## Use instead of plain `tar` files, compress these to produce `tar.xz` files instead.
## This is useful if archives are uploaded into `git-lfs`, which doesn't have built-in compression
## and metering counts towards uncompressed bytes transferred.
xz = ["dep:xz2"]

[dependencies]
gix-lock = "14.0.0"
gix-discover = "0.32.0"
Expand All @@ -35,4 +42,10 @@ parking_lot = { version = "0.12.0" }
is_ci = "1.1.1"
io-close = "0.3.7"
tar = { version = "0.4.38", default-features = false }
xz2 = "0.1.6"
xz2 = { version = "0.1.6", optional = true }

document-features = { version = "0.2.1", optional = true }

[package.metadata.docs.rs]
all-features = true
features = ["document-features"]
48 changes: 39 additions & 9 deletions tests/tools/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
//! Utilities for testing `gitoxide` crates, many of which might be useful for testing programs that use `git` in general.
//!
//! ## Feature Flags
#![cfg_attr(
all(doc, feature = "document-features"),
doc = ::document_features::document_features!()
)]
#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))]
#![deny(missing_docs)]

use std::{
Expand Down Expand Up @@ -269,7 +276,7 @@ fn fixture_bytes_inner(path: impl AsRef<Path>, root: DirectoryRoot) -> Vec<u8> {
/// #### Disable Archive Creation
///
/// If archives aren't useful, they can be disabled by using `.gitignore` specifications.
/// That way it's trivial to prevent creation of all archives with `generated-archives/*.tar.xz` in the root
/// That way it's trivial to prevent creation of all archives with `generated-archives/*.tar{.xz}` in the root
/// or more specific `.gitignore` configurations in lower levels of the work tree.
///
/// The latter is useful if the script's output is platform specific.
Expand Down Expand Up @@ -407,7 +414,11 @@ fn scripted_fixture_read_only_with_args_inner(

let script_basename = script_location.file_stem().unwrap_or(script_location.as_os_str());
let archive_file_path = fixture_path_inner(
Path::new("generated-archives").join(format!("{}.tar.xz", script_basename.to_str().expect("valid UTF-8"))),
Path::new("generated-archives").join(format!(
"{}.tar{}",
script_basename.to_str().expect("valid UTF-8"),
if cfg!(feature = "xz") { ".xz" } else { "" }
)),
root,
);
let (force_run, script_result_directory) = destination_dir.map_or_else(
Expand Down Expand Up @@ -566,14 +577,24 @@ fn create_archive_if_not_on_ci(source_dir: &Path, archive: &Path, script_identit
ar.append_dir_all(".", source_dir)?;
ar.finish()?;
}
let archive = std::fs::OpenOptions::new()
#[cfg_attr(feature = "xz", allow(unused_mut))]
let mut archive = std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(archive)?;
let mut xz_write = xz2::write::XzEncoder::new(archive, 3);
std::io::copy(&mut &*buf, &mut xz_write)?;
xz_write.finish()?.close()
#[cfg(feature = "xz")]
{
let mut xz_write = xz2::write::XzEncoder::new(archive, 3);
std::io::copy(&mut &*buf, &mut xz_write)?;
xz_write.finish()?.close()
}
#[cfg(not(feature = "xz"))]
{
use std::io::Write;
archive.write_all(&buf)?;
archive.close()
}
})();
#[cfg(not(windows))]
std::fs::remove_dir_all(meta_dir)?;
Expand Down Expand Up @@ -629,7 +650,8 @@ fn extract_archive(
) -> std::io::Result<(u32, Option<String>)> {
let archive_buf: Vec<u8> = {
let mut buf = Vec::new();
let input_archive = std::fs::File::open(archive)?;
#[cfg_attr(feature = "xz", allow(unused_mut))]
let mut input_archive = std::fs::File::open(archive)?;
if std::env::var_os("GIX_TEST_IGNORE_ARCHIVES").is_some() {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
Expand All @@ -639,8 +661,16 @@ fn extract_archive(
),
));
}
let mut decoder = xz2::bufread::XzDecoder::new(std::io::BufReader::new(input_archive));
std::io::copy(&mut decoder, &mut buf)?;
#[cfg(feature = "xz")]
{
let mut decoder = xz2::bufread::XzDecoder::new(std::io::BufReader::new(input_archive));
std::io::copy(&mut decoder, &mut buf)?;
}
#[cfg(not(feature = "xz"))]
{
use std::io::Read;
input_archive.read_to_end(&mut buf)?;
}
buf
};

Expand Down
Loading