@@ -432,6 +432,7 @@ mod find {
432432 use gix_pack:: Find ;
433433
434434 use crate :: basic_repo;
435+ use crate :: repository:: object:: empty_bare_in_memory_repo;
435436
436437 #[ test]
437438 fn find_and_try_find_with_and_without_object_cache ( ) -> crate :: Result {
@@ -515,9 +516,12 @@ mod find {
515516 fn empty_blob_can_be_found_if_it_exists ( ) -> crate :: Result {
516517 let repo = basic_repo ( ) ?;
517518 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+ ) ;
521525 assert ! ( repo. has_object( empty_blob) ) ;
522526 assert_eq ! (
523527 repo. find_header( empty_blob) ?,
@@ -547,41 +551,45 @@ mod find {
547551 }
548552
549553 #[ 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 ( ) ?;
552556 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( ) ) ;
556559 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+
558565 Ok ( ( ) )
559566 }
560567}
561568
562569#[ test]
563570fn empty_objects_are_always_present_but_not_in_plumbing ( ) -> crate :: Result {
564571 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 ( ) ;
566573
567574 assert ! (
568575 !repo. has_object( empty_blob_id) ,
569576 "empty blob is not present unless it actually exists"
570577 ) ;
571578 assert ! ( !repo. objects. contains( & empty_blob_id) ) ;
572579
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+ ) ;
575584 assert_eq ! ( repo. objects. try_header( & empty_blob_id) ?, None ) ;
576585
577586 assert_eq ! ( repo. try_find_header( empty_blob_id) ?, None ) ;
578587 assert ! ( repo. find_object( empty_blob_id) . is_err( ) ) ;
579588
589+ assert ! ( repo. try_find_object( empty_blob_id) ?. is_none( ) ) ;
580590 let mut buf = Vec :: new ( ) ;
581591 assert_eq ! ( repo. objects. try_find( & empty_blob_id, & mut buf) ?, None ) ;
582592
583- assert ! ( repo. try_find_object( empty_blob_id) ?. is_none( ) ) ;
584-
585593 Ok ( ( ) )
586594}
587595
0 commit comments