Skip to content

Commit 9d65360

Browse files
Erik Aignerpks-t
authored andcommitted
tests: diff: test parsing diffs with a new file with spaces in its path
Add a test that verifies that we are able to parse patches which add a new file that has spaces in its path.
1 parent b349734 commit 9d65360

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/diff/parse.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,21 @@ void test_diff_parse__lineinfo(void)
359359
git_patch_free(patch);
360360
git_diff_free(diff);
361361
}
362+
363+
void test_diff_parse__new_file_with_space(void)
364+
{
365+
const char *content = PATCH_ORIGINAL_NEW_FILE_WITH_SPACE;
366+
git_patch *patch;
367+
git_diff *diff;
368+
369+
cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
370+
cl_git_pass(git_patch_from_diff((git_patch **) &patch, diff, 0));
371+
372+
cl_assert_equal_p(patch->diff_opts.old_prefix, NULL);
373+
cl_assert_equal_p(patch->delta->old_file.path, NULL);
374+
cl_assert_equal_s(patch->diff_opts.new_prefix, "b/");
375+
cl_assert_equal_s(patch->delta->new_file.path, "sp ace.txt");
376+
377+
git_patch_free(patch);
378+
git_diff_free(diff);
379+
}

tests/patch/patch_common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,12 @@
841841
"diff --git a/binary.bin b/binary.bin\n" \
842842
"index 27184d9..7c94f9e 100644\n" \
843843
"Binary files a/binary.bin and b/binary.bin differ\n"
844+
845+
#define PATCH_ORIGINAL_NEW_FILE_WITH_SPACE \
846+
"diff --git a/sp ace.txt b/sp ace.txt\n" \
847+
"new file mode 100644\n" \
848+
"index 000000000..789819226\n" \
849+
"--- /dev/null\n" \
850+
"+++ b/sp ace.txt\n" \
851+
"@@ -0,0 +1 @@\n" \
852+
"+a\n"

0 commit comments

Comments
 (0)