Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/applier.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright 2022-2026 Shannon Booth <shannon.ml.booth@gmail.com>

#include <cmath>
#include <istream>
#include <limits>
#include <ostream>
Expand Down Expand Up @@ -163,7 +164,7 @@ static void print_hunk_statistics(std::ostream& out, size_t hunk_num, bool skipp
out << " with fuzz " << location.fuzz;
if (offset_error != 0) {
out << " (offset " << offset_error << " line";
if (offset_error > 1)
if (std::abs(offset_error) > 1)
out << "s";
out << ")";
}
Expand Down
39 changes: 38 additions & 1 deletion tests/test_applier.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright 2022-2023 Shannon Booth <shannon.ml.booth@gmail.com>
// Copyright 2022-2026 Shannon Booth <shannon.ml.booth@gmail.com>

#include <patch/process.h>
#include <patch/test.h>
Expand Down Expand Up @@ -976,6 +976,43 @@ int main()
)");
}

PATCH_TEST(applier_context_diff_with_negative_offset)
{
{
Patch::File file("diff.patch", std::ios_base::out);
file << R"(
--- a.c 2022-10-23 21:25:13.856207590 +1300
+++ b.c 2022-10-23 21:25:25.511912172 +1300
@@ -3,4 +3,4 @@
int main()
{
- return 0;
+ return 1;
}
)";
}

{
Patch::File file("a.c", std::ios_base::out);
file << R"(int main()
{
return 0;
}
)";
}

Process process(patch_path, { patch_path, "-i", "diff.patch", nullptr });
EXPECT_EQ(process.stdout_data(), "patching file a.c\nHunk #1 succeeded at 1 (offset -2 lines).\n");
EXPECT_EQ(process.stderr_data(), "");
EXPECT_EQ(process.return_code(), 0);

EXPECT_FILE_EQ("a.c", R"(int main()
{
return 1;
}
)");
}

PATCH_TEST(applier_unified_diff_with_only_whitespace_change_ignore_whitespace)
{
{
Expand Down
Loading