diff --git a/Makefile.am b/Makefile.am index 63cab01e..d3c3f981 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/interdiff.c b/src/interdiff.c index fc240843..48acf864 100644 --- a/src/interdiff.c +++ b/src/interdiff.c @@ -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) { diff --git a/tests/combine4/run-test b/tests/combine4/run-test new file mode 100755 index 00000000..db1408a3 --- /dev/null +++ b/tests/combine4/run-test @@ -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 diff --git a/tests/trimlast2/run-test b/tests/trimlast2/run-test index 4148df8e..1c6fd276 100755 --- a/tests/trimlast2/run-test +++ b/tests/trimlast2/run-test @@ -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