Skip to content

Commit 585fbd7

Browse files
author
Max Kostyukevich
committed
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.
1 parent 630127e commit 585fbd7

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

tests/apply/fromdiff.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ void test_apply_fromdiff__lastline(void)
131131
PATCH_ORIGINAL_TO_CHANGE_LASTLINE, NULL));
132132
}
133133

134+
void test_apply_fromdiff__change_middle_and_lastline_nocontext(void)
135+
{
136+
git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
137+
diff_opts.context_lines = 0;
138+
139+
cl_git_pass(apply_buf(
140+
FILE_ORIGINAL, "file.txt",
141+
FILE_CHANGE_MIDDLE_AND_LASTLINE, "file.txt",
142+
PATCH_ORIGINAL_TO_CHANGE_MIDDLE_AND_LASTLINE_NOCONTEXT, &diff_opts));
143+
}
144+
134145
void test_apply_fromdiff__prepend(void)
135146
{
136147
cl_git_pass(apply_buf(

tests/patch/patch_common.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,32 @@
263263
"-(this line is changed)\n" \
264264
"+(THIS line is changed!)\n"
265265

266+
/* A change in the middle and a deletion of the newline at the end of the file */
267+
268+
#define FILE_CHANGE_MIDDLE_AND_LASTLINE \
269+
"hey!\n" \
270+
"this is some context!\n" \
271+
"around some lines\n" \
272+
"that will change\n" \
273+
"yes it is!\n" \
274+
"(THIS line is changed!)\n" \
275+
"and this\n" \
276+
"is additional context\n" \
277+
"BELOW it! - (THIS line is changed!)"
278+
279+
#define PATCH_ORIGINAL_TO_CHANGE_MIDDLE_AND_LASTLINE_NOCONTEXT \
280+
"diff --git a/file.txt b/file.txt\n" \
281+
"index 9432026..e05d36c 100644\n" \
282+
"--- a/file.txt\n" \
283+
"+++ b/file.txt\n" \
284+
"@@ -6 +6 @@ yes it is!\n" \
285+
"-(this line is changed)\n" \
286+
"+(THIS line is changed!)\n" \
287+
"@@ -9 +9 @@ is additional context\n" \
288+
"-below it!\n" \
289+
"+BELOW it! - (THIS line is changed!)\n" \
290+
"\\ No newline at end of file\n"
291+
266292
/* A deletion at the beginning of the file and a change in the middle */
267293

268294
#define FILE_DELETE_AND_CHANGE \

0 commit comments

Comments
 (0)