@@ -811,3 +811,96 @@ void test_diff_rename__from_deleted_to_split(void)
811
811
812
812
git_buf_free (& c1 );
813
813
}
814
+
815
+ struct rename_expected
816
+ {
817
+ size_t len ;
818
+ const char * * sources ;
819
+ const char * * targets ;
820
+
821
+ size_t idx ;
822
+ };
823
+
824
+ int test_names_expected (const git_diff_delta * delta , float progress , void * p )
825
+ {
826
+ struct rename_expected * expected = p ;
827
+
828
+ cl_assert (expected -> idx < expected -> len );
829
+
830
+ cl_assert_equal_i (delta -> status , GIT_DELTA_RENAMED );
831
+
832
+ cl_assert (git__strcmp (expected -> sources [expected -> idx ],
833
+ delta -> old_file .path ) == 0 );
834
+ cl_assert (git__strcmp (expected -> targets [expected -> idx ],
835
+ delta -> new_file .path ) == 0 );
836
+
837
+ expected -> idx ++ ;
838
+
839
+ return 0 ;
840
+ }
841
+
842
+ void test_diff_rename__rejected_match_can_match_others (void )
843
+ {
844
+ git_reference * head , * selfsimilar ;
845
+ git_index * index ;
846
+ git_tree * tree ;
847
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT ;
848
+ git_diff_list * diff ;
849
+ git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT ;
850
+ git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT ;
851
+ git_buf one = GIT_BUF_INIT , two = GIT_BUF_INIT ;
852
+ const char * sources [] = { "Class1.cs" , "Class2.cs" };
853
+ const char * targets [] = { "ClassA.cs" , "ClassB.cs" };
854
+ struct rename_expected expect = { 2 , sources , targets };
855
+ char * ptr ;
856
+
857
+ opts .checkout_strategy = GIT_CHECKOUT_FORCE ;
858
+
859
+ cl_git_pass (git_reference_lookup (& head , g_repo , "HEAD" ));
860
+ cl_git_pass (git_reference_symbolic_set_target (
861
+ & selfsimilar , head , "refs/heads/renames_similar" ));
862
+ cl_git_pass (git_checkout_head (g_repo , & opts ));
863
+ cl_git_pass (git_repository_index (& index , g_repo ));
864
+
865
+ cl_git_pass (git_futils_readbuffer (& one , "renames/Class1.cs" ));
866
+ cl_git_pass (git_futils_readbuffer (& two , "renames/Class2.cs" ));
867
+
868
+ cl_git_pass (p_unlink ("renames/Class1.cs" ));
869
+ cl_git_pass (p_unlink ("renames/Class2.cs" ));
870
+
871
+ cl_git_pass (git_index_remove_bypath (index , "Class1.cs" ));
872
+ cl_git_pass (git_index_remove_bypath (index , "Class2.cs" ));
873
+
874
+ cl_assert (ptr = strstr (one .ptr , "Class1" ));
875
+ ptr [5 ] = 'A' ;
876
+
877
+ cl_assert (ptr = strstr (two .ptr , "Class2" ));
878
+ ptr [5 ] = 'B' ;
879
+
880
+ cl_git_pass (
881
+ git_futils_writebuffer (& one , "renames/ClassA.cs" , O_RDWR |O_CREAT , 0777 ));
882
+ cl_git_pass (
883
+ git_futils_writebuffer (& two , "renames/ClassB.cs" , O_RDWR |O_CREAT , 0777 ));
884
+
885
+ cl_git_pass (git_index_add_bypath (index , "ClassA.cs" ));
886
+ cl_git_pass (git_index_add_bypath (index , "ClassB.cs" ));
887
+
888
+ cl_git_pass (git_index_write (index ));
889
+
890
+ cl_git_pass (
891
+ git_revparse_single ((git_object * * )& tree , g_repo , "HEAD^{tree}" ));
892
+
893
+ cl_git_pass (
894
+ git_diff_tree_to_index (& diff , g_repo , tree , index , & diffopts ));
895
+ cl_git_pass (git_diff_find_similar (diff , & findopts ));
896
+
897
+ cl_git_pass (
898
+ git_diff_foreach (diff , test_names_expected , NULL , NULL , & expect ));
899
+
900
+ git_tree_free (tree );
901
+ git_index_free (index );
902
+ git_reference_free (head );
903
+ git_reference_free (selfsimilar );
904
+ git_buf_free (& one );
905
+ git_buf_free (& two );
906
+ }
0 commit comments