summaryrefslogtreecommitdiff
path: root/tests/file-modes
blob: b7c23600d8e5ca373fc2eb9d2fed8fa73e5da175 (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
# 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.

# Test if git diffs can change file modes

. $srcdir/test-lib.sh

require_cat
require_sed
use_local_patch
use_tmpdir

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

cat > f.diff <<EOF
diff --git a/f b/f
old mode 100644
new mode 100600
--- a/f
+++ a/f
@@ -1 +1 @@
-old
+new

diff --git a/g b/g
old mode 100644
new mode 100600
--- a/g
+++ a/g
@@ -1 +1 @@
-old
+new

EOF

echo old > f
echo old > g
chmod 644 f g

check 'patch -p1 < f.diff' <<EOF
patching file f
patching file g
EOF

check 'ls -l f g | sed "s,\(..........\).*,\1,"' <<EOF
-rw-------
-rw-------
EOF

check 'patch -p1 -R < f.diff' <<EOF
patching file f
patching file g
EOF

check 'ls -l f g | sed "s,\(..........\).*,\1,"' <<EOF
-rw-r--r--
-rw-r--r--
EOF

cat > g.diff <<EOF
diff --git a/f b/f
old mode 100644
new mode 100600

diff --git a/g b/g
old mode 100644
new mode 100600

EOF

chmod 600 f
chmod 644 g
check 'patch -p1 < g.diff || echo "Status: $?"' <<EOF
patching file f
patching file g
EOF

check 'ls -l f g | sed "s,\(..........\).*,\1,"' <<EOF
-rw-------
-rw-------
EOF