#!/bin/sh # This is a rediff(1) testcase. # Test: Preserve diff command headers in multi-file patches (GitHub issue #48) . ${top_srcdir-.}/tests/common.sh cat << "EOF" > patch.orig diff -rpU 3 old/a.c new/a.c --- old/a.c 2021-01-07 13:58:44.000000000 +0000 +++ new/a.c 2021-01-07 13:55:34.000000000 +0000 @@ -1,3 +1,4 @@ line1 line2 +added_line line3 diff -rpU 3 old/b.c new/b.c --- old/b.c 2021-01-07 14:01:32.000000000 +0000 +++ new/b.c 2021-01-07 13:57:02.000000000 +0000 @@ -1,3 +1,4 @@ another1 another2 +another_added another3 diff -rpU 3 old/c.c new/c.c --- old/c.c 2021-01-07 14:01:40.000000000 +0000 +++ new/c.c 2021-01-07 13:57:30.000000000 +0000 @@ -1,3 +1,6 @@ +#include + int main() { return 0; } EOF # Test with identical files (no changes) - this was the failing case ${REDIFF} patch.orig patch.orig > patch-rediffed 2>errors || exit 1 [ -s errors ] && exit 1 # Verify all diff command headers are preserved if ! grep -q "^diff -rpU 3 old/a.c new/a.c$" patch-rediffed; then echo "Missing diff header for a.c" >&2 exit 1 fi if ! grep -q "^diff -rpU 3 old/b.c new/b.c$" patch-rediffed; then echo "Missing diff header for b.c" >&2 exit 1 fi if ! grep -q "^diff -rpU 3 old/c.c new/c.c$" patch-rediffed; then echo "Missing diff header for c.c" >&2 exit 1 fi # Verify the output is identical to input when no changes are made cmp patch.orig patch-rediffed || exit 1 exit 0