@@ -432,6 +432,7 @@ mod find {
432
432
use gix_pack:: Find ;
433
433
434
434
use crate :: basic_repo;
435
+ use crate :: repository:: object:: empty_bare_in_memory_repo;
435
436
436
437
#[ test]
437
438
fn find_and_try_find_with_and_without_object_cache ( ) -> crate :: Result {
@@ -515,9 +516,12 @@ mod find {
515
516
fn empty_blob_can_be_found_if_it_exists ( ) -> crate :: Result {
516
517
let repo = basic_repo ( ) ?;
517
518
let empty_blob = gix:: hash:: ObjectId :: empty_blob ( repo. object_hash ( ) ) ;
518
-
519
- // The basic_repo fixture contains an empty blob, so these should work
520
- assert_eq ! ( repo. find_object( empty_blob) ?. into_blob( ) . data. len( ) , 0 ) ;
519
+
520
+ assert_eq ! (
521
+ repo. find_object( empty_blob) ?. into_blob( ) . data. len( ) ,
522
+ 0 ,
523
+ "The basic_repo fixture contains an empty blob"
524
+ ) ;
521
525
assert ! ( repo. has_object( empty_blob) ) ;
522
526
assert_eq ! (
523
527
repo. find_header( empty_blob) ?,
@@ -547,41 +551,45 @@ mod find {
547
551
}
548
552
549
553
#[ test]
550
- fn empty_blob_method_creates_correct_object ( ) -> crate :: Result {
551
- let repo = basic_repo ( ) ?;
554
+ fn empty_blob ( ) -> crate :: Result {
555
+ let repo = empty_bare_in_memory_repo ( ) ?;
552
556
let empty_blob = repo. empty_blob ( ) ;
553
-
554
- // The empty_blob method should create an object with the right ID and empty data
555
- assert_eq ! ( empty_blob. id, gix:: hash:: ObjectId :: empty_blob( repo. object_hash( ) ) ) ;
557
+
558
+ assert_eq ! ( empty_blob. id, repo. object_hash( ) . empty_blob( ) ) ;
556
559
assert_eq ! ( empty_blob. data. len( ) , 0 ) ;
557
-
560
+
561
+ assert ! ( !repo. has_object( empty_blob. id) , "it doesn't exist by default" ) ;
562
+ repo. write_blob ( & empty_blob. data ) ?;
563
+ assert ! ( repo. has_object( empty_blob. id) , "it exists after it was written" ) ;
564
+
558
565
Ok ( ( ) )
559
566
}
560
567
}
561
568
562
569
#[ test]
563
570
fn empty_objects_are_always_present_but_not_in_plumbing ( ) -> crate :: Result {
564
571
let repo = empty_bare_in_memory_repo ( ) ?;
565
- let empty_blob_id = gix :: hash :: ObjectId :: empty_blob ( repo. object_hash ( ) ) ;
572
+ let empty_blob_id = repo. object_hash ( ) . empty_blob ( ) ;
566
573
567
574
assert ! (
568
575
!repo. has_object( empty_blob_id) ,
569
576
"empty blob is not present unless it actually exists"
570
577
) ;
571
578
assert ! ( !repo. objects. contains( & empty_blob_id) ) ;
572
579
573
- // Empty blob should cause errors when it doesn't exist
574
- assert ! ( repo. find_header( empty_blob_id) . is_err( ) ) ;
580
+ assert ! (
581
+ repo. find_header( empty_blob_id) . is_err( ) ,
582
+ "Empty blob doesn't exist automatically just like in Git"
583
+ ) ;
575
584
assert_eq ! ( repo. objects. try_header( & empty_blob_id) ?, None ) ;
576
585
577
586
assert_eq ! ( repo. try_find_header( empty_blob_id) ?, None ) ;
578
587
assert ! ( repo. find_object( empty_blob_id) . is_err( ) ) ;
579
588
589
+ assert ! ( repo. try_find_object( empty_blob_id) ?. is_none( ) ) ;
580
590
let mut buf = Vec :: new ( ) ;
581
591
assert_eq ! ( repo. objects. try_find( & empty_blob_id, & mut buf) ?, None ) ;
582
592
583
- assert ! ( repo. try_find_object( empty_blob_id) ?. is_none( ) ) ;
584
-
585
593
Ok ( ( ) )
586
594
}
587
595
0 commit comments