Skip to content

Commit 1f6298a

Browse files
committed
Add another test case for -p/--strip/--git-prefixes interactions
Assisted-by: Cursor
1 parent 35d4bb9 commit 1f6298a

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ TESTS = tests/newline1/run-test \
279279
tests/git-binary-issue57/run-test \
280280
tests/git-mode-issue59/run-test \
281281
tests/git-exclude-issue27/run-test \
282-
tests/git-prefixes-option/run-test
282+
tests/git-prefixes-option/run-test \
283+
tests/git-prefixes-with-strip/run-test
283284

284285
# These ones don't work yet.
285286
# Feel free to send me patches. :-)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/sh
2+
3+
# This is a filterdiff(1) testcase.
4+
# Test: Verify interaction between --git-prefixes, -p, and --strip options
5+
# This tests the order of operations and how they affect each other
6+
7+
. ${top_srcdir-.}/tests/common.sh
8+
9+
# Create a Git patch with a/ and b/ prefixes and nested paths
10+
cat << EOF > git-test.patch
11+
diff --git a/level1/level2/file1.txt b/level1/level2/file1.txt
12+
index abcdef1..1234567 100644
13+
--- a/level1/level2/file1.txt
14+
+++ b/level1/level2/file1.txt
15+
@@ -1 +1 @@
16+
-old content
17+
+new content
18+
diff --git a/other/path/file2.c b/other/path/file2.c
19+
index abcdef2..7890abc 100644
20+
--- a/other/path/file2.c
21+
+++ b/other/path/file2.c
22+
@@ -1 +1 @@
23+
-old code
24+
+new code
25+
EOF
26+
27+
# Test 1: --git-prefixes=keep (default) with -p and --strip
28+
# With keep: a/level1/level2/file1.txt -> -p1 -> level1/level2/file1.txt for matching
29+
# Then --strip=2 affects output: removes first 2 components from diff headers
30+
${FILTERDIFF} --git-prefixes=keep -p1 --strip=2 -i "level1/level2/file1.txt" git-test.patch 2>errors1 >result1 || exit 1
31+
[ -s errors1 ] && exit 1
32+
33+
cat << EOF | cmp - result1 || exit 1
34+
diff --git level2/file1.txt level2/file1.txt
35+
index abcdef1..1234567 100644
36+
--- level2/file1.txt
37+
+++ level2/file1.txt
38+
@@ -1 +1 @@
39+
-old content
40+
+new content
41+
EOF
42+
43+
# Test 2: --git-prefixes=strip with -p and --strip
44+
# With strip: a/level1/level2/file1.txt -> strip a/ -> level1/level2/file1.txt -> -p1 -> level2/file1.txt for matching
45+
# Then --strip=2 affects output
46+
${FILTERDIFF} --git-prefixes=strip -p1 --strip=2 -i "level2/file1.txt" git-test.patch 2>errors2 >result2 || exit 1
47+
[ -s errors2 ] && exit 1
48+
49+
cat << EOF | cmp - result2 || exit 1
50+
diff --git level2/file1.txt level2/file1.txt
51+
index abcdef1..1234567 100644
52+
--- level2/file1.txt
53+
+++ level2/file1.txt
54+
@@ -1 +1 @@
55+
-old content
56+
+new content
57+
EOF
58+
59+
# Test 3: --git-prefixes=strip with -p0 and --strip=1
60+
# With strip: a/level1/level2/file1.txt -> strip a/ -> level1/level2/file1.txt -> -p0 -> level1/level2/file1.txt for matching
61+
# Then --strip=1 affects output
62+
${FILTERDIFF} --git-prefixes=strip -p0 --strip=1 -i "level1/level2/file1.txt" git-test.patch 2>errors3 >result3 || exit 1
63+
[ -s errors3 ] && exit 1
64+
65+
cat << EOF | cmp - result3 || exit 1
66+
diff --git level1/level2/file1.txt level1/level2/file1.txt
67+
index abcdef1..1234567 100644
68+
--- level1/level2/file1.txt
69+
+++ level1/level2/file1.txt
70+
@@ -1 +1 @@
71+
-old content
72+
+new content
73+
EOF
74+
75+
# Test 4: Verify exclusion works correctly with --git-prefixes=strip
76+
# Exclude "path/file2.c" after stripping a/ and applying -p1
77+
${FILTERDIFF} --git-prefixes=strip -p1 --strip=1 -x "path/file2.c" git-test.patch 2>errors4 >result4 || exit 1
78+
[ -s errors4 ] && exit 1
79+
80+
cat << EOF | cmp - result4 || exit 1
81+
diff --git level1/level2/file1.txt level1/level2/file1.txt
82+
index abcdef1..1234567 100644
83+
--- level1/level2/file1.txt
84+
+++ level1/level2/file1.txt
85+
@@ -1 +1 @@
86+
-old content
87+
+new content
88+
EOF
89+
90+
exit 0

0 commit comments

Comments
 (0)