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_success
'template cannot 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_is_missing subdir/HEAD
66 test_expect_success POSIXPERM
'update-server-info honors core.sharedRepository' '
73 git update-server-info &&
74 actual="$(ls -l .git/info/refs)" &&
80 echo Oops, .git/info/refs is not 0444
86 for u
in 0660:rw-rw---- \
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" &&
98 test_expect_success POSIXPERM
"shared = $u ($y) ro" '
100 rm -f .git/info/refs &&
101 git update-server-info &&
102 actual="$(test_modebits .git/info/refs)" &&
103 test "x$actual" = "x-$y"
108 test_expect_success POSIXPERM
"shared = $u ($x) rw" '
110 rm -f .git/info/refs &&
111 git update-server-info &&
112 actual="$(test_modebits .git/info/refs)" &&
113 test "x$actual" = "x-$x"
119 test_expect_success POSIXPERM
'info/refs respects umask in unshared repo' '
120 rm -f .git/info/refs &&
121 test_unconfig core.sharedrepository &&
123 git update-server-info &&
124 echo "-rw-rw-r--" >expect &&
125 test_modebits .git/info/refs >actual &&
126 test_cmp expect actual
129 test_expect_success POSIXPERM
'forced modes' '
130 test_when_finished "rm -rf new" &&
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 &&
139 git init --shared=0660 --template=../templates &&
140 test_path_is_file .git/hooks/post-update &&
143 git commit -a -m initial &&
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 |
150 xargs ls -ld >actual &&
152 # Everything must be unaccessible to others
153 test -z "$(sed -e "/^.......---/d" actual)" &&
155 # All directories must have either 2770 or 770
156 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
158 # post-update hook must be 0770
159 test -z "$(sed -n -e "/post-update/{
164 # All files inside objects must be accessible by us
165 test -z "$(sed -n -e "/objects\//{
172 test_expect_success POSIXPERM
'remote init does not use config from cwd' '
173 test_when_finished "rm -rf child.git" &&
174 git config core.sharedrepository 0666 &&
176 git init --bare child.git &&
177 echo "-rw-r--r--" >expect &&
178 test_modebits child.git/config >actual &&
179 test_cmp expect actual
182 test_expect_success POSIXPERM
're-init respects core.sharedrepository (local)' '
183 git config core.sharedrepository 0666 &&
185 echo whatever >templates/foo &&
186 git init --template=templates &&
187 echo "-rw-rw-rw-" >expect &&
188 test_modebits .git/foo >actual &&
189 test_cmp expect actual
192 test_expect_success POSIXPERM
're-init respects core.sharedrepository (remote)' '
193 test_when_finished "rm -rf child.git" &&
195 git init --bare --shared=0666 child.git &&
196 test_path_is_missing child.git/foo &&
197 git init --bare --template=templates child.git &&
198 echo "-rw-rw-rw-" >expect &&
199 test_modebits child.git/foo >actual &&
200 test_cmp expect actual
203 test_expect_success POSIXPERM
'template can set core.sharedrepository' '
204 test_when_finished "rm -rf child.git" &&
206 git config core.sharedrepository 0666 &&
207 cp .git/config templates/config &&
208 git init --bare --template=templates child.git &&
209 echo "-rw-rw-rw-" >expect &&
210 test_modebits child.git/HEAD >actual &&
211 test_cmp expect actual