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