Skip to content

Commit 1186632

Browse files
committed
test: add test that regenerates patches with spaces in filename
This currently crashes, proposed fix in subsequent commit.
1 parent 2a0d0bd commit 1186632

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

tests/libgit2/diff/parse.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,32 @@ void test_diff_parse__new_file_with_space(void)
431431
git_diff_free(diff);
432432
}
433433

434+
void test_diff_parse__new_file_with_space_and_regenerate_patch(void)
435+
{
436+
const char *content = PATCH_ORIGINAL_NEW_FILE_WITH_SPACE;
437+
git_diff *diff = NULL;
438+
git_buf buf = GIT_BUF_INIT;
439+
440+
cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
441+
cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
442+
443+
git_buf_dispose(&buf);
444+
git_diff_free(diff);
445+
}
446+
447+
void test_diff_parse__delete_file_with_space_and_regenerate_patch(void)
448+
{
449+
const char *content = PATCH_DELETE_FILE_WITH_SPACE;
450+
git_diff *diff = NULL;
451+
git_buf buf = GIT_BUF_INIT;
452+
453+
cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
454+
cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
455+
456+
git_buf_dispose(&buf);
457+
git_diff_free(diff);
458+
}
459+
434460
void test_diff_parse__crlf(void)
435461
{
436462
const char *text = PATCH_CRLF;

tests/libgit2/patch/patch_common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,15 @@
933933
"@@ -0,0 +1 @@\n" \
934934
"+a\n"
935935

936+
#define PATCH_DELETE_FILE_WITH_SPACE \
937+
"diff --git a/sp ace.txt b/sp ace.txt\n" \
938+
"deleted file mode 100644\n" \
939+
"index 789819226..000000000\n" \
940+
"--- a/sp ace.txt\n" \
941+
"+++ /dev/null\n" \
942+
"@@ -1 +0,0 @@\n" \
943+
"-a\n"
944+
936945
#define PATCH_CRLF \
937946
"diff --git a/test-file b/test-file\r\n" \
938947
"new file mode 100644\r\n" \

0 commit comments

Comments
 (0)