@@ -1765,3 +1765,216 @@ void test_diff_rename__identical(void)
1765
1765
git_tree_free (new_tree );
1766
1766
}
1767
1767
1768
+ void test_diff_rename__rewrite_and_delete (void )
1769
+ {
1770
+ const char * old_sha = RENAME_MODIFICATION_COMMIT ;
1771
+ const char * new_sha = REWRITE_DELETE_COMMIT ;
1772
+ git_tree * old_tree , * new_tree ;
1773
+ git_diff * diff ;
1774
+ git_diff_find_options find_opts = GIT_DIFF_FIND_OPTIONS_INIT ;
1775
+ git_buf diff_buf = GIT_BUF_INIT ;
1776
+ const char * expected =
1777
+ "diff --git a/ikeepsix.txt b/ikeepsix.txt\n"
1778
+ "deleted file mode 100644\n"
1779
+ "index eaf4a3e..0000000\n"
1780
+ "--- a/ikeepsix.txt\n"
1781
+ "+++ /dev/null\n"
1782
+ "@@ -1,27 +0,0 @@\n"
1783
+ "-I Keep Six Honest Serving-Men\n"
1784
+ "-=============================\n"
1785
+ "-\n"
1786
+ "-She sends'em abroad on her own affairs,\n"
1787
+ "- From the second she opens her eyes—\n"
1788
+ "-One million Hows, two million Wheres,\n"
1789
+ "-And seven million Whys!\n"
1790
+ "-\n"
1791
+ "-I let them rest from nine till five,\n"
1792
+ "- For I am busy then,\n"
1793
+ "-As well as breakfast, lunch, and tea,\n"
1794
+ "- For they are hungry men.\n"
1795
+ "-But different folk have different views;\n"
1796
+ "-I know a person small—\n"
1797
+ "-She keeps ten million serving-men,\n"
1798
+ "-Who get no rest at all!\n"
1799
+ "-\n"
1800
+ "- -- Rudyard Kipling\n"
1801
+ "-\n"
1802
+ "-I KEEP six honest serving-men\n"
1803
+ "- (They taught me all I knew);\n"
1804
+ "-Their names are What and Why and When\n"
1805
+ "- And How and Where and Who.\n"
1806
+ "-I send them over land and sea,\n"
1807
+ "- I send them east and west;\n"
1808
+ "-But after they have worked for me,\n"
1809
+ "- I give them all a rest.\n"
1810
+ "diff --git a/songof7cities.txt b/songof7cities.txt\n"
1811
+ "index 4210ffd..95ceb12 100644\n"
1812
+ "--- a/songof7cities.txt\n"
1813
+ "+++ b/songof7cities.txt\n"
1814
+ "@@ -1,45 +1,45 @@\n"
1815
+ "-The Song of Seven Cities\n"
1816
+ "+THE SONG OF SEVEN CITIES\n"
1817
+ " ------------------------\n"
1818
+ " \n"
1819
+ "-I WAS Lord of Cities very sumptuously builded.\n"
1820
+ "-Seven roaring Cities paid me tribute from afar.\n"
1821
+ "-Ivory their outposts were--the guardrooms of them gilded,\n"
1822
+ "-And garrisoned with Amazons invincible in war.\n"
1823
+ "-\n"
1824
+ "-All the world went softly when it walked before my Cities--\n"
1825
+ "-Neither King nor Army vexed my peoples at their toil,\n"
1826
+ "-Never horse nor chariot irked or overbore my Cities,\n"
1827
+ "-Never Mob nor Ruler questioned whence they drew their spoil.\n"
1828
+ "-\n"
1829
+ "-Banded, mailed and arrogant from sunrise unto sunset;\n"
1830
+ "-Singing while they sacked it, they possessed the land at large.\n"
1831
+ "-Yet when men would rob them, they resisted, they made onset\n"
1832
+ "-And pierced the smoke of battle with a thousand-sabred charge.\n"
1833
+ "-\n"
1834
+ "-So they warred and trafficked only yesterday, my Cities.\n"
1835
+ "-To-day there is no mark or mound of where my Cities stood.\n"
1836
+ "-For the River rose at midnight and it washed away my Cities.\n"
1837
+ "-They are evened with Atlantis and the towns before the Flood.\n"
1838
+ "-\n"
1839
+ "-Rain on rain-gorged channels raised the water-levels round them,\n"
1840
+ "-Freshet backed on freshet swelled and swept their world from sight,\n"
1841
+ "-Till the emboldened floods linked arms and, flashing forward, drowned them--\n"
1842
+ "-Drowned my Seven Cities and their peoples in one night!\n"
1843
+ "-\n"
1844
+ "-Low among the alders lie their derelict foundations,\n"
1845
+ "-The beams wherein they trusted and the plinths whereon they built--\n"
1846
+ "-My rulers and their treasure and their unborn populations,\n"
1847
+ "-Dead, destroyed, aborted, and defiled with mud and silt!\n"
1848
+ "-\n"
1849
+ "-The Daughters of the Palace whom they cherished in my Cities,\n"
1850
+ "-My silver-tongued Princesses, and the promise of their May--\n"
1851
+ "-Their bridegrooms of the June-tide--all have perished in my Cities,\n"
1852
+ "-With the harsh envenomed virgins that can neither love nor play.\n"
1853
+ "-\n"
1854
+ "-I was Lord of Cities--I will build anew my Cities,\n"
1855
+ "-Seven, set on rocks, above the wrath of any flood.\n"
1856
+ "-Nor will I rest from search till I have filled anew my Cities\n"
1857
+ "-With peoples undefeated of the dark, enduring blood.\n"
1858
+ "+I WAS LORD OF CITIES VERY SUMPTUOUSLY BUILDED.\n"
1859
+ "+SEVEN ROARING CITIES PAID ME TRIBUTE FROM AFAR.\n"
1860
+ "+IVORY THEIR OUTPOSTS WERE--THE GUARDROOMS OF THEM GILDED,\n"
1861
+ "+AND GARRISONED WITH AMAZONS INVINCIBLE IN WAR.\n"
1862
+ "+\n"
1863
+ "+ALL THE WORLD WENT SOFTLY WHEN IT WALKED BEFORE MY CITIES--\n"
1864
+ "+NEITHER KING NOR ARMY VEXED MY PEOPLES AT THEIR TOIL,\n"
1865
+ "+NEVER HORSE NOR CHARIOT IRKED OR OVERBORE MY CITIES,\n"
1866
+ "+NEVER MOB NOR RULER QUESTIONED WHENCE THEY DREW THEIR SPOIL.\n"
1867
+ "+\n"
1868
+ "+BANDED, MAILED AND ARROGANT FROM SUNRISE UNTO SUNSET;\n"
1869
+ "+SINGING WHILE THEY SACKED IT, THEY POSSESSED THE LAND AT LARGE.\n"
1870
+ "+YET WHEN MEN WOULD ROB THEM, THEY RESISTED, THEY MADE ONSET\n"
1871
+ "+AND PIERCED THE SMOKE OF BATTLE WITH A THOUSAND-SABRED CHARGE.\n"
1872
+ "+\n"
1873
+ "+SO THEY WARRED AND TRAFFICKED ONLY YESTERDAY, MY CITIES.\n"
1874
+ "+TO-DAY THERE IS NO MARK OR MOUND OF WHERE MY CITIES STOOD.\n"
1875
+ "+FOR THE RIVER ROSE AT MIDNIGHT AND IT WASHED AWAY MY CITIES.\n"
1876
+ "+THEY ARE EVENED WITH ATLANTIS AND THE TOWNS BEFORE THE FLOOD.\n"
1877
+ "+\n"
1878
+ "+RAIN ON RAIN-GORGED CHANNELS RAISED THE WATER-LEVELS ROUND THEM,\n"
1879
+ "+FRESHET BACKED ON FRESHET SWELLED AND SWEPT THEIR WORLD FROM SIGHT,\n"
1880
+ "+TILL THE EMBOLDENED FLOODS LINKED ARMS AND, FLASHING FORWARD, DROWNED THEM--\n"
1881
+ "+DROWNED MY SEVEN CITIES AND THEIR PEOPLES IN ONE NIGHT!\n"
1882
+ "+\n"
1883
+ "+LOW AMONG THE ALDERS LIE THEIR DERELICT FOUNDATIONS,\n"
1884
+ "+THE BEAMS WHEREIN THEY TRUSTED AND THE PLINTHS WHEREON THEY BUILT--\n"
1885
+ "+MY RULERS AND THEIR TREASURE AND THEIR UNBORN POPULATIONS,\n"
1886
+ "+DEAD, DESTROYED, ABORTED, AND DEFILED WITH MUD AND SILT!\n"
1887
+ "+\n"
1888
+ "+THE DAUGHTERS OF THE PALACE WHOM THEY CHERISHED IN MY CITIES,\n"
1889
+ "+MY SILVER-TONGUED PRINCESSES, AND THE PROMISE OF THEIR MAY--\n"
1890
+ "+THEIR BRIDEGROOMS OF THE JUNE-TIDE--ALL HAVE PERISHED IN MY CITIES,\n"
1891
+ "+WITH THE HARSH ENVENOMED VIRGINS THAT CAN NEITHER LOVE NOR PLAY.\n"
1892
+ "+\n"
1893
+ "+I WAS LORD OF CITIES--I WILL BUILD ANEW MY CITIES,\n"
1894
+ "+SEVEN, SET ON ROCKS, ABOVE THE WRATH OF ANY FLOOD.\n"
1895
+ "+NOR WILL I REST FROM SEARCH TILL I HAVE FILLED ANEW MY CITIES\n"
1896
+ "+WITH PEOPLES UNDEFEATED OF THE DARK, ENDURING BLOOD.\n"
1897
+ " \n"
1898
+ " To the sound of trumpets shall their seed restore my Cities\n"
1899
+ " Wealthy and well-weaponed, that once more may I behold\n" ;
1900
+
1901
+ old_tree = resolve_commit_oid_to_tree (g_repo , old_sha );
1902
+ new_tree = resolve_commit_oid_to_tree (g_repo , new_sha );
1903
+
1904
+ find_opts .flags = GIT_DIFF_FIND_RENAMES_FROM_REWRITES ;
1905
+
1906
+ cl_git_pass (git_diff_tree_to_tree (& diff , g_repo , old_tree , new_tree , NULL ));
1907
+ cl_git_pass (git_diff_find_similar (diff , & find_opts ));
1908
+
1909
+ cl_git_pass (git_diff_to_buf (& diff_buf , diff , GIT_DIFF_FORMAT_PATCH ));
1910
+
1911
+ cl_assert_equal_s (expected , diff_buf .ptr );
1912
+
1913
+ git_buf_free (& diff_buf );
1914
+ git_diff_free (diff );
1915
+ git_tree_free (old_tree );
1916
+ git_tree_free (new_tree );
1917
+ }
1918
+
1919
+ void test_diff_rename__delete_and_rename (void )
1920
+ {
1921
+ const char * old_sha = RENAME_MODIFICATION_COMMIT ;
1922
+ const char * new_sha = DELETE_RENAME_COMMIT ;
1923
+ git_tree * old_tree , * new_tree ;
1924
+ git_diff * diff ;
1925
+ git_diff_find_options find_opts = GIT_DIFF_FIND_OPTIONS_INIT ;
1926
+ git_buf diff_buf = GIT_BUF_INIT ;
1927
+ const char * expected =
1928
+ "diff --git a/sixserving.txt b/sixserving.txt\n"
1929
+ "deleted file mode 100644\n"
1930
+ "index f90d4fc..0000000\n"
1931
+ "--- a/sixserving.txt\n"
1932
+ "+++ /dev/null\n"
1933
+ "@@ -1,25 +0,0 @@\n"
1934
+ "-I KEEP six honest serving-men\n"
1935
+ "- (They taught me all I knew);\n"
1936
+ "-Their names are What and Why and When\n"
1937
+ "- And How and Where and Who.\n"
1938
+ "-I send them over land and sea,\n"
1939
+ "- I send them east and west;\n"
1940
+ "-But after they have worked for me,\n"
1941
+ "- I give them all a rest.\n"
1942
+ "-\n"
1943
+ "-I let them rest from nine till five,\n"
1944
+ "- For I am busy then,\n"
1945
+ "-As well as breakfast, lunch, and tea,\n"
1946
+ "- For they are hungry men.\n"
1947
+ "-But different folk have different views;\n"
1948
+ "-I know a person small—\n"
1949
+ "-She keeps ten million serving-men,\n"
1950
+ "-Who get no rest at all!\n"
1951
+ "-\n"
1952
+ "-She sends'em abroad on her own affairs,\n"
1953
+ "- From the second she opens her eyes—\n"
1954
+ "-One million Hows, two million Wheres,\n"
1955
+ "-And seven million Whys!\n"
1956
+ "-\n"
1957
+ "- -- Rudyard Kipling\n"
1958
+ "-\n"
1959
+ "diff --git a/songof7cities.txt b/sixserving.txt\n"
1960
+ "similarity index 100%\n"
1961
+ "rename from songof7cities.txt\n"
1962
+ "rename to sixserving.txt\n" ;
1963
+
1964
+ old_tree = resolve_commit_oid_to_tree (g_repo , old_sha );
1965
+ new_tree = resolve_commit_oid_to_tree (g_repo , new_sha );
1966
+
1967
+ find_opts .flags = GIT_DIFF_FIND_RENAMES_FROM_REWRITES ;
1968
+
1969
+ cl_git_pass (git_diff_tree_to_tree (& diff , g_repo , old_tree , new_tree , NULL ));
1970
+ cl_git_pass (git_diff_find_similar (diff , & find_opts ));
1971
+
1972
+ cl_git_pass (git_diff_to_buf (& diff_buf , diff , GIT_DIFF_FORMAT_PATCH ));
1973
+
1974
+ cl_assert_equal_s (expected , diff_buf .ptr );
1975
+
1976
+ git_buf_free (& diff_buf );
1977
+ git_diff_free (diff );
1978
+ git_tree_free (old_tree );
1979
+ git_tree_free (new_tree );
1980
+ }
0 commit comments