]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4129-apply-samemode.sh
Merge branch 'es/maintenance-of-bare-repositories'
[thirdparty/git.git] / t / t4129-apply-samemode.sh
CommitLineData
1f7903a3
JH
1#!/bin/sh
2
3test_description='applying patch with mode bits'
4
5. ./test-lib.sh
872f349e 6
1f7903a3
JH
7test_expect_success setup '
8 echo original >file &&
9 git add file &&
10 test_tick &&
11 git commit -m initial &&
12 git tag initial &&
13 echo modified >file &&
14 git diff --stat -p >patch-0.txt &&
15 chmod +x file &&
44e5471a
RS
16 git diff --stat -p >patch-1.txt &&
17 sed "s/^\(new mode \).*/\1/" <patch-1.txt >patch-empty-mode.txt &&
18 sed "s/^\(new mode \).*/\1garbage/" <patch-1.txt >patch-bogus-mode.txt
1f7903a3
JH
19'
20
872f349e 21test_expect_success FILEMODE 'same mode (no index)' '
1f7903a3
JH
22 git reset --hard &&
23 chmod +x file &&
24 git apply patch-0.txt &&
25 test -x file
26'
27
872f349e 28test_expect_success FILEMODE 'same mode (with index)' '
1f7903a3
JH
29 git reset --hard &&
30 chmod +x file &&
31 git add file &&
32 git apply --index patch-0.txt &&
33 test -x file &&
34 git diff --exit-code
35'
36
872f349e 37test_expect_success FILEMODE 'same mode (index only)' '
1f7903a3
JH
38 git reset --hard &&
39 chmod +x file &&
40 git add file &&
41 git apply --cached patch-0.txt &&
42 git ls-files -s file | grep "^100755"
43'
44
872f349e 45test_expect_success FILEMODE 'mode update (no index)' '
1f7903a3
JH
46 git reset --hard &&
47 git apply patch-1.txt &&
48 test -x file
49'
50
872f349e 51test_expect_success FILEMODE 'mode update (with index)' '
1f7903a3
JH
52 git reset --hard &&
53 git apply --index patch-1.txt &&
54 test -x file &&
55 git diff --exit-code
56'
57
872f349e 58test_expect_success FILEMODE 'mode update (index only)' '
1f7903a3
JH
59 git reset --hard &&
60 git apply --cached patch-1.txt &&
61 git ls-files -s file | grep "^100755"
62'
63
44e5471a
RS
64test_expect_success FILEMODE 'empty mode is rejected' '
65 git reset --hard &&
66 test_must_fail git apply patch-empty-mode.txt 2>err &&
67 test_i18ngrep "invalid mode" err
68'
69
70test_expect_success FILEMODE 'bogus mode is rejected' '
71 git reset --hard &&
72 test_must_fail git apply patch-bogus-mode.txt 2>err &&
73 test_i18ngrep "invalid mode" err
74'
75
eb3c027e
MT
76test_expect_success POSIXPERM 'do not use core.sharedRepository for working tree files' '
77 git reset --hard &&
78 test_config core.sharedRepository 0666 &&
79 (
80 # Remove a default ACL if possible.
a1e03535 81 (setfacl -k . 2>/dev/null || true) &&
eb3c027e
MT
82 umask 0077 &&
83
84 # Test both files (f1) and leading dirs (d)
85 mkdir d &&
86 touch f1 d/f2 &&
87 git add f1 d/f2 &&
88 git diff --staged >patch-f1-and-f2.txt &&
89
90 rm -rf d f1 &&
91 git apply patch-f1-and-f2.txt &&
92
93 echo "-rw-------" >f1_mode.expected &&
94 echo "drwx------" >d_mode.expected &&
95 test_modebits f1 >f1_mode.actual &&
96 test_modebits d >d_mode.actual &&
97 test_cmp f1_mode.expected f1_mode.actual &&
98 test_cmp d_mode.expected d_mode.actual
99 )
100'
101
1f7903a3 102test_done