@@ -130,4 +130,66 @@ test_expect_success 'git apply respects core.fileMode' '
130130 test_grep ! "has type 100644, expected 100755" err
131131'
132132
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
136+ new file mode 100660
137+ --- /dev/null
138+ +++ b/non-canon
139+ +content
140+ EOF
141+ test_when_finished "git reset --hard" &&
142+ (
143+ umask 0 &&
144+ git apply --index patch 2>err
145+ ) &&
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
151+ '
152+
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 &&
157+ git add non-canon &&
158+
159+ cat >patch <<-\EOF &&
160+ diff --git a/non-canon b/non-canon
161+ deleted file mode 100660
162+ --- a/non-canon
163+ +++ /dev/null
164+ @@ -1 +0,0 @@
165+ -content
166+ EOF
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
172+ '
173+
174+ test_expect_success POSIXPERM ' patch mode for mode change is canonicalized' '
175+ test_when_finished "git reset --hard" &&
176+ echo content >non-canon &&
177+ git add non-canon &&
178+
179+ cat >patch <<-\EOF &&
180+ diff --git a/non-canon b/non-canon
181+ old mode 100660
182+ new mode 100770
183+ EOF
184+ (
185+ umask 0 &&
186+ git apply --index patch 2>err
187+ ) &&
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
193+ '
194+
133195test_done
0 commit comments