]>
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 | ||
8145a8fd | 55 | test_expect_success 'template cannot set core.bare' ' |
0f7443bd EN |
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 && | |
8145a8fd | 63 | test_path_is_missing subdir/HEAD |
0f7443bd EN |
64 | ' |
65 | ||
ee9fb68c | 66 | test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' ' |
83525227 JS |
67 | : > a1 && |
68 | git add a1 && | |
69 | test_tick && | |
70 | git commit -m a1 && | |
ce5369e3 | 71 | mkdir .git/info && |
83525227 JS |
72 | umask 0277 && |
73 | git update-server-info && | |
19b28bf5 AL |
74 | actual="$(ls -l .git/info/refs)" && |
75 | case "$actual" in | |
76 | -r--r--r--*) | |
77 | : happy | |
78 | ;; | |
79 | *) | |
80 | echo Oops, .git/info/refs is not 0444 | |
81 | false | |
82 | ;; | |
83 | esac | |
83525227 JS |
84 | ' |
85 | ||
06cbe855 HO |
86 | for u in 0660:rw-rw---- \ |
87 | 0640:rw-r----- \ | |
88 | 0600:rw------- \ | |
89 | 0666:rw-rw-rw- \ | |
90 | 0664:rw-rw-r-- | |
91 | do | |
92 | x=$(expr "$u" : ".*:\([rw-]*\)") && | |
93 | y=$(echo "$x" | sed -e "s/w/-/g") && | |
94 | u=$(expr "$u" : "\([0-7]*\)") && | |
95 | git config core.sharedrepository "$u" && | |
96 | umask 0277 && | |
97 | ||
ee9fb68c | 98 | test_expect_success POSIXPERM "shared = $u ($y) ro" ' |
06cbe855 HO |
99 | |
100 | rm -f .git/info/refs && | |
101 | git update-server-info && | |
73de1c93 | 102 | actual="$(test_modebits .git/info/refs)" && |
8ddfce71 | 103 | test "x$actual" = "x-$y" |
95508a07 | 104 | |
06cbe855 HO |
105 | ' |
106 | ||
107 | umask 077 && | |
ee9fb68c | 108 | test_expect_success POSIXPERM "shared = $u ($x) rw" ' |
06cbe855 HO |
109 | |
110 | rm -f .git/info/refs && | |
111 | git update-server-info && | |
73de1c93 | 112 | actual="$(test_modebits .git/info/refs)" && |
8ddfce71 | 113 | test "x$actual" = "x-$x" |
06cbe855 HO |
114 | |
115 | ' | |
116 | ||
117 | done | |
118 | ||
d91175b2 JK |
119 | test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' ' |
120 | rm -f .git/info/refs && | |
121 | test_unconfig core.sharedrepository && | |
122 | umask 002 && | |
123 | git update-server-info && | |
124 | echo "-rw-rw-r--" >expect && | |
73de1c93 | 125 | test_modebits .git/info/refs >actual && |
d91175b2 JK |
126 | test_cmp expect actual |
127 | ' | |
128 | ||
7d5a1806 | 129 | test_expect_success POSIXPERM 'forced modes' ' |
5d64229e | 130 | test_when_finished "rm -rf new" && |
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 && | |
a0883a24 JX |
139 | git init --shared=0660 --template=../templates && |
140 | test_path_is_file .git/hooks/post-update && | |
5a688fe4 JH |
141 | >frotz && |
142 | git add frotz && | |
143 | git commit -a -m initial && | |
144 | git repack | |
145 | ) && | |
07868821 JS |
146 | # List repository files meant to be protected; note that |
147 | # COMMIT_EDITMSG does not matter---0mode is not about a | |
148 | # repository with a work tree. | |
149 | find new/.git -type f -name COMMIT_EDITMSG -prune -o -print | | |
5a688fe4 JH |
150 | xargs ls -ld >actual && |
151 | ||
152 | # Everything must be unaccessible to others | |
07868821 | 153 | test -z "$(sed -e "/^.......---/d" actual)" && |
5a688fe4 | 154 | |
1b89eaa4 JK |
155 | # All directories must have either 2770 or 770 |
156 | test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" && | |
5a688fe4 JH |
157 | |
158 | # post-update hook must be 0770 | |
159 | test -z "$(sed -n -e "/post-update/{ | |
160 | /^-rwxrwx---/d | |
161 | p | |
162 | }" actual)" && | |
163 | ||
07868821 | 164 | # All files inside objects must be accessible by us |
5a688fe4 JH |
165 | test -z "$(sed -n -e "/objects\//{ |
166 | /^d/d | |
07868821 JS |
167 | /^-r.-r.----/d |
168 | p | |
5a688fe4 JH |
169 | }" actual)" |
170 | ' | |
171 | ||
b9605bc4 | 172 | test_expect_success POSIXPERM 'remote init does not use config from cwd' ' |
5d64229e | 173 | test_when_finished "rm -rf child.git" && |
b9605bc4 JK |
174 | git config core.sharedrepository 0666 && |
175 | umask 0022 && | |
176 | git init --bare child.git && | |
177 | echo "-rw-r--r--" >expect && | |
73de1c93 | 178 | test_modebits child.git/config >actual && |
b9605bc4 JK |
179 | test_cmp expect actual |
180 | ' | |
181 | ||
4543926b JK |
182 | test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' ' |
183 | git config core.sharedrepository 0666 && | |
184 | umask 0022 && | |
185 | echo whatever >templates/foo && | |
186 | git init --template=templates && | |
187 | echo "-rw-rw-rw-" >expect && | |
73de1c93 | 188 | test_modebits .git/foo >actual && |
4543926b JK |
189 | test_cmp expect actual |
190 | ' | |
191 | ||
192 | test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' ' | |
5d64229e | 193 | test_when_finished "rm -rf child.git" && |
4543926b JK |
194 | umask 0022 && |
195 | git init --bare --shared=0666 child.git && | |
196 | test_path_is_missing child.git/foo && | |
e1df7fe4 | 197 | git init --bare --template=templates child.git && |
4543926b | 198 | echo "-rw-rw-rw-" >expect && |
73de1c93 | 199 | test_modebits child.git/foo >actual && |
4543926b JK |
200 | test_cmp expect actual |
201 | ' | |
202 | ||
203 | test_expect_success POSIXPERM 'template can set core.sharedrepository' ' | |
5d64229e | 204 | test_when_finished "rm -rf child.git" && |
4543926b JK |
205 | umask 0022 && |
206 | git config core.sharedrepository 0666 && | |
207 | cp .git/config templates/config && | |
e1df7fe4 | 208 | git init --bare --template=templates child.git && |
4543926b | 209 | echo "-rw-rw-rw-" >expect && |
73de1c93 | 210 | test_modebits child.git/HEAD >actual && |
4543926b JK |
211 | test_cmp expect actual |
212 | ' | |
213 | ||
83525227 | 214 | test_done |