patch: add tests for aborting hunk callback
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
diff --git a/tests/apply/partial.c b/tests/apply/partial.c
index bdbf35a..243dccf 100644
--- a/tests/apply/partial.c
+++ b/tests/apply/partial.c
@@ -46,6 +46,33 @@ static int skip_change(
return (hunk->new_lines == hunk->old_lines) ? 1 : 0;
}
+static int abort_addition(
+ const git_diff_hunk *hunk,
+ void *payload)
+{
+ GIT_UNUSED(payload);
+
+ return (hunk->new_lines > hunk->old_lines) ? GIT_EUSER : 0;
+}
+
+static int abort_deletion(
+ const git_diff_hunk *hunk,
+ void *payload)
+{
+ GIT_UNUSED(payload);
+
+ return (hunk->new_lines < hunk->old_lines) ? GIT_EUSER : 0;
+}
+
+static int abort_change(
+ const git_diff_hunk *hunk,
+ void *payload)
+{
+ GIT_UNUSED(payload);
+
+ return (hunk->new_lines == hunk->old_lines) ? GIT_EUSER : 0;
+}
+
static int apply_buf(
const char *old,
const char *oldname,
@@ -103,6 +130,17 @@ void test_apply_partial__prepend_and_change_nocontext_skip_addition(void)
FILE_CHANGE_MIDDLE, &diff_opts, skip_addition, NULL));
}
+void test_apply_partial__prepend_and_change_nocontext_abort_addition(void)
+{
+ git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
+ diff_opts.context_lines = 0;
+
+ cl_git_fail(apply_buf(
+ FILE_ORIGINAL, "file.txt",
+ FILE_PREPEND_AND_CHANGE, "file.txt",
+ FILE_ORIGINAL, &diff_opts, abort_addition, NULL));
+}
+
void test_apply_partial__prepend_and_change_skip_change(void)
{
cl_git_pass(apply_buf(
@@ -122,6 +160,17 @@ void test_apply_partial__prepend_and_change_nocontext_skip_change(void)
FILE_PREPEND, &diff_opts, skip_change, NULL));
}
+void test_apply_partial__prepend_and_change_nocontext_abort_change(void)
+{
+ git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
+ diff_opts.context_lines = 0;
+
+ cl_git_fail(apply_buf(
+ FILE_ORIGINAL, "file.txt",
+ FILE_PREPEND_AND_CHANGE, "file.txt",
+ FILE_PREPEND, &diff_opts, abort_change, NULL));
+}
+
void test_apply_partial__delete_and_change_skip_deletion(void)
{
cl_git_pass(apply_buf(
@@ -141,6 +190,17 @@ void test_apply_partial__delete_and_change_nocontext_skip_deletion(void)
FILE_CHANGE_MIDDLE, &diff_opts, skip_deletion, NULL));
}
+void test_apply_partial__delete_and_change_nocontext_abort_deletion(void)
+{
+ git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
+ diff_opts.context_lines = 0;
+
+ cl_git_fail(apply_buf(
+ FILE_ORIGINAL, "file.txt",
+ FILE_DELETE_AND_CHANGE, "file.txt",
+ FILE_ORIGINAL, &diff_opts, abort_deletion, NULL));
+}
+
void test_apply_partial__delete_and_change_skip_change(void)
{
cl_git_pass(apply_buf(
@@ -159,3 +219,14 @@ void test_apply_partial__delete_and_change_nocontext_skip_change(void)
FILE_DELETE_AND_CHANGE, "file.txt",
FILE_DELETE_FIRSTLINE, &diff_opts, skip_change, NULL));
}
+
+void test_apply_partial__delete_and_change_nocontext_abort_change(void)
+{
+ git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
+ diff_opts.context_lines = 0;
+
+ cl_git_fail(apply_buf(
+ FILE_ORIGINAL, "file.txt",
+ FILE_DELETE_AND_CHANGE, "file.txt",
+ FILE_DELETE_FIRSTLINE, &diff_opts, abort_change, NULL));
+}