diff options
author | Max Kostyukevich <maxim.kostyukevich@mera.com> | 2019-08-28 23:18:31 +0300 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2020-03-26 16:20:11 +0100 |
commit | 5e5a9cce64366be8b4e117de92cb3b41d25648a2 (patch) | |
tree | 884ab4e78c84e1ea66cd49091830020a4a3f2091 | |
parent | 0126e3fc1317cf7a1ef0fd5ad1af460be547701e (diff) | |
download | libgit2-5e5a9cce64366be8b4e117de92cb3b41d25648a2.tar.gz |
apply: Test for EOFNL mishandling when several hunks are processed
Introduce an unit test to validate that git_apply__patch() properly
handles EOFNL changes in case of patches with several hunks.
-rw-r--r-- | tests/apply/fromdiff.c | 11 | ||||
-rw-r--r-- | tests/patch/patch_common.h | 26 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/apply/fromdiff.c b/tests/apply/fromdiff.c index 832415d79..e9329f6d3 100644 --- a/tests/apply/fromdiff.c +++ b/tests/apply/fromdiff.c @@ -131,6 +131,17 @@ void test_apply_fromdiff__lastline(void) PATCH_ORIGINAL_TO_CHANGE_LASTLINE, NULL)); } +void test_apply_fromdiff__change_middle_and_lastline_nocontext(void) +{ + git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT; + diff_opts.context_lines = 0; + + cl_git_pass(apply_buf( + FILE_ORIGINAL, "file.txt", + FILE_CHANGE_MIDDLE_AND_LASTLINE, "file.txt", + PATCH_ORIGINAL_TO_CHANGE_MIDDLE_AND_LASTLINE_NOCONTEXT, &diff_opts)); +} + void test_apply_fromdiff__prepend(void) { cl_git_pass(apply_buf( diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h index 2db8d933f..690e0a662 100644 --- a/tests/patch/patch_common.h +++ b/tests/patch/patch_common.h @@ -263,6 +263,32 @@ "-(this line is changed)\n" \ "+(THIS line is changed!)\n" +/* A change in the middle and a deletion of the newline at the end of the file */ + +#define FILE_CHANGE_MIDDLE_AND_LASTLINE \ + "hey!\n" \ + "this is some context!\n" \ + "around some lines\n" \ + "that will change\n" \ + "yes it is!\n" \ + "(THIS line is changed!)\n" \ + "and this\n" \ + "is additional context\n" \ + "BELOW it! - (THIS line is changed!)" + +#define PATCH_ORIGINAL_TO_CHANGE_MIDDLE_AND_LASTLINE_NOCONTEXT \ + "diff --git a/file.txt b/file.txt\n" \ + "index 9432026..e05d36c 100644\n" \ + "--- a/file.txt\n" \ + "+++ b/file.txt\n" \ + "@@ -6 +6 @@ yes it is!\n" \ + "-(this line is changed)\n" \ + "+(THIS line is changed!)\n" \ + "@@ -9 +9 @@ is additional context\n" \ + "-below it!\n" \ + "+BELOW it! - (THIS line is changed!)\n" \ + "\\ No newline at end of file\n" + /* A deletion at the beginning of the file and a change in the middle */ #define FILE_DELETE_AND_CHANGE \ |