mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
LibDiff+patch: Support multiple patches in a single patch file
Multiple patches may be concatenated in the same patch file, such as git commits which are changing multiple files at the same time. To handle this, parse each patch in order in the patch file, and apply each patch sequentially. To determine whether we are at the end of a patch (and not just parsing another hunk) the parser will look for a leading '@@ ' after every hunk. If that is found, there is another hunk. Otherwise, we must be at the end of this patch.
This commit is contained in:
parent
ddbd77cca1
commit
dd373eacbc
4 changed files with 57 additions and 20 deletions
|
@ -165,3 +165,25 @@ TEST_CASE(add_file_from_scratch)
|
|||
|
||||
EXPECT_FILE_EQ(MUST(String::formatted("{}/file_to_add", s_test_dir)), "Hello, friends!\n");
|
||||
}
|
||||
|
||||
TEST_CASE(two_patches_in_single_patch_file)
|
||||
{
|
||||
PatchSetup setup;
|
||||
|
||||
auto patch = R"(
|
||||
--- /dev/null
|
||||
+++ a/first_file_to_add
|
||||
@@ -0,0 +1 @@
|
||||
+Hello, friends!
|
||||
--- /dev/null
|
||||
+++ a/second_file_to_add
|
||||
@@ -0,0 +1 @@
|
||||
+Hello, friends!
|
||||
)"sv;
|
||||
|
||||
run_patch({}, patch, "patching file first_file_to_add\n"
|
||||
"patching file second_file_to_add\n"sv);
|
||||
|
||||
EXPECT_FILE_EQ(MUST(String::formatted("{}/first_file_to_add", s_test_dir)), "Hello, friends!\n");
|
||||
EXPECT_FILE_EQ(MUST(String::formatted("{}/second_file_to_add", s_test_dir)), "Hello, friends!\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue