3 test_description
='applying patch with mode bits'
6 TEST_PASSES_SANITIZE_LEAK
=true
9 test_expect_success setup
'
10 echo original >file &&
13 git commit -m initial &&
15 echo modified >file &&
16 git diff --stat -p >patch-0.txt &&
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
23 test_expect_success FILEMODE
'same mode (no index)' '
26 git apply patch-0.txt &&
30 test_expect_success FILEMODE
'same mode (with index)' '
34 git apply --index patch-0.txt &&
39 test_expect_success FILEMODE
'same mode (index only)' '
43 git apply --cached patch-0.txt &&
44 git ls-files -s file >ls-files-output &&
45 test_grep "^100755" ls-files-output
48 test_expect_success FILEMODE
'mode update (no index)' '
50 git apply patch-1.txt &&
54 test_expect_success FILEMODE
'mode update (with index)' '
56 git apply --index patch-1.txt &&
61 test_expect_success FILEMODE
'mode update (index only)' '
63 git apply --cached patch-1.txt &&
64 git ls-files -s file >ls-files-output &&
65 test_grep "^100755" ls-files-output
68 test_expect_success FILEMODE
'empty mode is rejected' '
70 test_must_fail git apply patch-empty-mode.txt 2>err &&
71 test_grep "invalid mode" err
74 test_expect_success FILEMODE
'bogus mode is rejected' '
76 test_must_fail git apply patch-bogus-mode.txt 2>err &&
77 test_grep "invalid mode" err
80 test_expect_success POSIXPERM
'do not use core.sharedRepository for working tree files' '
82 test_config core.sharedRepository 0666 &&
84 # Remove a default ACL if possible.
85 (setfacl -k . 2>/dev/null || true) &&
88 # Test both files (f1) and leading dirs (d)
92 git diff --staged >patch-f1-and-f2.txt &&
95 git apply patch-f1-and-f2.txt &&
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
106 test_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 &&
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 &&
121 git switch -c branch HEAD^ &&
122 git apply --index patch 2>err &&
123 test_grep ! "has type 100644, expected 100755" err &&
126 git apply patch 2>err &&
127 test_grep ! "has type 100644, expected 100755" err &&
129 git apply --cached patch 2>err &&
130 test_grep ! "has type 100644, expected 100755" err
133 test_expect_success POSIXPERM
'patch mode for new file is canonicalized' '
134 cat >patch <<-\EOF &&
135 diff --git a/non-canon b/non-canon
141 test_when_finished "git reset --hard" &&
144 git apply --index patch 2>err
146 test_must_be_empty err &&
147 git ls-files -s -- non-canon >staged &&
148 test_grep "^100644" staged &&
149 ls -l non-canon >worktree &&
150 test_grep "^-rw-rw-rw" worktree
153 test_expect_success POSIXPERM
'patch mode for deleted file is canonicalized' '
154 test_when_finished "git reset --hard" &&
155 echo content >non-canon &&
156 chmod 666 non-canon &&
159 cat >patch <<-\EOF &&
160 diff --git a/non-canon b/non-canon
161 deleted file mode 100660
167 git apply --index patch 2>err &&
168 test_must_be_empty err &&
169 git ls-files -- non-canon >staged &&
170 test_must_be_empty staged &&
171 test_path_is_missing non-canon
174 test_expect_success POSIXPERM
'patch mode for mode change is canonicalized' '
175 test_when_finished "git reset --hard" &&
176 echo content >non-canon &&
179 cat >patch <<-\EOF &&
180 diff --git a/non-canon b/non-canon
186 git apply --index patch 2>err
188 test_must_be_empty err &&
189 git ls-files -s -- non-canon >staged &&
190 test_grep "^100755" staged &&
191 ls -l non-canon >worktree &&
192 test_grep "^-rwxrwxrwx" worktree