Commit b8840db746452a6c8ea792b7362c554cc2a5870a

Edward Thomson 2018-07-10T16:18:45

apply tests: test delta callback skip Test that we can return a non-zero value from the apply delta callback and it will skip the application of a given delta.

diff --git a/tests/apply/callbacks.c b/tests/apply/callbacks.c
index 60799df..91bdfa3 100644
--- a/tests/apply/callbacks.c
+++ b/tests/apply/callbacks.c
@@ -50,3 +50,41 @@ void test_apply_callbacks__delta_aborts(void)
 
 	git_diff_free(diff);
 }
+
+static int delta_skip_cb(const git_diff_delta *delta, void *payload)
+{
+	GIT_UNUSED(payload);
+
+	if (!strcmp(delta->old_file.path, "asparagus.txt"))
+		return 1;
+
+	return 0;
+}
+
+void test_apply_callbacks__delta_can_skip(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, "a7b066537e6be7109abfe4ff97b675d4e077da20", 0, "veal.txt" },
+	};
+	size_t workdir_expected_cnt = sizeof(workdir_expected) /
+	    sizeof(struct merge_index_entry);
+
+	opts.delta_cb = delta_skip_cb;
+
+	cl_git_pass(git_diff_from_buffer(&diff,
+		DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
+	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);
+}