3 # Copyright (c) 2007 Johannes Schindelin
6 test_description
='Test shared repository initialization'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_CREATE_REPO_NO_TEMPLATE
=1
12 TEST_PASSES_SANITIZE_LEAK
=true
15 # Remove a default ACL from the test dir if possible.
16 setfacl
-k .
2>/dev
/null
18 # User must have read permissions to the repo -> failure on --shared=0400
19 test_expect_success
'shared = 0400 (faulty permission u-w)' '
20 test_when_finished "rm -rf sub" &&
23 test_must_fail git init --shared=0400
29 test_expect_success POSIXPERM
"shared=1 does not clear bits preset by umask $u" '
30 test_when_finished "rm -rf sub" &&
34 git init --shared=1 &&
35 test 1 = "$(git config core.sharedrepository)"
37 actual=$(ls -l sub/.git/HEAD) &&
43 echo Oops, .git/HEAD is not 0664 but $actual
50 test_expect_success
'shared=all' '
51 git init --template= --shared=all &&
52 test 2 = $(git config core.sharedrepository)
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 &&
60 mkdir -p templates/ &&
61 cp .git/config templates/config &&
62 git init --template=templates subdir &&
63 test_path_exists subdir/HEAD
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 &&
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
77 test_expect_success POSIXPERM
'update-server-info honors core.sharedRepository' '
84 git update-server-info &&
85 actual="$(ls -l .git/info/refs)" &&
91 echo Oops, .git/info/refs is not 0444
97 for u
in 0660:rw-rw---- \
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" &&
109 test_expect_success POSIXPERM
"shared = $u ($y) ro" '
111 rm -f .git/info/refs &&
112 git update-server-info &&
113 actual="$(test_modebits .git/info/refs)" &&
114 test "x$actual" = "x-$y"
119 test_expect_success POSIXPERM
"shared = $u ($x) rw" '
121 rm -f .git/info/refs &&
122 git update-server-info &&
123 actual="$(test_modebits .git/info/refs)" &&
124 test "x$actual" = "x-$x"
130 test_expect_success POSIXPERM
'info/refs respects umask in unshared repo' '
131 rm -f .git/info/refs &&
132 test_unconfig core.sharedrepository &&
134 git update-server-info &&
135 echo "-rw-rw-r--" >expect &&
136 test_modebits .git/info/refs >actual &&
137 test_cmp expect actual
140 test_expect_success POSIXPERM
'git reflog expire honors core.sharedRepository' '
142 git config core.sharedRepository group &&
143 git reflog expire --all &&
144 actual="$(ls -l .git/logs/refs/heads/main)" &&
150 echo Ooops, .git/logs/refs/heads/main is not 066x [$actual]
156 test_expect_success POSIXPERM
'forced modes' '
157 test_when_finished "rm -rf new" &&
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 &&
166 git init --shared=0660 --template=../templates &&
167 test_path_is_file .git/hooks/post-update &&
170 git commit -a -m initial &&
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 |
177 xargs ls -ld >actual &&
179 # Everything must be unaccessible to others
180 test -z "$(sed -e "/^.......---/d" actual)" &&
182 # All directories must have either 2770 or 770
183 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
185 # post-update hook must be 0770
186 test -z "$(sed -n -e "/post-update/{
191 # All files inside objects must be accessible by us
192 test -z "$(sed -n -e "/objects\//{
199 test_expect_success POSIXPERM
'remote init does not use config from cwd' '
200 test_when_finished "rm -rf child.git" &&
201 git config core.sharedrepository 0666 &&
203 git init --bare child.git &&
204 echo "-rw-r--r--" >expect &&
205 test_modebits child.git/config >actual &&
206 test_cmp expect actual
209 test_expect_success POSIXPERM
're-init respects core.sharedrepository (local)' '
210 git config core.sharedrepository 0666 &&
212 echo whatever >templates/foo &&
213 git init --template=templates &&
214 echo "-rw-rw-rw-" >expect &&
215 test_modebits .git/foo >actual &&
216 test_cmp expect actual
219 test_expect_success POSIXPERM
're-init respects core.sharedrepository (remote)' '
220 test_when_finished "rm -rf child.git" &&
222 git init --bare --shared=0666 child.git &&
223 test_path_is_missing child.git/foo &&
224 git init --bare --template=templates child.git &&
225 echo "-rw-rw-rw-" >expect &&
226 test_modebits child.git/foo >actual &&
227 test_cmp expect actual
230 test_expect_success POSIXPERM
'template can set core.sharedrepository' '
231 test_when_finished "rm -rf child.git" &&
233 git config core.sharedrepository 0666 &&
234 cp .git/config templates/config &&
235 git init --bare --template=templates child.git &&
236 echo "-rw-rw-rw-" >expect &&
237 test_modebits child.git/HEAD >actual &&
238 test_cmp expect actual