@@ -25,6 +25,7 @@ void test_diff_tree__cleanup(void)
2525 git_tree_free (b );
2626
2727 cl_git_sandbox_cleanup ();
28+
2829}
2930
3031void test_diff_tree__0 (void )
@@ -320,3 +321,111 @@ void test_diff_tree__checks_options_version(void)
320321 cl_git_fail (git_diff_tree_to_tree (& diff , g_repo , a , b , & opts ));
321322 err = giterr_last ();
322323}
324+
325+ void process_tree_to_tree_diffing (
326+ const char * old_commit ,
327+ const char * new_commit )
328+ {
329+ g_repo = cl_git_sandbox_init ("unsymlinked.git" );
330+
331+ cl_assert ((a = resolve_commit_oid_to_tree (g_repo , old_commit )) != NULL );
332+ cl_assert ((b = resolve_commit_oid_to_tree (g_repo , new_commit )) != NULL );
333+
334+ cl_git_pass (git_diff_tree_to_tree (& diff , g_repo , a , b , & opts ));
335+
336+ cl_git_pass (git_diff_foreach (
337+ diff , diff_file_cb , NULL , NULL , & exp ));
338+ }
339+
340+ void test_diff_tree__symlink_blob_mode_changed_to_regular_file (void )
341+ {
342+ /*
343+ * $ git diff 7fccd7..806999
344+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
345+ * deleted file mode 120000
346+ * index 19bf568..0000000
347+ * --- a/include/Nu/Nu.h
348+ * +++ /dev/null
349+ * @@ -1 +0,0 @@
350+ * -../../objc/Nu.h
351+ * \ No newline at end of file
352+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
353+ * new file mode 100644
354+ * index 0000000..f9e6561
355+ * --- /dev/null
356+ * +++ b/include/Nu/Nu.h
357+ * @@ -0,0 +1 @@
358+ * +awesome content
359+ * diff --git a/objc/Nu.h b/objc/Nu.h
360+ * deleted file mode 100644
361+ * index f9e6561..0000000
362+ * --- a/objc/Nu.h
363+ * +++ /dev/null
364+ * @@ -1 +0,0 @@
365+ * -awesome content
366+ */
367+
368+ process_tree_to_tree_diffing ("7fccd7" , "806999" );
369+
370+ cl_assert_equal_i (3 , exp .files );
371+ cl_assert_equal_i (2 , exp .file_status [GIT_DELTA_DELETED ]);
372+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_MODIFIED ]);
373+ cl_assert_equal_i (1 , exp .file_status [GIT_DELTA_ADDED ]);
374+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_TYPECHANGE ]);
375+ }
376+
377+ void test_diff_tree__symlink_blob_mode_changed_to_regular_file_as_typechange (void )
378+ {
379+ /*
380+ * $ git diff 7fccd7..a8595c
381+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
382+ * deleted file mode 120000
383+ * index 19bf568..0000000
384+ * --- a/include/Nu/Nu.h
385+ * +++ /dev/null
386+ * @@ -1 +0,0 @@
387+ * -../../objc/Nu.h
388+ * \ No newline at end of file
389+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
390+ * new file mode 100755
391+ * index 0000000..f9e6561
392+ * --- /dev/null
393+ * +++ b/include/Nu/Nu.h
394+ * @@ -0,0 +1 @@
395+ * +awesome content
396+ * diff --git a/objc/Nu.h b/objc/Nu.h
397+ * deleted file mode 100644
398+ * index f9e6561..0000000
399+ * --- a/objc/Nu.h
400+ * +++ /dev/null
401+ * @@ -1 +0,0 @@
402+ * -awesome content
403+ */
404+
405+ opts .flags = GIT_DIFF_INCLUDE_TYPECHANGE ;
406+ process_tree_to_tree_diffing ("7fccd7" , "a8595c" );
407+
408+ cl_assert_equal_i (2 , exp .files );
409+ cl_assert_equal_i (1 , exp .file_status [GIT_DELTA_DELETED ]);
410+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_MODIFIED ]);
411+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_ADDED ]);
412+ cl_assert_equal_i (1 , exp .file_status [GIT_DELTA_TYPECHANGE ]);
413+ }
414+
415+ void test_diff_tree__regular_blob_mode_changed_to_executable_file (void )
416+ {
417+ /*
418+ * $ git diff 806999..a8595c
419+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
420+ * old mode 100644
421+ * new mode 100755
422+ */
423+
424+ process_tree_to_tree_diffing ("806999" , "a8595c" );
425+
426+ cl_assert_equal_i (1 , exp .files );
427+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_DELETED ]);
428+ cl_assert_equal_i (1 , exp .file_status [GIT_DELTA_MODIFIED ]);
429+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_ADDED ]);
430+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_TYPECHANGE ]);
431+ }
0 commit comments