#!/bin/sh

# Test interdiff with patch2 having headers between +++ and @@
# This tests that interdiff can handle extra headers (like "index") between
# the +++ line and @@ line in patch2, without incorrectly reporting it as empty

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

# Create first patch (simple unified diff)
cat << EOF > patch1
--- a/file.txt
+++ b/file.txt
@@ -1,3 +1,3 @@
 line one
-line two
+line TWO
 line three
EOF

# Create second patch (git-style with index line between +++ and @@)
cat << EOF > patch2
--- a/file.txt
+++ b/file.txt
index abc123..def456 100644
@@ -1,3 +1,3 @@
 line one
-line two
+line 2
 line three
EOF

# Expected interdiff output
# This shows the difference between changing "two" to "TWO" vs "2"
cat << EOF > expected
diff -u b/file.txt b/file.txt
--- b/file.txt
+++ b/file.txt
@@ -1,3 +1,3 @@
 line one
-line TWO
+line 2
 line three
EOF

# Run interdiff - should succeed without errors
${INTERDIFF} patch1 patch2 2>errors >actual || exit 1

# Should not have any errors (especially not "patch2 is empty" or similar)
[ -s errors ] && exit 1

# Compare the actual output with expected
diff -u expected actual || exit 1

exit 0
