3 # Copyright (c) 2007 Johannes Schindelin
6 test_description
='Test shared repository initialization'
10 # Remove a default ACL from the test dir if possible.
11 setfacl
-k .
2>/dev
/null
13 # User must have read permissions to the repo -> failure on --shared=0400
14 test_expect_success
'shared = 0400 (faulty permission u-w)' '
15 test_when_finished "rm -rf sub" &&
18 test_must_fail git init --shared=0400
24 test_expect_success POSIXPERM
"shared=1 does not clear bits preset by umask $u" '
28 git init --shared=1 &&
29 test 1 = "$(git config core.sharedrepository)"
31 actual=$(ls -l sub/.git/HEAD) &&
37 echo Oops, .git/HEAD is not 0664 but $actual
45 test_expect_success
'shared=all' '
48 git init --shared=all &&
49 test 2 = $(git config core.sharedrepository)
52 test_expect_success POSIXPERM
'update-server-info honors core.sharedRepository' '
58 git update-server-info &&
59 actual="$(ls -l .git/info/refs)" &&
65 echo Oops, .git/info/refs is not 0444
71 for u
in 0660:rw-rw---- \
77 x
=$
(expr "$u" : ".*:\([rw-]*\)") &&
78 y
=$
(echo "$x" |
sed -e "s/w/-/g") &&
79 u
=$
(expr "$u" : "\([0-7]*\)") &&
80 git config core.sharedrepository
"$u" &&
83 test_expect_success POSIXPERM
"shared = $u ($y) ro" '
85 rm -f .git/info/refs &&
86 git update-server-info &&
87 actual="$(test_modebits .git/info/refs)" &&
88 verbose test "x$actual" = "x-$y"
93 test_expect_success POSIXPERM
"shared = $u ($x) rw" '
95 rm -f .git/info/refs &&
96 git update-server-info &&
97 actual="$(test_modebits .git/info/refs)" &&
98 verbose test "x$actual" = "x-$x"
104 test_expect_success POSIXPERM
'info/refs respects umask in unshared repo' '
105 rm -f .git/info/refs &&
106 test_unconfig core.sharedrepository &&
108 git update-server-info &&
109 echo "-rw-rw-r--" >expect &&
110 test_modebits .git/info/refs >actual &&
111 test_cmp expect actual
114 test_expect_success POSIXPERM
'git reflog expire honors core.sharedRepository' '
116 git config core.sharedRepository group &&
117 git reflog expire --all &&
118 actual="$(ls -l .git/logs/refs/heads/master)" &&
124 echo Ooops, .git/logs/refs/heads/master is not 0662 [$actual]
130 test_expect_success POSIXPERM
'forced modes' '
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 &&
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 git config core.sharedrepository 0666 &&
174 git init --bare child.git &&
175 echo "-rw-r--r--" >expect &&
176 test_modebits child.git/config >actual &&
177 test_cmp expect actual
180 test_expect_success POSIXPERM
're-init respects core.sharedrepository (local)' '
181 git config core.sharedrepository 0666 &&
183 echo whatever >templates/foo &&
184 git init --template=templates &&
185 echo "-rw-rw-rw-" >expect &&
186 test_modebits .git/foo >actual &&
187 test_cmp expect actual
190 test_expect_success POSIXPERM
're-init respects core.sharedrepository (remote)' '
193 git init --bare --shared=0666 child.git &&
194 test_path_is_missing child.git/foo &&
195 git init --bare --template=../templates child.git &&
196 echo "-rw-rw-rw-" >expect &&
197 test_modebits child.git/foo >actual &&
198 test_cmp expect actual
201 test_expect_success POSIXPERM
'template can set core.sharedrepository' '
204 git config core.sharedrepository 0666 &&
205 cp .git/config templates/config &&
206 git init --bare --template=../templates child.git &&
207 echo "-rw-rw-rw-" >expect &&
208 test_modebits child.git/HEAD >actual &&
209 test_cmp expect actual