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
|
# 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.
# LF vs. CRLF line endings
. $srcdir/test-lib.sh
require gnu_diff
require sed
use_local_patch
use_tmpdir
lf2crlf() {
while read l; do echo -e "$l\r"; done
}
echo 1 > a
echo 1b > b
diff a b | lf2crlf > ab.diff
echo 1 > c
check 'patch c < ab.diff' <<EOF
(Stripping trailing CRs from patch; use --binary to disable.)
patching file c
EOF
diff -c a b | lf2crlf > ab.diff
echo 1 > c
check 'patch c < ab.diff' <<EOF
(Stripping trailing CRs from patch; use --binary to disable.)
patching file c
EOF
diff -u a b | lf2crlf > ab.diff
echo 1 > c
check 'patch c < ab.diff' <<EOF
(Stripping trailing CRs from patch; use --binary to disable.)
patching file c
EOF
if ! have_ed ; then
echo "The ed utility is not available; skipping ed related tests"
else
diff -e a b > ab.ed | lf2crlf > ab.ed
echo 1 > c
ncheck 'patch c < ab.ed'
fi
# ==============================================================
echo 1 | lf2crlf > a
echo 1b | lf2crlf > b
diff a b > ab.diff
cp a c
check 'patch c < ab.diff' <<EOF
patching file c
EOF
check 'cat -ve c' <<EOF
1b^M$
EOF
# --------------------------------------------------------------
diff -u a b > ab.diff
cp a c
check 'patch c < ab.diff' <<EOF
patching file c
EOF
check 'cat -ve c' <<EOF
1b^M$
EOF
# --------------------------------------------------------------
diff -c a b > ab.diff
cp a c
check 'patch c < ab.diff' <<EOF
patching file c
EOF
check 'cat -ve c' <<EOF
1b^M$
EOF
# --------------------------------------------------------------
if ! have_ed ; then
echo "The ed utility is not available; skipping ed related tests"
else
diff -e a b > ab.diff
cp a c
ncheck 'patch c < ab.diff'
fi
check 'cat -ve c' <<EOF
1b^M$
EOF
# ==============================================================
echo 1 > a
echo 1b > b
diff a b | lf2crlf > ab.diff
cp a c
check 'patch --binary c < ab.diff || echo status: $?' <<EOF
patching file c
Hunk #1 FAILED at 1 (different line endings).
1 out of 1 hunk FAILED -- saving rejects to file c.rej
status: 1
EOF
check 'patch c < ab.diff' <<EOF
(Stripping trailing CRs from patch; use --binary to disable.)
patching file c
EOF
check 'cat -ve c' <<EOF
1b$
EOF
lf2crlf < a > c
check 'patch --binary c < ab.diff' <<EOF
patching file c
EOF
check 'cat -ve c' <<EOF
1b^M$
EOF
# --------------------------------------------------------------
diff -u a b | lf2crlf > ab.diff
cp a c
check 'patch c < ab.diff' <<EOF
(Stripping trailing CRs from patch; use --binary to disable.)
patching file c
EOF
check 'cat -ve c' <<EOF
1b$
EOF
lf2crlf < a > c
check 'patch --binary c < ab.diff' <<EOF
patching file c
EOF
check 'cat -ve c' <<EOF
1b^M$
EOF
# --------------------------------------------------------------
diff -c a b | lf2crlf > ab.diff
cp a c
check 'patch c < ab.diff' <<EOF
(Stripping trailing CRs from patch; use --binary to disable.)
patching file c
EOF
check 'cat -ve c' <<EOF
1b$
EOF
lf2crlf < a > c
check 'patch --binary c < ab.diff' <<EOF
patching file c
EOF
check 'cat -ve c' <<EOF
1b^M$
EOF
# --------------------------------------------------------------
# NOTE: ed does not fix up CRLF mangled input, so mangled ed-style
# patches will break. (We could fix up things in patch and pipe
# the result to ed, but this is not what we do so far.)
# ==============================================================
# Line endings of @@ lines are not used for guessing if a patch needs CR
# stripping: if the -p / --show-c-function option of GNU diff is used, these
# lines can have different line endings than the rest of the patch.
echo 1 > a
echo 2 > b
diff -u a b | sed -e 's,@@$,@@ context\r,' > ab.diff
echo 1 > c
check 'patch c < ab.diff' <<EOF
patching file c
EOF
check 'cat -ve c' <<EOF
2$
EOF
|