File: copy-rename

package info (click to toggle)
patch 2.7.6-3%2Bdeb10u1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 6,988 kB
  • sloc: ansic: 40,033; sh: 6,547; yacc: 1,842; makefile: 140; sed: 54
file content (154 lines) | stat: -rw-r--r-- 2,366 bytes parent folder | download | duplicates (5)
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
# Copyright (C) 2010-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.

# git diffs: copy and rename tests

. $srcdir/test-lib.sh

require cat
use_local_patch
use_tmpdir

# ==============================================================
# Normal copy and rename patches

echo old > f

cat > copy.diff <<EOF
diff --git a/f b/g
copy from f
copy to g
index 3367afd..3e75765 100644
--- a/f
+++ b/g
@@ -1 +1 @@
-old
+new
EOF

check 'patch -p1 < copy.diff || echo "Status: $?"' <<EOF
patching file g (copied from f)
EOF

check 'cat f' <<EOF
old
EOF

check 'cat g' <<EOF
new
EOF

cat > rename.diff <<EOF
diff --git a/f b/h
rename from f
rename to h
index 3367afd..3e75765 100644
--- a/f
+++ b/h
@@ -1 +1 @@
-old
+new
EOF

check 'patch -p1 < rename.diff || echo "Status: $?"' <<EOF
patching file h (renamed from f)
EOF

ncheck 'test ! -e f'

check 'cat h' <<EOF
new
EOF

echo old > h

check 'patch -p1 < rename.diff || echo "Status: $?"' <<EOF
patching file h (already renamed from f)
EOF

ncheck 'test ! -e f'

check 'cat h' <<EOF
new
EOF

mv h f

check 'patch -p1 -R < rename.diff || echo "Status: $?"' <<EOF
patching file f (already renamed from h)
EOF

ncheck 'test ! -e h'

check 'cat f' <<EOF
old
EOF

# --------------------------------------------------------------
# Patches with no hunks

echo old > f
rm -f g h

cat > copy.diff <<EOF
diff --git a/f a/g
copy from f
copy to g
EOF

check 'patch -p1 < copy.diff || echo "Status: $?"' <<EOF
patching file g (copied from f)
EOF

check 'cat f' <<EOF
old
EOF

check 'cat g' <<EOF
old
EOF

cat > rename.diff <<EOF
diff --git a/f a/h
rename from f
rename to h
EOF

check 'patch -p1 < rename.diff || echo "Status: $?"' <<EOF
patching file h (renamed from f)
EOF

ncheck 'test ! -e f'

check 'cat h' <<EOF
old
EOF

# --------------------------------------------------------------
# Backup file tests

echo old > f
rm -f g h

check 'patch -p1 --backup < copy.diff || echo "Status: $?"' <<EOF
patching file g (copied from f)
EOF

ncheck 'test ! -e f.orig'

ncheck 'cat g.orig'

rm -f f.orig g.orig

check 'patch -p1 --backup < rename.diff || echo "Status: $?"' <<EOF
patching file h (renamed from f)
EOF

check 'cat f.orig' <<EOF
old
EOF

ncheck 'cat h.orig'