interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4128-apply-root.sh

163 lines · 3884 bytes Raw Blame History
1#!/bin/sh
2
3test_description='apply same filename'
4
5. ./test-lib.sh
6
7test_expect_success 'setup' '
8
9 mkdir -p some/sub/dir &&
10 echo Hello > some/sub/dir/file &&
11 git add some/sub/dir/file &&
12 git commit -m initial &&
13 git tag initial
14
15'
16
17cat > patch << EOF
18diff a/bla/blub/dir/file b/bla/blub/dir/file
19--- a/bla/blub/dir/file
20+++ b/bla/blub/dir/file
21@@ -1,1 +1,1 @@
22-Hello
23+Bello
24EOF
25
26test_expect_success 'apply --directory -p (1)' '
27 git apply --directory=some/sub -p3 --index patch &&
28 echo Bello >expect &&
29 git show :some/sub/dir/file >actual &&
30 test_cmp expect actual &&
31 test_cmp expect some/sub/dir/file
32
33'
34
35test_expect_success 'apply --directory -p (2) ' '
36
37 git reset --hard initial &&
38 git apply --directory=some/sub/ -p3 --index patch &&
39 echo Bello >expect &&
40 git show :some/sub/dir/file >actual &&
41 test_cmp expect actual &&
42 test_cmp expect some/sub/dir/file
43
44'
45
46test_expect_success 'apply --directory (./ prefix)' '
47 git reset --hard initial &&
48 git apply --directory=./some/sub -p3 --index patch &&
49 echo Bello >expect &&
50 git show :some/sub/dir/file >actual &&
51 test_cmp expect actual &&
52 test_cmp expect some/sub/dir/file
53'
54
55test_expect_success 'apply --directory (double slash)' '
56 git reset --hard initial &&
57 git apply --directory=some//sub -p3 --index patch &&
58 echo Bello >expect &&
59 git show :some/sub/dir/file >actual &&
60 test_cmp expect actual &&
61 test_cmp expect some/sub/dir/file
62'
63
64test_expect_success 'apply --directory (./ in the middle)' '
65 git reset --hard initial &&
66 git apply --directory=some/./sub -p3 --index patch &&
67 echo Bello >expect &&
68 git show :some/sub/dir/file >actual &&
69 test_cmp expect actual &&
70 test_cmp expect some/sub/dir/file
71'
72
73test_expect_success 'apply --directory (../ in the middle)' '
74 git reset --hard initial &&
75 git apply --directory=some/../some/sub -p3 --index patch &&
76 echo Bello >expect &&
77 git show :some/sub/dir/file >actual &&
78 test_cmp expect actual &&
79 test_cmp expect some/sub/dir/file
80'
81
82test_expect_success 'apply --directory rejects leading ../' '
83 test_must_fail git apply --directory=../foo -p3 patch 2>err &&
84 test_grep "unable to normalize directory" err
85'
86
87cat > patch << EOF
88diff --git a/newfile b/newfile
89new file mode 100644
90index 0000000..d95f3ad
91--- /dev/null
92+++ b/newfile
93@@ -0,0 +1 @@
94+content
95EOF
96
97test_expect_success 'apply --directory (new file)' '
98 git reset --hard initial &&
99 git apply --directory=some/sub/dir/ --index patch &&
100 echo content >expect &&
101 git show :some/sub/dir/newfile >actual &&
102 test_cmp expect actual &&
103 test_cmp expect some/sub/dir/newfile
104'
105
106cat > patch << EOF
107diff --git a/c/newfile2 b/c/newfile2
108new file mode 100644
109index 0000000..d95f3ad
110--- /dev/null
111+++ b/c/newfile2
112@@ -0,0 +1 @@
113+content
114EOF
115
116test_expect_success 'apply --directory -p (new file)' '
117 git reset --hard initial &&
118 git apply -p2 --directory=some/sub/dir/ --index patch &&
119 echo content >expect &&
120 git show :some/sub/dir/newfile2 >actual &&
121 test_cmp expect actual &&
122 test_cmp expect some/sub/dir/newfile2
123'
124
125cat > patch << EOF
126diff --git a/delfile b/delfile
127deleted file mode 100644
128index d95f3ad..0000000
129--- a/delfile
130+++ /dev/null
131@@ -1 +0,0 @@
132-content
133EOF
134
135test_expect_success 'apply --directory (delete file)' '
136 git reset --hard initial &&
137 echo content >some/sub/dir/delfile &&
138 git add some/sub/dir/delfile &&
139 git apply --directory=some/sub/dir/ --index patch &&
140 git ls-files >out &&
141 test_grep ! delfile out
142'
143
144cat > patch << 'EOF'
145diff --git "a/qu\157tefile" "b/qu\157tefile"
146new file mode 100644
147index 0000000..d95f3ad
148--- /dev/null
149+++ "b/qu\157tefile"
150@@ -0,0 +1 @@
151+content
152EOF
153
154test_expect_success 'apply --directory (quoted filename)' '
155 git reset --hard initial &&
156 git apply --directory=some/sub/dir/ --index patch &&
157 echo content >expect &&
158 git show :some/sub/dir/quotefile >actual &&
159 test_cmp expect actual &&
160 test_cmp expect some/sub/dir/quotefile
161'
162
163test_done