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
'forced modes' '
141 test_when_finished "rm -rf new" &&
142 mkdir -p templates/hooks &&
143 echo update-server-info >templates/hooks/post-update &&
144 chmod +x templates/hooks/post-update &&
145 echo : >random-file &&
150 git init --shared=0660 --template=../templates &&
151 test_path_is_file .git/hooks/post-update &&
154 git commit -a -m initial &&
157 # List repository files meant to be protected; note that
158 # COMMIT_EDITMSG does not matter---0mode is not about a
159 # repository with a work tree.
160 find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
161 xargs ls -ld >actual &&
163 # Everything must be unaccessible to others
164 test -z "$(sed -e "/^.......---/d" actual)" &&
166 # All directories must have either 2770 or 770
167 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
169 # post-update hook must be 0770
170 test -z "$(sed -n -e "/post-update/{
175 # All files inside objects must be accessible by us
176 test -z "$(sed -n -e "/objects\//{
183 test_expect_success POSIXPERM
'remote init does not use config from cwd' '
184 test_when_finished "rm -rf child.git" &&
185 git config core.sharedrepository 0666 &&
187 git init --bare child.git &&
188 echo "-rw-r--r--" >expect &&
189 test_modebits child.git/config >actual &&
190 test_cmp expect actual
193 test_expect_success POSIXPERM
're-init respects core.sharedrepository (local)' '
194 git config core.sharedrepository 0666 &&
196 echo whatever >templates/foo &&
197 git init --template=templates &&
198 echo "-rw-rw-rw-" >expect &&
199 test_modebits .git/foo >actual &&
200 test_cmp expect actual
203 test_expect_success POSIXPERM
're-init respects core.sharedrepository (remote)' '
204 test_when_finished "rm -rf child.git" &&
206 git init --bare --shared=0666 child.git &&
207 test_path_is_missing child.git/foo &&
208 git init --bare --template=templates child.git &&
209 echo "-rw-rw-rw-" >expect &&
210 test_modebits child.git/foo >actual &&
211 test_cmp expect actual
214 test_expect_success POSIXPERM
'template can set core.sharedrepository' '
215 test_when_finished "rm -rf child.git" &&
217 git config core.sharedrepository 0666 &&
218 cp .git/config templates/config &&
219 git init --bare --template=templates child.git &&
220 echo "-rw-rw-rw-" >expect &&
221 test_modebits child.git/HEAD >actual &&
222 test_cmp expect actual