apply: test rename A -> B -> C scenarios Test that we can rename some file from B->C and then rename some other file from A->B. Do this with both exact rename patches (eg `rename from ...` / `rename to ...`) and patches that remove the files and replace them entirely.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
diff --git a/tests/apply/apply_helpers.h b/tests/apply/apply_helpers.h
index a3f7f18..165b10d 100644
--- a/tests/apply/apply_helpers.h
+++ b/tests/apply/apply_helpers.h
@@ -133,6 +133,98 @@
" Take the hind shin of beef, cut off all the flesh off the leg-bone,\n" \
" which must be taken away entirely, or the soup will be greasy. Wash the\n"
+#define DIFF_RENAME_A_TO_B_TO_C \
+ "diff --git a/asparagus.txt b/asparagus.txt\n" \
+ "deleted file mode 100644\n" \
+ "index f516580..0000000\n" \
+ "--- a/asparagus.txt\n" \
+ "+++ /dev/null\n" \
+ "@@ -1,10 +0,0 @@\n" \
+ "-ASPARAGUS SOUP!\n" \
+ "-\n" \
+ "-Take four large bunches of asparagus, scrape it nicely, cut off one inch\n" \
+ "-of the tops, and lay them in water, chop the stalks and put them on the\n" \
+ "-fire with a piece of bacon, a large onion cut up, and pepper and salt;\n" \
+ "-add two quarts of water, boil them till the stalks are quite soft, then\n" \
+ "-pulp them through a sieve, and strain the water to it, which must be put\n" \
+ "-back in the pot; put into it a chicken cut up, with the tops of\n" \
+ "-asparagus which had been laid by, boil it until these last articles are\n" \
+ "-sufficiently done, thicken with flour, butter and milk, and serve it up.\n" \
+ "diff --git a/beef.txt b/beef.txt\n" \
+ "index 68f6182..f516580 100644\n" \
+ "--- a/beef.txt\n" \
+ "+++ b/beef.txt\n" \
+ "@@ -1,22 +1,10 @@\n" \
+ "-BEEF SOUP.\n" \
+ "+ASPARAGUS SOUP!\n" \
+ "\n" \
+ "-Take the hind shin of beef, cut off all the flesh off the leg-bone,\n" \
+ "-which must be taken away entirely, or the soup will be greasy. Wash the\n" \
+ "-meat clean and lay it in a pot, sprinkle over it one small\n" \
+ "-table-spoonful of pounded black pepper, and two of salt; three onions\n" \
+ "-the size of a hen's egg, cut small, six small carrots scraped and cut\n" \
+ "-up, two small turnips pared and cut into dice; pour on three quarts of\n" \
+ "-water, cover the pot close, and keep it gently and steadily boiling five\n" \
+ "-hours, which will leave about three pints of clear soup; do not let the\n" \
+ "-pot boil over, but take off the scum carefully, as it rises. When it has\n" \
+ "-boiled four hours, put in a small bundle of thyme and parsley, and a\n" \
+ "-pint of celery cut small, or a tea-spoonful of celery seed pounded.\n" \
+ "-These latter ingredients would lose their delicate flavour if boiled too\n" \
+ "-much. Just before you take it up, brown it in the following manner: put\n" \
+ "-a small table-spoonful of nice brown sugar into an iron skillet, set it\n" \
+ "-on the fire and stir it till it melts and looks very dark, pour into it\n" \
+ "-a ladle full of the soup, a little at a time; stirring it all the while.\n" \
+ "-Strain this browning and mix it well with the soup; take out the bundle\n" \
+ "-of thyme and parsley, put the nicest pieces of meat in your tureen, and\n" \
+ "-pour on the soup and vegetables; put in some toasted bread cut in dice,\n" \
+ "-and serve it up.\n" \
+ "+Take four large bunches of asparagus, scrape it nicely, cut off one inch\n" \
+ "+of the tops, and lay them in water, chop the stalks and put them on the\n" \
+ "+fire with a piece of bacon, a large onion cut up, and pepper and salt;\n" \
+ "+add two quarts of water, boil them till the stalks are quite soft, then\n" \
+ "+pulp them through a sieve, and strain the water to it, which must be put\n" \
+ "+back in the pot; put into it a chicken cut up, with the tops of\n" \
+ "+asparagus which had been laid by, boil it until these last articles are\n" \
+ "+sufficiently done, thicken with flour, butter and milk, and serve it up.\n" \
+ "diff --git a/notbeef.txt b/notbeef.txt\n" \
+ "new file mode 100644\n" \
+ "index 0000000..68f6182\n" \
+ "--- /dev/null\n" \
+ "+++ b/notbeef.txt\n" \
+ "@@ -0,0 +1,22 @@\n" \
+ "+BEEF SOUP.\n" \
+ "+\n" \
+ "+Take the hind shin of beef, cut off all the flesh off the leg-bone,\n" \
+ "+which must be taken away entirely, or the soup will be greasy. Wash the\n" \
+ "+meat clean and lay it in a pot, sprinkle over it one small\n" \
+ "+table-spoonful of pounded black pepper, and two of salt; three onions\n" \
+ "+the size of a hen's egg, cut small, six small carrots scraped and cut\n" \
+ "+up, two small turnips pared and cut into dice; pour on three quarts of\n" \
+ "+water, cover the pot close, and keep it gently and steadily boiling five\n" \
+ "+hours, which will leave about three pints of clear soup; do not let the\n" \
+ "+pot boil over, but take off the scum carefully, as it rises. When it has\n" \
+ "+boiled four hours, put in a small bundle of thyme and parsley, and a\n" \
+ "+pint of celery cut small, or a tea-spoonful of celery seed pounded.\n" \
+ "+These latter ingredients would lose their delicate flavour if boiled too\n" \
+ "+much. Just before you take it up, brown it in the following manner: put\n" \
+ "+a small table-spoonful of nice brown sugar into an iron skillet, set it\n" \
+ "+on the fire and stir it till it melts and looks very dark, pour into it\n" \
+ "+a ladle full of the soup, a little at a time; stirring it all the while.\n" \
+ "+Strain this browning and mix it well with the soup; take out the bundle\n" \
+ "+of thyme and parsley, put the nicest pieces of meat in your tureen, and\n" \
+ "+pour on the soup and vegetables; put in some toasted bread cut in dice,\n" \
+ "+and serve it up.\n"
+
+#define DIFF_RENAME_A_TO_B_TO_C_EXACT \
+ "diff --git a/asparagus.txt b/beef.txt\n" \
+ "similarity index 100%\n" \
+ "rename from asparagus.txt\n" \
+ "rename to beef.txt\n" \
+ "diff --git a/beef.txt b/notbeef.txt\n" \
+ "similarity index 100%\n" \
+ "rename from beef.txt\n" \
+ "rename to notbeef.txt\n"
+
struct iterator_compare_data {
struct merge_index_entry *expected;
size_t cnt;
diff --git a/tests/apply/both.c b/tests/apply/both.c
index 15b2016..0e6d672 100644
--- a/tests/apply/both.c
+++ b/tests/apply/both.c
@@ -449,3 +449,53 @@ void test_apply_both__rename_and_modify(void)
git_diff_free(diff);
}
+
+void test_apply_both__rename_a_to_b_to_c(void)
+{
+ git_diff *diff;
+
+ struct merge_index_entry both_expected[] = {
+ { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "beef.txt" },
+ { 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
+ { 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
+ { 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "notbeef.txt" },
+ { 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
+ { 0100644, "94d2c01087f48213bd157222d54edfefd77c9bba", 0, "veal.txt" },
+ };
+ size_t both_expected_cnt = sizeof(both_expected) /
+ sizeof(struct merge_index_entry);
+
+ cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_A_TO_B_TO_C,
+ strlen(DIFF_RENAME_A_TO_B_TO_C)));
+ cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
+
+ validate_apply_index(repo, both_expected, both_expected_cnt);
+ validate_apply_workdir(repo, both_expected, both_expected_cnt);
+
+ git_diff_free(diff);
+}
+
+void test_apply_both__rename_a_to_b_to_c_exact(void)
+{
+ git_diff *diff;
+
+ struct merge_index_entry both_expected[] = {
+ { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "beef.txt" },
+ { 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
+ { 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
+ { 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "notbeef.txt" },
+ { 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
+ { 0100644, "94d2c01087f48213bd157222d54edfefd77c9bba", 0, "veal.txt" },
+ };
+ size_t both_expected_cnt = sizeof(both_expected) /
+ sizeof(struct merge_index_entry);
+
+ cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_A_TO_B_TO_C_EXACT,
+ strlen(DIFF_RENAME_A_TO_B_TO_C_EXACT)));
+ cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
+
+ validate_apply_index(repo, both_expected, both_expected_cnt);
+ validate_apply_workdir(repo, both_expected, both_expected_cnt);
+
+ git_diff_free(diff);
+}