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
14 # Remove a default ACL from the test dir if possible.
15 setfacl
-k .
2>/dev
/null
17 # User must have read permissions to the repo -> failure on --shared=0400
18 test_expect_success
'shared = 0400 (faulty permission u-w)' '
19 test_when_finished "rm -rf sub" &&
22 test_must_fail git init --shared=0400
28 test_expect_success POSIXPERM
"shared=1 does not clear bits preset by umask $u" '
29 test_when_finished "rm -rf sub" &&
33 git init --shared=1 &&
34 test 1 = "$(git config core.sharedrepository)"
36 actual=$(ls -l sub/.git/HEAD) &&
42 echo Oops, .git/HEAD is not 0664 but $actual
49 test_expect_success
'shared=all' '
50 git init --template= --shared=all &&
51 test 2 = $(git config core.sharedrepository)
54 test_expect_success
'template cannot set core.bare' '
55 test_when_finished "rm -rf subdir" &&
56 test_when_finished "rm -rf templates" &&
57 test_config core.bare true &&
59 mkdir -p templates/ &&
60 cp .git/config templates/config &&
61 git init --template=templates subdir &&
62 test_path_is_missing subdir/HEAD
65 test_expect_success POSIXPERM
'update-server-info honors core.sharedRepository' '
72 git update-server-info &&
73 actual="$(ls -l .git/info/refs)" &&
79 echo Oops, .git/info/refs is not 0444
85 for u
in 0660:rw-rw---- \
91 x
=$
(expr "$u" : ".*:\([rw-]*\)") &&
92 y
=$
(echo "$x" |
sed -e "s/w/-/g") &&
93 u
=$
(expr "$u" : "\([0-7]*\)") &&
94 git config core.sharedrepository
"$u" &&
97 test_expect_success POSIXPERM
"shared = $u ($y) ro" '
99 rm -f .git/info/refs &&
100 git update-server-info &&
101 actual="$(test_modebits .git/info/refs)" &&
102 test "x$actual" = "x-$y"
107 test_expect_success POSIXPERM
"shared = $u ($x) rw" '
109 rm -f .git/info/refs &&
110 git update-server-info &&
111 actual="$(test_modebits .git/info/refs)" &&
112 test "x$actual" = "x-$x"
118 test_expect_success POSIXPERM
'info/refs respects umask in unshared repo' '
119 rm -f .git/info/refs &&
120 test_unconfig core.sharedrepository &&
122 git update-server-info &&
123 echo "-rw-rw-r--" >expect &&
124 test_modebits .git/info/refs >actual &&
125 test_cmp expect actual
128 test_expect_success POSIXPERM
'forced modes' '
129 test_when_finished "rm -rf new" &&
130 mkdir -p templates/hooks &&
131 echo update-server-info >templates/hooks/post-update &&
132 chmod +x templates/hooks/post-update &&
133 echo : >random-file &&
138 git init --shared=0660 --template=../templates &&
139 test_path_is_file .git/hooks/post-update &&
142 git commit -a -m initial &&
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 |
149 xargs ls -ld >actual &&
151 # Everything must be unaccessible to others
152 test -z "$(sed -e "/^.......---/d" actual)" &&
154 # All directories must have either 2770 or 770
155 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
157 # post-update hook must be 0770
158 test -z "$(sed -n -e "/post-update/{
163 # All files inside objects must be accessible by us
164 test -z "$(sed -n -e "/objects\//{
171 test_expect_success POSIXPERM
'remote init does not use config from cwd' '
172 test_when_finished "rm -rf child.git" &&
173 git config core.sharedrepository 0666 &&
175 git init --bare child.git &&
176 echo "-rw-r--r--" >expect &&
177 test_modebits child.git/config >actual &&
178 test_cmp expect actual
181 test_expect_success POSIXPERM
're-init respects core.sharedrepository (local)' '
182 git config core.sharedrepository 0666 &&
184 echo whatever >templates/foo &&
185 git init --template=templates &&
186 echo "-rw-rw-rw-" >expect &&
187 test_modebits .git/foo >actual &&
188 test_cmp expect actual
191 test_expect_success POSIXPERM
're-init respects core.sharedrepository (remote)' '
192 test_when_finished "rm -rf child.git" &&
194 git init --bare --shared=0666 child.git &&
195 test_path_is_missing child.git/foo &&
196 git init --bare --template=templates child.git &&
197 echo "-rw-rw-rw-" >expect &&
198 test_modebits child.git/foo >actual &&
199 test_cmp expect actual
202 test_expect_success POSIXPERM
'template can set core.sharedrepository' '
203 test_when_finished "rm -rf child.git" &&
205 git config core.sharedrepository 0666 &&
206 cp .git/config templates/config &&
207 git init --bare --template=templates child.git &&
208 echo "-rw-rw-rw-" >expect &&
209 test_modebits child.git/HEAD >actual &&
210 test_cmp expect actual