1
1
//! Utilities for testing `gitoxide` crates, many of which might be useful for testing programs that use `git` in general.
2
+ //!
3
+ //! ## Feature Flags
4
+ #![ cfg_attr(
5
+ all( doc, feature = "document-features" ) ,
6
+ doc = :: document_features:: document_features!( )
7
+ ) ]
8
+ #![ cfg_attr( all( doc, feature = "document-features" ) , feature( doc_cfg, doc_auto_cfg) ) ]
2
9
#![ deny( missing_docs) ]
3
10
4
11
use std:: {
@@ -269,7 +276,7 @@ fn fixture_bytes_inner(path: impl AsRef<Path>, root: DirectoryRoot) -> Vec<u8> {
269
276
/// #### Disable Archive Creation
270
277
///
271
278
/// If archives aren't useful, they can be disabled by using `.gitignore` specifications.
272
- /// That way it's trivial to prevent creation of all archives with `generated-archives/*.tar.xz` in the root
279
+ /// That way it's trivial to prevent creation of all archives with `generated-archives/*.tar{ .xz} ` in the root
273
280
/// or more specific `.gitignore` configurations in lower levels of the work tree.
274
281
///
275
282
/// The latter is useful if the script's output is platform specific.
@@ -407,7 +414,11 @@ fn scripted_fixture_read_only_with_args_inner(
407
414
408
415
let script_basename = script_location. file_stem ( ) . unwrap_or ( script_location. as_os_str ( ) ) ;
409
416
let archive_file_path = fixture_path_inner (
410
- Path :: new ( "generated-archives" ) . join ( format ! ( "{}.tar.xz" , script_basename. to_str( ) . expect( "valid UTF-8" ) ) ) ,
417
+ Path :: new ( "generated-archives" ) . join ( format ! (
418
+ "{}.tar{}" ,
419
+ script_basename. to_str( ) . expect( "valid UTF-8" ) ,
420
+ if cfg!( feature = "xz" ) { ".xz" } else { "" }
421
+ ) ) ,
411
422
root,
412
423
) ;
413
424
let ( force_run, script_result_directory) = destination_dir. map_or_else (
@@ -566,14 +577,24 @@ fn create_archive_if_not_on_ci(source_dir: &Path, archive: &Path, script_identit
566
577
ar. append_dir_all ( "." , source_dir) ?;
567
578
ar. finish ( ) ?;
568
579
}
569
- let archive = std:: fs:: OpenOptions :: new ( )
580
+ #[ cfg_attr( feature = "xz" , allow( unused_mut) ) ]
581
+ let mut archive = std:: fs:: OpenOptions :: new ( )
570
582
. write ( true )
571
583
. create ( true )
572
584
. truncate ( true )
573
585
. open ( archive) ?;
574
- let mut xz_write = xz2:: write:: XzEncoder :: new ( archive, 3 ) ;
575
- std:: io:: copy ( & mut & * buf, & mut xz_write) ?;
576
- xz_write. finish ( ) ?. close ( )
586
+ #[ cfg( feature = "xz" ) ]
587
+ {
588
+ let mut xz_write = xz2:: write:: XzEncoder :: new ( archive, 3 ) ;
589
+ std:: io:: copy ( & mut & * buf, & mut xz_write) ?;
590
+ xz_write. finish ( ) ?. close ( )
591
+ }
592
+ #[ cfg( not( feature = "xz" ) ) ]
593
+ {
594
+ use std:: io:: Write ;
595
+ archive. write_all ( & buf) ?;
596
+ archive. close ( )
597
+ }
577
598
} ) ( ) ;
578
599
#[ cfg( not( windows) ) ]
579
600
std:: fs:: remove_dir_all ( meta_dir) ?;
@@ -629,7 +650,8 @@ fn extract_archive(
629
650
) -> std:: io:: Result < ( u32 , Option < String > ) > {
630
651
let archive_buf: Vec < u8 > = {
631
652
let mut buf = Vec :: new ( ) ;
632
- let input_archive = std:: fs:: File :: open ( archive) ?;
653
+ #[ cfg_attr( feature = "xz" , allow( unused_mut) ) ]
654
+ let mut input_archive = std:: fs:: File :: open ( archive) ?;
633
655
if std:: env:: var_os ( "GIX_TEST_IGNORE_ARCHIVES" ) . is_some ( ) {
634
656
return Err ( std:: io:: Error :: new (
635
657
std:: io:: ErrorKind :: Other ,
@@ -639,8 +661,16 @@ fn extract_archive(
639
661
) ,
640
662
) ) ;
641
663
}
642
- let mut decoder = xz2:: bufread:: XzDecoder :: new ( std:: io:: BufReader :: new ( input_archive) ) ;
643
- std:: io:: copy ( & mut decoder, & mut buf) ?;
664
+ #[ cfg( feature = "xz" ) ]
665
+ {
666
+ let mut decoder = xz2:: bufread:: XzDecoder :: new ( std:: io:: BufReader :: new ( input_archive) ) ;
667
+ std:: io:: copy ( & mut decoder, & mut buf) ?;
668
+ }
669
+ #[ cfg( not( feature = "xz" ) ) ]
670
+ {
671
+ use std:: io:: Read ;
672
+ input_archive. read_to_end ( & mut buf) ?;
673
+ }
644
674
buf
645
675
} ;
646
676
0 commit comments