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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
# 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
# ================================================================
# File expected to become empty doesn't become empty
seq 2 > target
cat > p.diff <<EOF
--- target
+++ /dev/null
@@ -1 +0,0 @@
-1
EOF
check 'patch -p0 < p.diff || echo status: $?' <<EOF
patching file target
Not deleting file target as content differs from patch
status: 1
EOF
check 'cat target' <<EOF
2
EOF
# --------------------------------------------------------------
seq 2 > target
cat > p.diff <<EOF
--- target 2012-09-25 03:09:15
+++ target 1970-01-01 00:00:00
@@ -1 +0,0 @@
-1
EOF
check 'patch -p0 < p.diff || echo status: $?' <<EOF
patching file target
Not deleting file target as content differs from patch
status: 1
EOF
check 'cat target' <<EOF
2
EOF
# --------------------------------------------------------------
printf '\0' > target
if ! test -s target; then
echo "Failed to printf a null character; skipping this test"
else
cat > p.diff <<EOF
diff --git a/target b/target
deleted file mode 100644
index f76dd23..0000000
Binary files a/target and /dev/null differ
EOF
check 'patch -p1 -b < p.diff || echo status: $?' <<EOF
patching file target
Not deleting file target as content differs from patch
status: 1
EOF
ncheck 'test -e target'
# Patch creates a backup file even when the original file remains unchanged:
ncheck 'test -e target.orig'
fi
# ================================================================
# File not expected to become empty does become empty
echo 1 > target
cat > p.diff <<EOF
--- target
+++ target
@@ -1 +0,0 @@
-1
EOF
check 'patch -p0 < p.diff || echo status: $?' <<EOF
patching file target
EOF
check 'cat target' <<EOF
EOF
echo 1 > target
check 'patch -p0 -E < p.diff || echo status: $?' <<EOF
patching file target
EOF
ncheck 'test ! -e target'
# ================================================================
# File expected to become empty does become empty
echo data > target
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
echo data > target
check 'patch -p1 -b --posix -f < p.diff || echo status: $?' <<EOF
patching file target
EOF
check 'cat target' <<EOF
EOF
check 'cat target.orig' <<EOF
data
EOF
|