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

LibDiff: Reject patches adding files when a file already exists

We should still add an informational message about when this happens
before we even get here - but we still shouldn't be able to locate a
place to apply a hunk as it ends up producing unexpected results where
the patch is prepended to the existing file.
This commit is contained in:
Shannon Booth 2024-02-10 23:52:14 +13:00 committed by Jelle Raaijmakers
parent c72c3d5f3b
commit df6a627323
2 changed files with 34 additions and 3 deletions

View file

@ -200,3 +200,23 @@ TEST_CASE(two_patches_in_single_patch_file)
EXPECT_FILE_EQ(ByteString::formatted("{}/first_file_to_add", s_test_dir), "Hello, friends!\n");
EXPECT_FILE_EQ(ByteString::formatted("{}/second_file_to_add", s_test_dir), "Hello, friends!\n");
}
TEST_CASE(patch_adding_file_to_existing_file)
{
PatchSetup setup;
auto patch = R"(
--- /dev/null
+++ a
@@ -0,0 +1 @@
+1
)"sv;
auto file = "a\n"sv;
auto input = MUST(Core::File::open(ByteString::formatted("{}/a", s_test_dir), Core::File::OpenMode::Write));
MUST(input->write_until_depleted(file.bytes()));
run_patch(ExpectSuccess::No, {}, patch);
EXPECT_FILE_EQ(ByteString::formatted("{}/a", s_test_dir), "a\n"sv);
}