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