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
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ TESTS = tests/newline1/run-test \
tests/combine1/run-test \
tests/combine2/run-test \
tests/combine3/run-test \
tests/combine4/run-test \
tests/gendiff1/run-test \
tests/gendiff2/run-test \
tests/comma/run-test \
Expand Down
33 changes: 24 additions & 9 deletions src/interdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,16 +1055,31 @@ output_delta (FILE *p1, FILE *p2, FILE *out)
tmpp1fd = xmkstemp (tmpp1);
tmpp2fd = xmkstemp (tmpp2);

do {
if (oldname) {
free (oldname);
oldname = NULL;
}
if (getline (&oldname, &namelen, p1) < 0)
error (EXIT_FAILURE, errno, "Bad patch #1");
if (mode == mode_combine) {
/* For combinediff, we want the --- line from patch1 (original file) */
do {
if (oldname) {
free (oldname);
oldname = NULL;
}
if (getline (&oldname, &namelen, p1) < 0)
error (EXIT_FAILURE, errno, "Bad patch #1");

} while (strncmp (oldname, "+++ ", 4));
oldname[strlen (oldname) - 1] = '\0';
} while (strncmp (oldname, "--- ", 4));
oldname[strlen (oldname) - 1] = '\0';
} else {
/* For interdiff, use +++ line from patch1 */
do {
if (oldname) {
free (oldname);
oldname = NULL;
}
if (getline (&oldname, &namelen, p1) < 0)
error (EXIT_FAILURE, errno, "Bad patch #1");

} while (strncmp (oldname, "+++ ", 4));
oldname[strlen (oldname) - 1] = '\0';
}

do {
if (newname) {
Expand Down
46 changes: 46 additions & 0 deletions tests/combine4/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# This is a combinediff(1) testcase.
# Bug report: combinediff produces incorrect file path prefixes
# Expected: diff -u a/file.c a/file.c
# Actual: diff -u b/file.c b/file.c
#
# This test expects the correct behavior and will fail until the bug is fixed.
# It's added to XFAIL_TESTS to mark it as an expected failure.

. ${top_srcdir-.}/tests/common.sh

# Create the patch files from the bug report
cat << EOF > first.patch
--- a/file.c
+++ b/file.c
@@ -0,0 +1,3 @@
+a
+b
+c
EOF

cat << EOF > second.patch
--- a/file.c
+++ b/file.c
@@ -1,3 +1,2 @@
a
b
-c
EOF

# Run combinediff with -p1 as mentioned in the bug report
${COMBINEDIFF} -p1 first.patch second.patch 2>errors >combined.patch || exit 1
[ -s errors ] && exit 1

# Check that the combined patch exists and is not empty
[ -s combined.patch ] || exit 1

# Check that the combined patch has the correct header format
head -3 combined.patch > header
cat << EOF > expected
diff -u a/file.c b/file.c
--- a/file.c
+++ b/file.c
EOF
cmp header expected || exit 1
4 changes: 2 additions & 2 deletions tests/trimlast2/run-test
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ ${COMBINEDIFF} patch1 patch2 > patch12 2>errors || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - patch12 || exit 1
diff -u file file
--- file
diff -u file.orig file
--- file.orig
+++ file
@@ -1,4 +1,4 @@
-0
Expand Down