summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIliyas Jorio <iliyas@jor.io>2022-03-13 17:36:48 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2022-04-12 14:17:48 -0400
commit8e29fa38c0c519e6b1fb1fccb87543c0c0dc123f (patch)
tree96aedefd9a176245d1399dc53c07fd1bd1ecbf6b
parentc93609120a76dcd25369dca4be69dbca7dfdaff7 (diff)
downloadlibgit2-8e29fa38c0c519e6b1fb1fccb87543c0c0dc123f.tar.gz
test: add test that regenerates patches with spaces in filename
This currently crashes, proposed fix in subsequent commit.
-rw-r--r--tests/diff/parse.c26
-rw-r--r--tests/patch/patch_common.h9
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/diff/parse.c b/tests/diff/parse.c
index d3a0c8de6..9c3f798e4 100644
--- a/tests/diff/parse.c
+++ b/tests/diff/parse.c
@@ -431,6 +431,32 @@ void test_diff_parse__new_file_with_space(void)
git_diff_free(diff);
}
+void test_diff_parse__new_file_with_space_and_regenerate_patch(void)
+{
+ const char *content = PATCH_ORIGINAL_NEW_FILE_WITH_SPACE;
+ git_diff *diff = NULL;
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
+ cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
+
+ git_buf_dispose(&buf);
+ git_diff_free(diff);
+}
+
+void test_diff_parse__delete_file_with_space_and_regenerate_patch(void)
+{
+ const char *content = PATCH_DELETE_FILE_WITH_SPACE;
+ git_diff *diff = NULL;
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
+ cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
+
+ git_buf_dispose(&buf);
+ git_diff_free(diff);
+}
+
void test_diff_parse__crlf(void)
{
const char *text = PATCH_CRLF;
diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h
index 1e03889fc..7e2cb6a58 100644
--- a/tests/patch/patch_common.h
+++ b/tests/patch/patch_common.h
@@ -933,6 +933,15 @@
"@@ -0,0 +1 @@\n" \
"+a\n"
+#define PATCH_DELETE_FILE_WITH_SPACE \
+ "diff --git a/sp ace.txt b/sp ace.txt\n" \
+ "deleted file mode 100644\n" \
+ "index 789819226..000000000\n" \
+ "--- a/sp ace.txt\n" \
+ "+++ /dev/null\n" \
+ "@@ -1 +0,0 @@\n" \
+ "-a\n"
+
#define PATCH_CRLF \
"diff --git a/test-file b/test-file\r\n" \
"new file mode 100644\r\n" \