Skip to content

Commit 89b5a56

Browse files
committed
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 parent 6fecf4d commit 89b5a56

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

tests/apply/apply_helpers.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,98 @@
133133
" Take the hind shin of beef, cut off all the flesh off the leg-bone,\n" \
134134
" which must be taken away entirely, or the soup will be greasy. Wash the\n"
135135

136+
#define DIFF_RENAME_A_TO_B_TO_C \
137+
"diff --git a/asparagus.txt b/asparagus.txt\n" \
138+
"deleted file mode 100644\n" \
139+
"index f516580..0000000\n" \
140+
"--- a/asparagus.txt\n" \
141+
"+++ /dev/null\n" \
142+
"@@ -1,10 +0,0 @@\n" \
143+
"-ASPARAGUS SOUP!\n" \
144+
"-\n" \
145+
"-Take four large bunches of asparagus, scrape it nicely, cut off one inch\n" \
146+
"-of the tops, and lay them in water, chop the stalks and put them on the\n" \
147+
"-fire with a piece of bacon, a large onion cut up, and pepper and salt;\n" \
148+
"-add two quarts of water, boil them till the stalks are quite soft, then\n" \
149+
"-pulp them through a sieve, and strain the water to it, which must be put\n" \
150+
"-back in the pot; put into it a chicken cut up, with the tops of\n" \
151+
"-asparagus which had been laid by, boil it until these last articles are\n" \
152+
"-sufficiently done, thicken with flour, butter and milk, and serve it up.\n" \
153+
"diff --git a/beef.txt b/beef.txt\n" \
154+
"index 68f6182..f516580 100644\n" \
155+
"--- a/beef.txt\n" \
156+
"+++ b/beef.txt\n" \
157+
"@@ -1,22 +1,10 @@\n" \
158+
"-BEEF SOUP.\n" \
159+
"+ASPARAGUS SOUP!\n" \
160+
"\n" \
161+
"-Take the hind shin of beef, cut off all the flesh off the leg-bone,\n" \
162+
"-which must be taken away entirely, or the soup will be greasy. Wash the\n" \
163+
"-meat clean and lay it in a pot, sprinkle over it one small\n" \
164+
"-table-spoonful of pounded black pepper, and two of salt; three onions\n" \
165+
"-the size of a hen's egg, cut small, six small carrots scraped and cut\n" \
166+
"-up, two small turnips pared and cut into dice; pour on three quarts of\n" \
167+
"-water, cover the pot close, and keep it gently and steadily boiling five\n" \
168+
"-hours, which will leave about three pints of clear soup; do not let the\n" \
169+
"-pot boil over, but take off the scum carefully, as it rises. When it has\n" \
170+
"-boiled four hours, put in a small bundle of thyme and parsley, and a\n" \
171+
"-pint of celery cut small, or a tea-spoonful of celery seed pounded.\n" \
172+
"-These latter ingredients would lose their delicate flavour if boiled too\n" \
173+
"-much. Just before you take it up, brown it in the following manner: put\n" \
174+
"-a small table-spoonful of nice brown sugar into an iron skillet, set it\n" \
175+
"-on the fire and stir it till it melts and looks very dark, pour into it\n" \
176+
"-a ladle full of the soup, a little at a time; stirring it all the while.\n" \
177+
"-Strain this browning and mix it well with the soup; take out the bundle\n" \
178+
"-of thyme and parsley, put the nicest pieces of meat in your tureen, and\n" \
179+
"-pour on the soup and vegetables; put in some toasted bread cut in dice,\n" \
180+
"-and serve it up.\n" \
181+
"+Take four large bunches of asparagus, scrape it nicely, cut off one inch\n" \
182+
"+of the tops, and lay them in water, chop the stalks and put them on the\n" \
183+
"+fire with a piece of bacon, a large onion cut up, and pepper and salt;\n" \
184+
"+add two quarts of water, boil them till the stalks are quite soft, then\n" \
185+
"+pulp them through a sieve, and strain the water to it, which must be put\n" \
186+
"+back in the pot; put into it a chicken cut up, with the tops of\n" \
187+
"+asparagus which had been laid by, boil it until these last articles are\n" \
188+
"+sufficiently done, thicken with flour, butter and milk, and serve it up.\n" \
189+
"diff --git a/notbeef.txt b/notbeef.txt\n" \
190+
"new file mode 100644\n" \
191+
"index 0000000..68f6182\n" \
192+
"--- /dev/null\n" \
193+
"+++ b/notbeef.txt\n" \
194+
"@@ -0,0 +1,22 @@\n" \
195+
"+BEEF SOUP.\n" \
196+
"+\n" \
197+
"+Take the hind shin of beef, cut off all the flesh off the leg-bone,\n" \
198+
"+which must be taken away entirely, or the soup will be greasy. Wash the\n" \
199+
"+meat clean and lay it in a pot, sprinkle over it one small\n" \
200+
"+table-spoonful of pounded black pepper, and two of salt; three onions\n" \
201+
"+the size of a hen's egg, cut small, six small carrots scraped and cut\n" \
202+
"+up, two small turnips pared and cut into dice; pour on three quarts of\n" \
203+
"+water, cover the pot close, and keep it gently and steadily boiling five\n" \
204+
"+hours, which will leave about three pints of clear soup; do not let the\n" \
205+
"+pot boil over, but take off the scum carefully, as it rises. When it has\n" \
206+
"+boiled four hours, put in a small bundle of thyme and parsley, and a\n" \
207+
"+pint of celery cut small, or a tea-spoonful of celery seed pounded.\n" \
208+
"+These latter ingredients would lose their delicate flavour if boiled too\n" \
209+
"+much. Just before you take it up, brown it in the following manner: put\n" \
210+
"+a small table-spoonful of nice brown sugar into an iron skillet, set it\n" \
211+
"+on the fire and stir it till it melts and looks very dark, pour into it\n" \
212+
"+a ladle full of the soup, a little at a time; stirring it all the while.\n" \
213+
"+Strain this browning and mix it well with the soup; take out the bundle\n" \
214+
"+of thyme and parsley, put the nicest pieces of meat in your tureen, and\n" \
215+
"+pour on the soup and vegetables; put in some toasted bread cut in dice,\n" \
216+
"+and serve it up.\n"
217+
218+
#define DIFF_RENAME_A_TO_B_TO_C_EXACT \
219+
"diff --git a/asparagus.txt b/beef.txt\n" \
220+
"similarity index 100%\n" \
221+
"rename from asparagus.txt\n" \
222+
"rename to beef.txt\n" \
223+
"diff --git a/beef.txt b/notbeef.txt\n" \
224+
"similarity index 100%\n" \
225+
"rename from beef.txt\n" \
226+
"rename to notbeef.txt\n"
227+
136228
struct iterator_compare_data {
137229
struct merge_index_entry *expected;
138230
size_t cnt;

tests/apply/both.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,53 @@ void test_apply_both__rename_and_modify(void)
449449

450450
git_diff_free(diff);
451451
}
452+
453+
void test_apply_both__rename_a_to_b_to_c(void)
454+
{
455+
git_diff *diff;
456+
457+
struct merge_index_entry both_expected[] = {
458+
{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "beef.txt" },
459+
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
460+
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
461+
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "notbeef.txt" },
462+
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
463+
{ 0100644, "94d2c01087f48213bd157222d54edfefd77c9bba", 0, "veal.txt" },
464+
};
465+
size_t both_expected_cnt = sizeof(both_expected) /
466+
sizeof(struct merge_index_entry);
467+
468+
cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_A_TO_B_TO_C,
469+
strlen(DIFF_RENAME_A_TO_B_TO_C)));
470+
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
471+
472+
validate_apply_index(repo, both_expected, both_expected_cnt);
473+
validate_apply_workdir(repo, both_expected, both_expected_cnt);
474+
475+
git_diff_free(diff);
476+
}
477+
478+
void test_apply_both__rename_a_to_b_to_c_exact(void)
479+
{
480+
git_diff *diff;
481+
482+
struct merge_index_entry both_expected[] = {
483+
{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "beef.txt" },
484+
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
485+
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
486+
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "notbeef.txt" },
487+
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
488+
{ 0100644, "94d2c01087f48213bd157222d54edfefd77c9bba", 0, "veal.txt" },
489+
};
490+
size_t both_expected_cnt = sizeof(both_expected) /
491+
sizeof(struct merge_index_entry);
492+
493+
cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_A_TO_B_TO_C_EXACT,
494+
strlen(DIFF_RENAME_A_TO_B_TO_C_EXACT)));
495+
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
496+
497+
validate_apply_index(repo, both_expected, both_expected_cnt);
498+
validate_apply_workdir(repo, both_expected, both_expected_cnt);
499+
500+
git_diff_free(diff);
501+
}

0 commit comments

Comments
 (0)