summaryrefslogtreecommitdiff
path: root/tests/create-delete
blob: 7eed11f4003564c1b1ef3c9461e9c3206b7f5a08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Copyright (C) 2009, 2011-2012 Free Software Foundation, Inc.
#
# Copying and distribution of this file, with or without modification,
# in any medium, are permitted without royalty provided the copyright
# notice and this notice are preserved.

. $srcdir/test-lib.sh

require_cat
require_sed
use_local_patch
use_tmpdir

# ==============================================================

# Bug #25970: intuit_diff_type: Assertion `i0 != NONE' failed.

cat > f.diff <<EOF
--- f
+++ f
@@ -1 +0,0 @@
-one
EOF
echo one > f

check 'patch -f -p1 < f.diff || echo "Status: $?"' <<EOF
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- f
|+++ f
--------------------------
No file to patch.  Skipping patch.
1 out of 1 hunk ignored
Status: 1
EOF

# ==============================================================

cat > f.diff <<EOF
--- /dev/null
+++ f
@@ -0,0 +1 @@
+one
EOF
echo one > f

check 'patch -f < f.diff || echo "Status: $?"' <<EOF
The next patch would create the file f,
which already exists!  Applying it anyway.
patching file f
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file f.rej
Status: 1
EOF

# ==============================================================

cat > f.diff <<EOF
--- f
+++ /dev/null
@@ -1 +0,0 @@
-one
EOF
rm -f f

preserve_trailing_blank=

check 'patch -p0 < f.diff || echo "Status: $?"' <<EOF
The next patch would delete the file f,
which does not exist!  Assume -R? [n] $preserve_trailing_blank
Apply anyway? [n] $preserve_trailing_blank
Skipping patch.
1 out of 1 hunk ignored
Status: 1
EOF

# --------------------------------------------------------------

rm -f f

check 'patch -p0 -f < f.diff || echo "Status: $?"' <<EOF
The next patch would delete the file f,
which does not exist!  Applying it anyway.
patching file f
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file f.rej
Status: 1
EOF

# --------------------------------------------------------------
# Check the file mode of backups of new files

umask 022
rm -f f.orig f

check 'patch -f f < f.diff || echo "Status: $?"' <<EOF
The next patch would delete the file f,
which does not exist!  Applying it anyway.
patching file f
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file f.rej
Status: 1
EOF

ncheck '! test -s f.orig'

# ==============================================================

cat > f.diff <<EOF
--- f.orig
+++ f
@@ -1 +0,0 @@
-f
EOF
echo f > f.orig
: > f

check 'patch -f < f.diff || echo "Status: $?"' <<EOF
The next patch would empty out the file f,
which is already empty!  Applying it anyway.
patching file f
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file f.rej
Status: 1
EOF

# ==============================================================

cat > f.diff <<EOF
--- f
+++ f.orig
@@ -1 +0,0 @@
-f
EOF
rm -f f.orig
: > f

check 'patch -p0 -t < f.diff || echo "Status: $?"' <<EOF
The next patch would empty out the file f,
which is already empty!  Assuming -R.
patching file f
EOF

check 'cat f' <<EOF
f
EOF

# --------------------------------------------------------------

cat > f.diff <<EOF
--- f
+++ /dev/null
@@ -1 +0,0 @@
-f
EOF
rm -f f.orig
: > f

# FIXME: "The next patch would delete the file f" would be better here
check 'patch -p0 -t < f.diff || echo "Status: $?"' <<EOF
The next patch would empty out the file f,
which is already empty!  Assuming -R.
patching file f
EOF

check 'cat f' <<EOF
f
EOF
#
# ----------------------------------------------------------------

# This test deletes the target file.

echo data > target
cat > p.diff <<EOF
diff --git a/target b/target
deleted file mode 100644
index 1269488..0000000
EOF

check 'patch -p1 -b < p.diff || echo status: $?' <<EOF
patching file target
File target is not empty after patch, as expected
status: 1
EOF

check 'cat target' <<EOF
data
EOF

# Patch creates a backup file even when the original file remains unchanged:
check 'cat target.orig' <<EOF
data
EOF

cat > p.diff <<EOF
diff --git a/target b/target
deleted file mode 100644
index 1269488..0000000
--- a/target
+++ /dev/null
@@ -1 +0,0 @@
-data
EOF

check 'patch -p1 -b -f < p.diff || echo status: $?' <<EOF
patching file target
EOF

ncheck 'test ! -e target'

check 'cat target.orig' <<EOF
data
EOF