]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4129-apply-samemode.sh
The third batch
[thirdparty/git.git] / t / t4129-apply-samemode.sh
CommitLineData
1f7903a3
JH
1#!/bin/sh
2
3test_description='applying patch with mode bits'
4
f54f48fc
ÆAB
5
6TEST_PASSES_SANITIZE_LEAK=true
1f7903a3 7. ./test-lib.sh
872f349e 8
1f7903a3
JH
9test_expect_success setup '
10 echo original >file &&
11 git add file &&
12 test_tick &&
13 git commit -m initial &&
14 git tag initial &&
15 echo modified >file &&
16 git diff --stat -p >patch-0.txt &&
17 chmod +x file &&
44e5471a
RS
18 git diff --stat -p >patch-1.txt &&
19 sed "s/^\(new mode \).*/\1/" <patch-1.txt >patch-empty-mode.txt &&
20 sed "s/^\(new mode \).*/\1garbage/" <patch-1.txt >patch-bogus-mode.txt
1f7903a3
JH
21'
22
872f349e 23test_expect_success FILEMODE 'same mode (no index)' '
1f7903a3
JH
24 git reset --hard &&
25 chmod +x file &&
26 git apply patch-0.txt &&
27 test -x file
28'
29
872f349e 30test_expect_success FILEMODE 'same mode (with index)' '
1f7903a3
JH
31 git reset --hard &&
32 chmod +x file &&
33 git add file &&
34 git apply --index patch-0.txt &&
35 test -x file &&
36 git diff --exit-code
37'
38
872f349e 39test_expect_success FILEMODE 'same mode (index only)' '
1f7903a3
JH
40 git reset --hard &&
41 chmod +x file &&
42 git add file &&
43 git apply --cached patch-0.txt &&
12609141
CP
44 git ls-files -s file >ls-files-output &&
45 test_grep "^100755" ls-files-output
1f7903a3
JH
46'
47
872f349e 48test_expect_success FILEMODE 'mode update (no index)' '
1f7903a3
JH
49 git reset --hard &&
50 git apply patch-1.txt &&
51 test -x file
52'
53
872f349e 54test_expect_success FILEMODE 'mode update (with index)' '
1f7903a3
JH
55 git reset --hard &&
56 git apply --index patch-1.txt &&
57 test -x file &&
58 git diff --exit-code
59'
60
872f349e 61test_expect_success FILEMODE 'mode update (index only)' '
1f7903a3
JH
62 git reset --hard &&
63 git apply --cached patch-1.txt &&
12609141
CP
64 git ls-files -s file >ls-files-output &&
65 test_grep "^100755" ls-files-output
1f7903a3
JH
66'
67
44e5471a
RS
68test_expect_success FILEMODE 'empty mode is rejected' '
69 git reset --hard &&
70 test_must_fail git apply patch-empty-mode.txt 2>err &&
6789275d 71 test_grep "invalid mode" err
44e5471a
RS
72'
73
74test_expect_success FILEMODE 'bogus mode is rejected' '
75 git reset --hard &&
76 test_must_fail git apply patch-bogus-mode.txt 2>err &&
6789275d 77 test_grep "invalid mode" err
44e5471a
RS
78'
79
eb3c027e
MT
80test_expect_success POSIXPERM 'do not use core.sharedRepository for working tree files' '
81 git reset --hard &&
82 test_config core.sharedRepository 0666 &&
83 (
84 # Remove a default ACL if possible.
a1e03535 85 (setfacl -k . 2>/dev/null || true) &&
eb3c027e
MT
86 umask 0077 &&
87
88 # Test both files (f1) and leading dirs (d)
89 mkdir d &&
90 touch f1 d/f2 &&
91 git add f1 d/f2 &&
92 git diff --staged >patch-f1-and-f2.txt &&
93
94 rm -rf d f1 &&
95 git apply patch-f1-and-f2.txt &&
96
97 echo "-rw-------" >f1_mode.expected &&
98 echo "drwx------" >d_mode.expected &&
99 test_modebits f1 >f1_mode.actual &&
100 test_modebits d >d_mode.actual &&
101 test_cmp f1_mode.expected f1_mode.actual &&
102 test_cmp d_mode.expected d_mode.actual
103 )
104'
105
0482c32c
CP
106test_expect_success 'git apply respects core.fileMode' '
107 test_config core.fileMode false &&
108 echo true >script.sh &&
109 git add --chmod=+x script.sh &&
110 git ls-files -s script.sh >ls-files-output &&
111 test_grep "^100755" ls-files-output &&
112 test_tick && git commit -m "Add script" &&
113 git ls-tree -r HEAD script.sh >ls-tree-output &&
114 test_grep "^100755" ls-tree-output &&
115
116 echo true >>script.sh &&
117 test_tick && git commit -m "Modify script" script.sh &&
118 git format-patch -1 --stdout >patch &&
119 test_grep "^index.*100755$" patch &&
120
121 git switch -c branch HEAD^ &&
122 git apply --index patch 2>err &&
123 test_grep ! "has type 100644, expected 100755" err &&
124 git reset --hard &&
125
126 git apply patch 2>err &&
127 test_grep ! "has type 100644, expected 100755" err &&
128
129 git apply --cached patch 2>err &&
130 test_grep ! "has type 100644, expected 100755" err
131'
132
1f7903a3 133test_done