@@ -442,7 +442,89 @@ mod test {
442
442
let blob = tree. get_name ( "foo.txt" ) . unwrap ( ) . id ( ) ; // We fail here to get the entry because the tree is empty
443
443
let blob: git2:: Blob = test_repository. repository . find_blob ( blob) . unwrap ( ) ;
444
444
445
- assert_eq ! ( blob. content( ) , b"b" ) // expect b"b", using x as a test inverse
445
+ assert_eq ! ( blob. content( ) , b"b" )
446
+ }
447
+
448
+ #[ test]
449
+ fn test_diverging_renames ( ) {
450
+ let test_repository = TestingRepository :: open ( ) ;
451
+
452
+ // Make some commits
453
+ let a = test_repository. commit_tree ( None , & [ ( "foo.txt" , "a" ) ] ) ;
454
+ let b = test_repository. commit_tree ( None , & [ ( "bar.txt" , "a" ) ] ) ;
455
+ let c = test_repository. commit_tree ( None , & [ ( "baz.txt" , "a" ) ] ) ;
456
+ test_repository. commit_tree ( None , & [ ( "foo.txt" , "asdfasdf" ) ] ) ;
457
+
458
+ // Merge the index
459
+ let mut index: git2:: Index = test_repository
460
+ . repository
461
+ . merge_trees (
462
+ & a. tree ( ) . unwrap ( ) , // Base
463
+ & b. tree ( ) . unwrap ( ) , // Ours
464
+ & c. tree ( ) . unwrap ( ) , // Theirs
465
+ None ,
466
+ )
467
+ . unwrap ( ) ;
468
+
469
+ assert ! ( index. has_conflicts( ) ) ;
470
+
471
+ // Call our index resolution function
472
+ resolve_index ( & test_repository. repository , & mut index) . unwrap ( ) ;
473
+
474
+ // Ensure there are no conflicts
475
+ assert ! ( !index. has_conflicts( ) ) ;
476
+
477
+ let tree = index. write_tree_to ( & test_repository. repository ) . unwrap ( ) ;
478
+ let tree: git2:: Tree = test_repository. repository . find_tree ( tree) . unwrap ( ) ;
479
+
480
+ assert ! ( tree. get_name( "foo.txt" ) . is_none( ) ) ;
481
+ assert ! ( tree. get_name( "baz.txt" ) . is_none( ) ) ;
482
+
483
+ let blob = tree. get_name ( "bar.txt" ) . unwrap ( ) . id ( ) ; // We fail here to get the entry because the tree is empty
484
+ let blob: git2:: Blob = test_repository. repository . find_blob ( blob) . unwrap ( ) ;
485
+
486
+ assert_eq ! ( blob. content( ) , b"a" )
487
+ }
488
+
489
+ #[ test]
490
+ fn test_converging_renames ( ) {
491
+ let test_repository = TestingRepository :: open ( ) ;
492
+
493
+ // Make some commits
494
+ let a = test_repository. commit_tree ( None , & [ ( "foo.txt" , "a" ) , ( "bar.txt" , "b" ) ] ) ;
495
+ let b = test_repository. commit_tree ( None , & [ ( "baz.txt" , "a" ) ] ) ;
496
+ let c = test_repository. commit_tree ( None , & [ ( "baz.txt" , "b" ) ] ) ;
497
+ test_repository. commit_tree ( None , & [ ( "foo.txt" , "asdfasdf" ) ] ) ;
498
+
499
+ // Merge the index
500
+ let mut index: git2:: Index = test_repository
501
+ . repository
502
+ . merge_trees (
503
+ & a. tree ( ) . unwrap ( ) , // Base
504
+ & b. tree ( ) . unwrap ( ) , // Ours
505
+ & c. tree ( ) . unwrap ( ) , // Theirs
506
+ None ,
507
+ )
508
+ . unwrap ( ) ;
509
+
510
+ assert ! ( index. has_conflicts( ) ) ;
511
+
512
+ // Call our index resolution function
513
+ resolve_index ( & test_repository. repository , & mut index) . unwrap ( ) ;
514
+
515
+ // Ensure there are no conflicts
516
+ assert ! ( !index. has_conflicts( ) ) ;
517
+
518
+ let tree = index. write_tree_to ( & test_repository. repository ) . unwrap ( ) ;
519
+ let tree: git2:: Tree = test_repository. repository . find_tree ( tree) . unwrap ( ) ;
520
+
521
+ assert ! ( tree. get_name( "foo.txt" ) . is_none( ) ) ;
522
+ assert ! ( tree. get_name( "bar.txt" ) . is_none( ) ) ;
523
+
524
+ let blob = tree. get_name ( "baz.txt" ) . unwrap ( ) . id ( ) ; // We fail here to get the entry because the tree is empty
525
+ let blob: git2:: Blob = test_repository. repository . find_blob ( blob) . unwrap ( ) ;
526
+
527
+ assert_eq ! ( blob. content( ) , b"a" )
446
528
}
447
529
}
448
530
}
0 commit comments