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
13 # Remove a default ACL from the test dir if possible.
14 setfacl
-k .
2>/dev
/null
16 # User must have read permissions to the repo -> failure on --shared=0400
17 test_expect_success
'shared = 0400 (faulty permission u-w)' '
18 test_when_finished "rm -rf sub" &&
21 test_must_fail git init --shared=0400
27 test_expect_success POSIXPERM
"shared=1 does not clear bits preset by umask $u" '
31 git init --shared=1 &&
32 test 1 = "$(git config core.sharedrepository)"
34 actual=$(ls -l sub/.git/HEAD) &&
40 echo Oops, .git/HEAD is not 0664 but $actual
48 test_expect_success
'shared=all' '
51 git init --shared=all &&
52 test 2 = $(git config core.sharedrepository)
55 test_expect_success POSIXPERM
'update-server-info honors core.sharedRepository' '
61 git update-server-info &&
62 actual="$(ls -l .git/info/refs)" &&
68 echo Oops, .git/info/refs is not 0444
74 for u
in 0660:rw-rw---- \
80 x
=$
(expr "$u" : ".*:\([rw-]*\)") &&
81 y
=$
(echo "$x" |
sed -e "s/w/-/g") &&
82 u
=$
(expr "$u" : "\([0-7]*\)") &&
83 git config core.sharedrepository
"$u" &&
86 test_expect_success POSIXPERM
"shared = $u ($y) ro" '
88 rm -f .git/info/refs &&
89 git update-server-info &&
90 actual="$(test_modebits .git/info/refs)" &&
91 verbose test "x$actual" = "x-$y"
96 test_expect_success POSIXPERM
"shared = $u ($x) rw" '
98 rm -f .git/info/refs &&
99 git update-server-info &&
100 actual="$(test_modebits .git/info/refs)" &&
101 verbose test "x$actual" = "x-$x"
107 test_expect_success POSIXPERM
'info/refs respects umask in unshared repo' '
108 rm -f .git/info/refs &&
109 test_unconfig core.sharedrepository &&
111 git update-server-info &&
112 echo "-rw-rw-r--" >expect &&
113 test_modebits .git/info/refs >actual &&
114 test_cmp expect actual
117 test_expect_success POSIXPERM
'git reflog expire honors core.sharedRepository' '
119 git config core.sharedRepository group &&
120 git reflog expire --all &&
121 actual="$(ls -l .git/logs/refs/heads/main)" &&
127 echo Ooops, .git/logs/refs/heads/main is not 066x [$actual]
133 test_expect_success POSIXPERM
'forced modes' '
134 mkdir -p templates/hooks &&
135 echo update-server-info >templates/hooks/post-update &&
136 chmod +x templates/hooks/post-update &&
137 echo : >random-file &&
142 git init --shared=0660 --template=templates &&
145 git commit -a -m initial &&
148 # List repository files meant to be protected; note that
149 # COMMIT_EDITMSG does not matter---0mode is not about a
150 # repository with a work tree.
151 find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
152 xargs ls -ld >actual &&
154 # Everything must be unaccessible to others
155 test -z "$(sed -e "/^.......---/d" actual)" &&
157 # All directories must have either 2770 or 770
158 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
160 # post-update hook must be 0770
161 test -z "$(sed -n -e "/post-update/{
166 # All files inside objects must be accessible by us
167 test -z "$(sed -n -e "/objects\//{
174 test_expect_success POSIXPERM
'remote init does not use config from cwd' '
175 git config core.sharedrepository 0666 &&
177 git init --bare child.git &&
178 echo "-rw-r--r--" >expect &&
179 test_modebits child.git/config >actual &&
180 test_cmp expect actual
183 test_expect_success POSIXPERM
're-init respects core.sharedrepository (local)' '
184 git config core.sharedrepository 0666 &&
186 echo whatever >templates/foo &&
187 git init --template=templates &&
188 echo "-rw-rw-rw-" >expect &&
189 test_modebits .git/foo >actual &&
190 test_cmp expect actual
193 test_expect_success POSIXPERM
're-init respects core.sharedrepository (remote)' '
196 git init --bare --shared=0666 child.git &&
197 test_path_is_missing child.git/foo &&
198 git init --bare --template=templates child.git &&
199 echo "-rw-rw-rw-" >expect &&
200 test_modebits child.git/foo >actual &&
201 test_cmp expect actual
204 test_expect_success POSIXPERM
'template can set core.sharedrepository' '
207 git config core.sharedrepository 0666 &&
208 cp .git/config templates/config &&
209 git init --bare --template=templates child.git &&
210 echo "-rw-rw-rw-" >expect &&
211 test_modebits child.git/HEAD >actual &&
212 test_cmp expect actual