diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2018-07-10 16:13:17 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2018-11-05 15:53:59 +0000 |
commit | db6b11649e12fc0e8e58ad98087da383096ae662 (patch) | |
tree | f3b130db8e4a2561390ee4141337266951392af4 /tests/apply | |
parent | af33210b735b760debc03ce558ff62c3834f0a5b (diff) | |
download | libgit2-db6b11649e12fc0e8e58ad98087da383096ae662.tar.gz |
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.
Diffstat (limited to 'tests/apply')
-rw-r--r-- | tests/apply/callbacks.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/apply/callbacks.c b/tests/apply/callbacks.c new file mode 100644 index 000000000..60799df09 --- /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); +} |