Debian Codegraph @

tests/git-prefixes-with-strip/run-test

raw
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-extended-diffs=include --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-extended-diffs=include --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-extended-diffs=include --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-extended-diffs=include --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