]>
Commit | Line | Data |
---|---|---|
83525227 JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Johannes Schindelin | |
4 | # | |
5 | ||
6 | test_description='Test shared repository initialization' | |
7 | ||
06d53148 | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
10 | ||
83525227 JS |
11 | . ./test-lib.sh |
12 | ||
8ed0a740 MM |
13 | # Remove a default ACL from the test dir if possible. |
14 | setfacl -k . 2>/dev/null | |
15 | ||
06cbe855 HO |
16 | # User must have read permissions to the repo -> failure on --shared=0400 |
17 | test_expect_success 'shared = 0400 (faulty permission u-w)' ' | |
95508a07 | 18 | test_when_finished "rm -rf sub" && |
06cbe855 | 19 | mkdir sub && ( |
95508a07 JK |
20 | cd sub && |
21 | test_must_fail git init --shared=0400 | |
06cbe855 | 22 | ) |
06cbe855 HO |
23 | ' |
24 | ||
8c6202d8 PB |
25 | for u in 002 022 |
26 | do | |
ee9fb68c | 27 | test_expect_success POSIXPERM "shared=1 does not clear bits preset by umask $u" ' |
8c6202d8 PB |
28 | mkdir sub && ( |
29 | cd sub && | |
30 | umask $u && | |
31 | git init --shared=1 && | |
32 | test 1 = "$(git config core.sharedrepository)" | |
33 | ) && | |
95508a07 | 34 | actual=$(ls -l sub/.git/HEAD) && |
8c6202d8 PB |
35 | case "$actual" in |
36 | -rw-rw-r--*) | |
37 | : happy | |
38 | ;; | |
39 | *) | |
40 | echo Oops, .git/HEAD is not 0664 but $actual | |
41 | false | |
42 | ;; | |
43 | esac | |
44 | ' | |
45 | rm -rf sub | |
46 | done | |
47 | ||
83525227 JS |
48 | test_expect_success 'shared=all' ' |
49 | mkdir sub && | |
50 | cd sub && | |
51 | git init --shared=all && | |
52 | test 2 = $(git config core.sharedrepository) | |
53 | ' | |
54 | ||
ee9fb68c | 55 | test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' ' |
83525227 JS |
56 | : > a1 && |
57 | git add a1 && | |
58 | test_tick && | |
59 | git commit -m a1 && | |
60 | umask 0277 && | |
61 | git update-server-info && | |
19b28bf5 AL |
62 | actual="$(ls -l .git/info/refs)" && |
63 | case "$actual" in | |
64 | -r--r--r--*) | |
65 | : happy | |
66 | ;; | |
67 | *) | |
68 | echo Oops, .git/info/refs is not 0444 | |
69 | false | |
70 | ;; | |
71 | esac | |
83525227 JS |
72 | ' |
73 | ||
06cbe855 HO |
74 | for u in 0660:rw-rw---- \ |
75 | 0640:rw-r----- \ | |
76 | 0600:rw------- \ | |
77 | 0666:rw-rw-rw- \ | |
78 | 0664:rw-rw-r-- | |
79 | do | |
80 | x=$(expr "$u" : ".*:\([rw-]*\)") && | |
81 | y=$(echo "$x" | sed -e "s/w/-/g") && | |
82 | u=$(expr "$u" : "\([0-7]*\)") && | |
83 | git config core.sharedrepository "$u" && | |
84 | umask 0277 && | |
85 | ||
ee9fb68c | 86 | test_expect_success POSIXPERM "shared = $u ($y) ro" ' |
06cbe855 HO |
87 | |
88 | rm -f .git/info/refs && | |
89 | git update-server-info && | |
73de1c93 | 90 | actual="$(test_modebits .git/info/refs)" && |
95508a07 JK |
91 | verbose test "x$actual" = "x-$y" |
92 | ||
06cbe855 HO |
93 | ' |
94 | ||
95 | umask 077 && | |
ee9fb68c | 96 | test_expect_success POSIXPERM "shared = $u ($x) rw" ' |
06cbe855 HO |
97 | |
98 | rm -f .git/info/refs && | |
99 | git update-server-info && | |
73de1c93 | 100 | actual="$(test_modebits .git/info/refs)" && |
95508a07 | 101 | verbose test "x$actual" = "x-$x" |
06cbe855 HO |
102 | |
103 | ' | |
104 | ||
105 | done | |
106 | ||
d91175b2 JK |
107 | test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' ' |
108 | rm -f .git/info/refs && | |
109 | test_unconfig core.sharedrepository && | |
110 | umask 002 && | |
111 | git update-server-info && | |
112 | echo "-rw-rw-r--" >expect && | |
73de1c93 | 113 | test_modebits .git/info/refs >actual && |
d91175b2 JK |
114 | test_cmp expect actual |
115 | ' | |
116 | ||
ee9fb68c | 117 | test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' ' |
d05c77cc | 118 | umask 077 && |
336d09da PH |
119 | git config core.sharedRepository group && |
120 | git reflog expire --all && | |
06d53148 | 121 | actual="$(ls -l .git/logs/refs/heads/main)" && |
336d09da PH |
122 | case "$actual" in |
123 | -rw-rw-*) | |
124 | : happy | |
125 | ;; | |
126 | *) | |
06d53148 | 127 | echo Ooops, .git/logs/refs/heads/main is not 0662 [$actual] |
336d09da PH |
128 | false |
129 | ;; | |
130 | esac | |
131 | ' | |
132 | ||
7d5a1806 | 133 | test_expect_success POSIXPERM 'forced modes' ' |
5a688fe4 JH |
134 | mkdir -p templates/hooks && |
135 | echo update-server-info >templates/hooks/post-update && | |
136 | chmod +x templates/hooks/post-update && | |
137 | echo : >random-file && | |
138 | mkdir new && | |
139 | ( | |
140 | cd new && | |
141 | umask 002 && | |
e1df7fe4 | 142 | git init --shared=0660 --template=templates && |
5a688fe4 JH |
143 | >frotz && |
144 | git add frotz && | |
145 | git commit -a -m initial && | |
146 | git repack | |
147 | ) && | |
07868821 JS |
148 | # List repository files meant to be protected; note that |
149 | # COMMIT_EDITMSG does not matter---0mode is not about a | |
150 | # repository with a work tree. | |
151 | find new/.git -type f -name COMMIT_EDITMSG -prune -o -print | | |
5a688fe4 JH |
152 | xargs ls -ld >actual && |
153 | ||
154 | # Everything must be unaccessible to others | |
07868821 | 155 | test -z "$(sed -e "/^.......---/d" actual)" && |
5a688fe4 | 156 | |
1b89eaa4 JK |
157 | # All directories must have either 2770 or 770 |
158 | test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" && | |
5a688fe4 JH |
159 | |
160 | # post-update hook must be 0770 | |
161 | test -z "$(sed -n -e "/post-update/{ | |
162 | /^-rwxrwx---/d | |
163 | p | |
164 | }" actual)" && | |
165 | ||
07868821 | 166 | # All files inside objects must be accessible by us |
5a688fe4 JH |
167 | test -z "$(sed -n -e "/objects\//{ |
168 | /^d/d | |
07868821 JS |
169 | /^-r.-r.----/d |
170 | p | |
5a688fe4 JH |
171 | }" actual)" |
172 | ' | |
173 | ||
b9605bc4 JK |
174 | test_expect_success POSIXPERM 'remote init does not use config from cwd' ' |
175 | git config core.sharedrepository 0666 && | |
176 | umask 0022 && | |
177 | git init --bare child.git && | |
178 | echo "-rw-r--r--" >expect && | |
73de1c93 | 179 | test_modebits child.git/config >actual && |
b9605bc4 JK |
180 | test_cmp expect actual |
181 | ' | |
182 | ||
4543926b JK |
183 | test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' ' |
184 | git config core.sharedrepository 0666 && | |
185 | umask 0022 && | |
186 | echo whatever >templates/foo && | |
187 | git init --template=templates && | |
188 | echo "-rw-rw-rw-" >expect && | |
73de1c93 | 189 | test_modebits .git/foo >actual && |
4543926b JK |
190 | test_cmp expect actual |
191 | ' | |
192 | ||
193 | test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' ' | |
194 | rm -rf child.git && | |
195 | umask 0022 && | |
196 | git init --bare --shared=0666 child.git && | |
197 | test_path_is_missing child.git/foo && | |
e1df7fe4 | 198 | git init --bare --template=templates child.git && |
4543926b | 199 | echo "-rw-rw-rw-" >expect && |
73de1c93 | 200 | test_modebits child.git/foo >actual && |
4543926b JK |
201 | test_cmp expect actual |
202 | ' | |
203 | ||
204 | test_expect_success POSIXPERM 'template can set core.sharedrepository' ' | |
205 | rm -rf child.git && | |
206 | umask 0022 && | |
207 | git config core.sharedrepository 0666 && | |
208 | cp .git/config templates/config && | |
e1df7fe4 | 209 | git init --bare --template=templates child.git && |
4543926b | 210 | echo "-rw-rw-rw-" >expect && |
73de1c93 | 211 | test_modebits child.git/HEAD >actual && |
4543926b JK |
212 | test_cmp expect actual |
213 | ' | |
214 | ||
83525227 | 215 | test_done |