summaryrefslogtreecommitdiff
path: root/tests/copy-rename
blob: 20836666076fca2ff7d5ce92538e57b1021d32d4 (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
# Copyright (C) 2010-2011 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
--- 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
--- 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

# --------------------------------------------------------------
# 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'