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