1+ use crate :: {
2+ hex_to_id,
3+ rewrites:: { Change , NULL_ID } ,
4+ } ;
5+ use gix_diff:: tree:: visit:: Relation ;
16use gix_diff:: {
27 blob:: DiffLineStats ,
38 rewrites,
@@ -14,11 +19,6 @@ use gix_diff::{
1419use gix_object:: tree:: EntryKind ;
1520use pretty_assertions:: assert_eq;
1621
17- use crate :: {
18- hex_to_id,
19- rewrites:: { Change , NULL_ID } ,
20- } ;
21-
2222#[ test]
2323fn rename_by_id ( ) -> crate :: Result {
2424 // Limits are only applied when doing rewrite-checks
@@ -522,6 +522,106 @@ fn rename_by_50_percent_similarity() -> crate::Result {
522522 Ok ( ( ) )
523523}
524524
525+ #[ test]
526+ fn directories_without_relation_are_ignored ( ) -> crate :: Result {
527+ let mut track = util:: new_tracker ( Default :: default ( ) ) ;
528+ let tree_without_relation = Change {
529+ id : NULL_ID ,
530+ kind : ChangeKind :: Deletion ,
531+ mode : EntryKind :: Tree . into ( ) ,
532+ relation : None ,
533+ } ;
534+ assert_eq ! (
535+ track. try_push_change( tree_without_relation, "dir" . into( ) ) ,
536+ Some ( tree_without_relation) ,
537+ "trees, or non-blobs, are ignored, particularly when they have no relation"
538+ ) ;
539+ Ok ( ( ) )
540+ }
541+
542+ #[ test]
543+ #[ ignore = "cannot match directories if their content doesn't match" ]
544+ fn simple_directory_rename_with_changes ( ) -> crate :: Result {
545+ Ok ( ( ) )
546+ }
547+
548+ #[ test]
549+ #[ ignore = "one side has relationships, the other side does not, it still works on leaf-level" ]
550+ fn directory_rename_with_ids_one_side_without_on_the_other ( ) -> crate :: Result {
551+ Ok ( ( ) )
552+ }
553+
554+ #[ test]
555+ #[ ignore = "TBD" ]
556+ fn simple_directory_rename_by_id ( ) -> crate :: Result {
557+ let rewrites = Rewrites {
558+ copies : None ,
559+ percentage : Some ( 0.5 ) ,
560+ limit : 0 ,
561+ } ;
562+ let mut track = util:: new_tracker ( Default :: default ( ) ) ;
563+ let tree_dst_id = 1 ;
564+ assert ! ( track
565+ . try_push_change( Change :: tree_addition( tree_dst_id) , "d-renamed" . into( ) )
566+ . is_none( ) ) ;
567+ let tree_src_id = 3 ;
568+ assert ! ( track
569+ . try_push_change( Change :: tree_deletion( tree_src_id) , "d" . into( ) )
570+ . is_none( ) ) ;
571+ assert ! (
572+ track
573+ . try_push_change(
574+ Change {
575+ id: NULL_ID , /* does not matter for trees */
576+ kind: ChangeKind :: Deletion ,
577+ mode: EntryKind :: Tree . into( ) ,
578+ relation: Some ( Relation :: ChildOfParent ( tree_src_id) ) ,
579+ } ,
580+ "d/subdir" . into( ) ,
581+ )
582+ . is_some( ) ,
583+ "trees that are children are simply ignored. It's easier to compare views of worktrees (`gix-dirwalk`) \
584+ and trees/indices that way."
585+ ) ;
586+ assert ! ( track
587+ . try_push_change(
588+ Change {
589+ id: NULL_ID ,
590+ kind: ChangeKind :: Addition ,
591+ mode: EntryKind :: Tree . into( ) ,
592+ relation: Some ( Relation :: ChildOfParent ( tree_dst_id) ) ,
593+ } ,
594+ "d-renamed/subdir" . into( ) ,
595+ )
596+ . is_some( ) ) ;
597+ let _odb = util:: add_retained_blobs (
598+ & mut track,
599+ [
600+ ( Change :: deletion_in_tree ( tree_src_id) , "d/a" , "a" ) ,
601+ ( Change :: deletion_in_tree ( tree_src_id) , "d/b" , "b" ) ,
602+ ( Change :: deletion_in_tree ( tree_src_id) , "d/c" , "c" ) ,
603+ ( Change :: deletion_in_tree ( tree_src_id) , "d/subdir/d" , "d" ) ,
604+ ( Change :: addition_in_tree ( tree_dst_id) , "d-renamed/a" , "a" ) ,
605+ ( Change :: addition_in_tree ( tree_dst_id) , "d-renamed/b" , "b" ) ,
606+ ( Change :: addition_in_tree ( tree_dst_id) , "d-renamed/c" , "c" ) ,
607+ ( Change :: addition_in_tree ( tree_dst_id) , "d-renamed/subdir/d" , "d" ) ,
608+ ( Change :: deletion ( ) , "a" , "first\n second\n " ) ,
609+ ( Change :: addition ( ) , "b" , "firt\n second\n " ) ,
610+ ] ,
611+ ) ;
612+ let mut called = false ;
613+ let out = util:: assert_emit ( & mut track, |dst, src| {
614+ called = true ;
615+ assert_eq ! ( src, None , "there is just a single deletion, no pair" ) ;
616+ assert_eq ! ( dst. location, "a" ) ;
617+ assert_eq ! ( dst. change. kind, ChangeKind :: Deletion ) ;
618+ Action :: Continue
619+ } ) ;
620+ assert_eq ! ( out, Default :: default ( ) ) ;
621+ assert ! ( called) ;
622+ Ok ( ( ) )
623+ }
624+
525625#[ test]
526626fn remove_only ( ) -> crate :: Result {
527627 let mut track = util:: new_tracker ( Default :: default ( ) ) ;
@@ -554,7 +654,7 @@ fn add_only() -> crate::Result {
554654 let out = util:: assert_emit ( & mut track, |dst, src| {
555655 assert ! ( !called) ;
556656 called = true ;
557- assert ! ( src. is_none( ) , "there is just a single deletion , no pair" ) ;
657+ assert ! ( src. is_none( ) , "there is just a single addition , no pair" ) ;
558658 assert_eq ! ( dst. location, "a" ) ;
559659 assert_eq ! ( dst. change. kind, ChangeKind :: Addition ) ;
560660 Action :: Continue
0 commit comments