apply tests: tests a diff w/ many small changes
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
diff --git a/tests/apply/apply_helpers.h b/tests/apply/apply_helpers.h
index a28a813..8f94d39 100644
--- a/tests/apply/apply_helpers.h
+++ b/tests/apply/apply_helpers.h
@@ -52,6 +52,66 @@
"old mode 100644\n" \
"new mode 100755\n"
+#define DIFF_MANY_CHANGES_ONE \
+ "diff --git a/veal.txt b/veal.txt\n" \
+ "index 94d2c01..c9d7d5d 100644\n" \
+ "--- a/veal.txt\n" \
+ "+++ b/veal.txt\n" \
+ "@@ -1,2 +1,2 @@\n" \
+ "-VEAL SOUP!\n" \
+ "+VEAL SOUP\n" \
+ " \n" \
+ "@@ -4,3 +4,2 @@\n" \
+ " spoonful of black pepper pounded, and two of salt, with two or three\n" \
+ "-slices of lean ham; let it boil steadily two hours; skim it\n" \
+ " occasionally, then put into it a shin of veal, let it boil two hours\n" \
+ "@@ -8,3 +7,3 @@\n" \
+ " should rise, take a gill of good cream, mix with it two table-spoonsful\n" \
+ "-of flour very nicely, and the yelks of two eggs beaten well, strain this\n" \
+ "+OF FLOUR very nicely, and the yelks of two eggs beaten well, strain this\n" \
+ " mixture, and add some chopped parsley; pour some soup on by degrees,\n" \
+ "@@ -12,2 +11,3 @@\n" \
+ " boiled two or three minutes to take off the raw taste of the eggs. If\n" \
+ "+Inserted line.\n" \
+ " the cream be not perfectly sweet, and the eggs quite new, the thickening\n" \
+ "@@ -15,3 +15,3 @@\n" \
+ " in, first taking off their skins, by letting them stand a few minutes in\n" \
+ "-hot water, when they may be easily peeled. When made in this way you\n" \
+ "+Changed line.\n" \
+ " must thicken it with the flour only. Any part of the veal may be used,\n"
+
+#define DIFF_MANY_CHANGES_TWO \
+ "diff --git a/veal.txt b/veal.txt\n" \
+ "index 94d2c01..6b943d6 100644\n" \
+ "--- a/veal.txt\n" \
+ "+++ b/veal.txt\n" \
+ "@@ -1,2 +1,2 @@\n" \
+ "-VEAL SOUP!\n" \
+ "+VEAL SOUP!!!\n" \
+ " \n" \
+ "@@ -4,3 +4,2 @@\n" \
+ " spoonful of black pepper pounded, and two of salt, with two or three\n" \
+ "-slices of lean ham; let it boil steadily two hours; skim it\n" \
+ " occasionally, then put into it a shin of veal, let it boil two hours\n" \
+ "@@ -8,3 +7,3 @@\n" \
+ " should rise, take a gill of good cream, mix with it two table-spoonsful\n" \
+ "-of flour very nicely, and the yelks of two eggs beaten well, strain this\n" \
+ "+of flour very nicely, AND the yelks of two eggs beaten well, strain this\n" \
+ " mixture, and add some chopped parsley; pour some soup on by degrees,\n" \
+ "@@ -12,2 +11,3 @@\n" \
+ " boiled two or three minutes to take off the raw taste of the eggs. If\n" \
+ "+New line.\n" \
+ " the cream be not perfectly sweet, and the eggs quite new, the thickening\n" \
+ "@@ -15,4 +15,5 @@\n" \
+ " in, first taking off their skins, by letting them stand a few minutes in\n" \
+ "-hot water, when they may be easily peeled. When made in this way you\n" \
+ "-must thicken it with the flour only. Any part of the veal may be used,\n" \
+ "-but the shin or knuckle is the nicest.\n" \
+ "+HOT water, when they may be easily peeled. When made in this way you\n" \
+ "+must THICKEN it with the flour only. Any part of the veal may be used,\n" \
+ "+but the shin OR knuckle is the nicest.\n" \
+ "+Another new line.\n" \
+
struct iterator_compare_data {
struct merge_index_entry *expected;
size_t cnt;
diff --git a/tests/apply/workdir.c b/tests/apply/workdir.c
index ab1dc25..1a82925 100644
--- a/tests/apply/workdir.c
+++ b/tests/apply/workdir.c
@@ -304,3 +304,55 @@ void test_apply_workdir__change_mode(void)
git_diff_free(diff);
#endif
}
+
+void test_apply_workdir__apply_many_changes_one(void)
+{
+ git_diff *diff;
+ git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
+
+ struct merge_index_entry workdir_expected[] = {
+ { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
+ { 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
+ { 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
+ { 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
+ { 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
+ { 0100644, "c9d7d5d58088bc91f6e06f17ca3a205091568d3a", 0, "veal.txt" },
+ };
+ size_t workdir_expected_cnt = sizeof(workdir_expected) /
+ sizeof(struct merge_index_entry);
+
+ cl_git_pass(git_diff_from_buffer(&diff,
+ DIFF_MANY_CHANGES_ONE, strlen(DIFF_MANY_CHANGES_ONE)));
+ cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, &opts));
+
+ validate_index_unchanged(repo);
+ validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
+
+ git_diff_free(diff);
+}
+
+void test_apply_workdir__apply_many_changes_two(void)
+{
+ git_diff *diff;
+ git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
+
+ struct merge_index_entry workdir_expected[] = {
+ { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
+ { 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
+ { 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
+ { 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
+ { 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
+ { 0100644, "6b943d65af6d8db74d747284fa4ca7d716ad5bbb", 0, "veal.txt" },
+ };
+ size_t workdir_expected_cnt = sizeof(workdir_expected) /
+ sizeof(struct merge_index_entry);
+
+ cl_git_pass(git_diff_from_buffer(&diff,
+ DIFF_MANY_CHANGES_TWO, strlen(DIFF_MANY_CHANGES_TWO)));
+ cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, &opts));
+
+ validate_index_unchanged(repo);
+ validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
+
+ git_diff_free(diff);
+}