Commit 89b5a56e by Edward Thomson

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.
parent 6fecf4d1
......@@ -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;
......
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment