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
23 ls -l "$1" |
sed -e 's|^\(..........\).*|\1|'
28 test_expect_success POSIXPERM
"shared=1 does not clear bits preset by umask $u" '
32 git init --shared=1 &&
33 test 1 = "$(git config core.sharedrepository)"
35 actual=$(ls -l sub/.git/HEAD) &&
41 echo Oops, .git/HEAD is not 0664 but $actual
49 test_expect_success
'shared=all' '
52 git init --shared=all &&
53 test 2 = $(git config core.sharedrepository)
56 test_expect_success POSIXPERM
'update-server-info honors core.sharedRepository' '
62 git update-server-info &&
63 actual="$(ls -l .git/info/refs)" &&
69 echo Oops, .git/info/refs is not 0444
75 for u
in 0660:rw-rw---- \
81 x
=$
(expr "$u" : ".*:\([rw-]*\)") &&
82 y
=$
(echo "$x" |
sed -e "s/w/-/g") &&
83 u
=$
(expr "$u" : "\([0-7]*\)") &&
84 git config core.sharedrepository
"$u" &&
87 test_expect_success POSIXPERM
"shared = $u ($y) ro" '
89 rm -f .git/info/refs &&
90 git update-server-info &&
91 actual="$(modebits .git/info/refs)" &&
92 verbose test "x$actual" = "x-$y"
97 test_expect_success POSIXPERM
"shared = $u ($x) rw" '
99 rm -f .git/info/refs &&
100 git update-server-info &&
101 actual="$(modebits .git/info/refs)" &&
102 verbose test "x$actual" = "x-$x"
108 test_expect_success POSIXPERM
'info/refs respects umask in unshared repo' '
109 rm -f .git/info/refs &&
110 test_unconfig core.sharedrepository &&
112 git update-server-info &&
113 echo "-rw-rw-r--" >expect &&
114 modebits .git/info/refs >actual &&
115 test_cmp expect actual
118 test_expect_success POSIXPERM
'git reflog expire honors core.sharedRepository' '
120 git config core.sharedRepository group &&
121 git reflog expire --all &&
122 actual="$(ls -l .git/logs/refs/heads/master)" &&
128 echo Ooops, .git/logs/refs/heads/master is not 0662 [$actual]
134 test_expect_success POSIXPERM
'forced modes' '
135 mkdir -p templates/hooks &&
136 echo update-server-info >templates/hooks/post-update &&
137 chmod +x templates/hooks/post-update &&
138 echo : >random-file &&
143 git init --shared=0660 --template=../templates &&
146 git commit -a -m initial &&
149 # List repository files meant to be protected; note that
150 # COMMIT_EDITMSG does not matter---0mode is not about a
151 # repository with a work tree.
152 find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
153 xargs ls -ld >actual &&
155 # Everything must be unaccessible to others
156 test -z "$(sed -e "/^.......---/d" actual)" &&
158 # All directories must have either 2770 or 770
159 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
161 # post-update hook must be 0770
162 test -z "$(sed -n -e "/post-update/{
167 # All files inside objects must be accessible by us
168 test -z "$(sed -n -e "/objects\//{
175 test_expect_success POSIXPERM
'remote init does not use config from cwd' '
176 git config core.sharedrepository 0666 &&
178 git init --bare child.git &&
179 echo "-rw-r--r--" >expect &&
180 modebits child.git/config >actual &&
181 test_cmp expect actual
184 test_expect_success POSIXPERM
're-init respects core.sharedrepository (local)' '
185 git config core.sharedrepository 0666 &&
187 echo whatever >templates/foo &&
188 git init --template=templates &&
189 echo "-rw-rw-rw-" >expect &&
190 modebits .git/foo >actual &&
191 test_cmp expect actual
194 test_expect_success POSIXPERM
're-init respects core.sharedrepository (remote)' '
197 git init --bare --shared=0666 child.git &&
198 test_path_is_missing child.git/foo &&
199 git init --bare --template=../templates child.git &&
200 echo "-rw-rw-rw-" >expect &&
201 modebits child.git/foo >actual &&
202 test_cmp expect actual
205 test_expect_success POSIXPERM
'template can set core.sharedrepository' '
208 git config core.sharedrepository 0666 &&
209 cp .git/config templates/config &&
210 git init --bare --template=../templates child.git &&
211 echo "-rw-rw-rw-" >expect &&
212 modebits child.git/HEAD >actual &&
213 test_cmp expect actual