1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 07:47:48 +00:00

patch: Support creation of a file

Previously patch would always expect the file that it was patching to
exist (even it were empty). If we know that the patch is creating a file
from nothing (i.e has a start line of '0'), then we treat a file that
doesn't exist as if it has no content lines.
This commit is contained in:
Shannon Booth 2023-07-10 18:48:32 +12:00 committed by Sam Atkins
parent 0612e8ec6a
commit f893e0820f
2 changed files with 40 additions and 3 deletions

View file

@ -149,3 +149,19 @@ TEST_CASE(strip_path_partially)
EXPECT_FILE_EQ(MUST(String::formatted("{}/to/basename", s_test_dir)), "Hello, friends!\n");
}
TEST_CASE(add_file_from_scratch)
{
PatchSetup setup;
auto patch = R"(
--- /dev/null
+++ a/file_to_add
@@ -0,0 +1 @@
+Hello, friends!
)"sv;
run_patch({}, patch, "patching file file_to_add\n"sv);
EXPECT_FILE_EQ(MUST(String::formatted("{}/file_to_add", s_test_dir)), "Hello, friends!\n");
}