]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1301-shared-repo.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t1301-shared-repo.sh
CommitLineData
83525227
JS
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes Schindelin
4#
5
6test_description='Test shared repository initialization'
7
06d53148 8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
83525227
JS
11. ./test-lib.sh
12
8ed0a740
MM
13# Remove a default ACL from the test dir if possible.
14setfacl -k . 2>/dev/null
15
06cbe855
HO
16# User must have read permissions to the repo -> failure on --shared=0400
17test_expect_success 'shared = 0400 (faulty permission u-w)' '
95508a07 18 test_when_finished "rm -rf sub" &&
06cbe855 19 mkdir sub && (
95508a07
JK
20 cd sub &&
21 test_must_fail git init --shared=0400
06cbe855 22 )
06cbe855
HO
23'
24
8c6202d8
PB
25for u in 002 022
26do
ee9fb68c 27 test_expect_success POSIXPERM "shared=1 does not clear bits preset by umask $u" '
8c6202d8
PB
28 mkdir sub && (
29 cd sub &&
30 umask $u &&
31 git init --shared=1 &&
32 test 1 = "$(git config core.sharedrepository)"
33 ) &&
95508a07 34 actual=$(ls -l sub/.git/HEAD) &&
8c6202d8
PB
35 case "$actual" in
36 -rw-rw-r--*)
37 : happy
38 ;;
39 *)
40 echo Oops, .git/HEAD is not 0664 but $actual
41 false
42 ;;
43 esac
44 '
45 rm -rf sub
46done
47
83525227
JS
48test_expect_success 'shared=all' '
49 mkdir sub &&
50 cd sub &&
ce5369e3 51 git init --template= --shared=all &&
83525227
JS
52 test 2 = $(git config core.sharedrepository)
53'
54
ee9fb68c 55test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
83525227
JS
56 : > a1 &&
57 git add a1 &&
58 test_tick &&
59 git commit -m a1 &&
ce5369e3 60 mkdir .git/info &&
83525227
JS
61 umask 0277 &&
62 git update-server-info &&
19b28bf5
AL
63 actual="$(ls -l .git/info/refs)" &&
64 case "$actual" in
65 -r--r--r--*)
66 : happy
67 ;;
68 *)
69 echo Oops, .git/info/refs is not 0444
70 false
71 ;;
72 esac
83525227
JS
73'
74
06cbe855
HO
75for u in 0660:rw-rw---- \
76 0640:rw-r----- \
77 0600:rw------- \
78 0666:rw-rw-rw- \
79 0664:rw-rw-r--
80do
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" &&
85 umask 0277 &&
86
ee9fb68c 87 test_expect_success POSIXPERM "shared = $u ($y) ro" '
06cbe855
HO
88
89 rm -f .git/info/refs &&
90 git update-server-info &&
73de1c93 91 actual="$(test_modebits .git/info/refs)" &&
95508a07
JK
92 verbose test "x$actual" = "x-$y"
93
06cbe855
HO
94 '
95
96 umask 077 &&
ee9fb68c 97 test_expect_success POSIXPERM "shared = $u ($x) rw" '
06cbe855
HO
98
99 rm -f .git/info/refs &&
100 git update-server-info &&
73de1c93 101 actual="$(test_modebits .git/info/refs)" &&
95508a07 102 verbose test "x$actual" = "x-$x"
06cbe855
HO
103
104 '
105
106done
107
d91175b2
JK
108test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' '
109 rm -f .git/info/refs &&
110 test_unconfig core.sharedrepository &&
111 umask 002 &&
112 git update-server-info &&
113 echo "-rw-rw-r--" >expect &&
73de1c93 114 test_modebits .git/info/refs >actual &&
d91175b2
JK
115 test_cmp expect actual
116'
117
ee9fb68c 118test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' '
d05c77cc 119 umask 077 &&
336d09da
PH
120 git config core.sharedRepository group &&
121 git reflog expire --all &&
06d53148 122 actual="$(ls -l .git/logs/refs/heads/main)" &&
336d09da
PH
123 case "$actual" in
124 -rw-rw-*)
125 : happy
126 ;;
127 *)
0218ad5d 128 echo Ooops, .git/logs/refs/heads/main is not 066x [$actual]
336d09da
PH
129 false
130 ;;
131 esac
132'
133
7d5a1806 134test_expect_success POSIXPERM 'forced modes' '
5a688fe4
JH
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 &&
139 mkdir new &&
140 (
141 cd new &&
142 umask 002 &&
e1df7fe4 143 git init --shared=0660 --template=templates &&
5a688fe4
JH
144 >frotz &&
145 git add frotz &&
146 git commit -a -m initial &&
147 git repack
148 ) &&
07868821
JS
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 |
5a688fe4
JH
153 xargs ls -ld >actual &&
154
155 # Everything must be unaccessible to others
07868821 156 test -z "$(sed -e "/^.......---/d" actual)" &&
5a688fe4 157
1b89eaa4
JK
158 # All directories must have either 2770 or 770
159 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
5a688fe4
JH
160
161 # post-update hook must be 0770
162 test -z "$(sed -n -e "/post-update/{
163 /^-rwxrwx---/d
164 p
165 }" actual)" &&
166
07868821 167 # All files inside objects must be accessible by us
5a688fe4
JH
168 test -z "$(sed -n -e "/objects\//{
169 /^d/d
07868821
JS
170 /^-r.-r.----/d
171 p
5a688fe4
JH
172 }" actual)"
173'
174
b9605bc4
JK
175test_expect_success POSIXPERM 'remote init does not use config from cwd' '
176 git config core.sharedrepository 0666 &&
177 umask 0022 &&
178 git init --bare child.git &&
179 echo "-rw-r--r--" >expect &&
73de1c93 180 test_modebits child.git/config >actual &&
b9605bc4
JK
181 test_cmp expect actual
182'
183
4543926b
JK
184test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' '
185 git config core.sharedrepository 0666 &&
186 umask 0022 &&
187 echo whatever >templates/foo &&
188 git init --template=templates &&
189 echo "-rw-rw-rw-" >expect &&
73de1c93 190 test_modebits .git/foo >actual &&
4543926b
JK
191 test_cmp expect actual
192'
193
194test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' '
195 rm -rf child.git &&
196 umask 0022 &&
197 git init --bare --shared=0666 child.git &&
198 test_path_is_missing child.git/foo &&
e1df7fe4 199 git init --bare --template=templates child.git &&
4543926b 200 echo "-rw-rw-rw-" >expect &&
73de1c93 201 test_modebits child.git/foo >actual &&
4543926b
JK
202 test_cmp expect actual
203'
204
205test_expect_success POSIXPERM 'template can set core.sharedrepository' '
206 rm -rf child.git &&
207 umask 0022 &&
208 git config core.sharedrepository 0666 &&
209 cp .git/config templates/config &&
e1df7fe4 210 git init --bare --template=templates child.git &&
4543926b 211 echo "-rw-rw-rw-" >expect &&
73de1c93 212 test_modebits child.git/HEAD >actual &&
4543926b
JK
213 test_cmp expect actual
214'
215
83525227 216test_done