apply tests: test delta callback errors Test that we can return an error from the apply delta callback and the error code is propagated back to the caller.
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
diff --git a/tests/apply/callbacks.c b/tests/apply/callbacks.c
new file mode 100644
index 0000000..60799df
--- /dev/null
+++ b/tests/apply/callbacks.c
@@ -0,0 +1,52 @@
+#include "clar_libgit2.h"
+#include "apply_helpers.h"
+
+static git_repository *repo;
+
+#define TEST_REPO_PATH "merge-recursive"
+
+void test_apply_callbacks__initialize(void)
+{
+ git_oid oid;
+ git_commit *commit;
+
+ repo = cl_git_sandbox_init(TEST_REPO_PATH);
+
+ git_oid_fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707");
+ cl_git_pass(git_commit_lookup(&commit, repo, &oid));
+ cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL));
+ git_commit_free(commit);
+}
+
+void test_apply_callbacks__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+static int delta_abort_cb(const git_diff_delta *delta, void *payload)
+{
+ GIT_UNUSED(payload);
+
+ if (!strcmp(delta->old_file.path, "veal.txt"))
+ return -99;
+
+ return 0;
+}
+
+void test_apply_callbacks__delta_aborts(void)
+{
+ git_diff *diff;
+ git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
+
+ opts.delta_cb = delta_abort_cb;
+
+ cl_git_pass(git_diff_from_buffer(&diff,
+ DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
+ cl_git_fail_with(-99,
+ git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, &opts));
+
+ validate_index_unchanged(repo);
+ validate_workdir_unchanged(repo);
+
+ git_diff_free(diff);
+}