]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1301-shared-repo.sh
test_i18ngrep: hard deprecate and forbid its use
[thirdparty/git.git] / t / t1301-shared-repo.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes Schindelin
4 #
5
6 test_description='Test shared repository initialization'
7
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 TEST_CREATE_REPO_NO_TEMPLATE=1
12 TEST_PASSES_SANITIZE_LEAK=true
13 . ./test-lib.sh
14
15 # Remove a default ACL from the test dir if possible.
16 setfacl -k . 2>/dev/null
17
18 # User must have read permissions to the repo -> failure on --shared=0400
19 test_expect_success 'shared = 0400 (faulty permission u-w)' '
20 test_when_finished "rm -rf sub" &&
21 mkdir sub && (
22 cd sub &&
23 test_must_fail git init --shared=0400
24 )
25 '
26
27 for u in 002 022
28 do
29 test_expect_success POSIXPERM "shared=1 does not clear bits preset by umask $u" '
30 test_when_finished "rm -rf sub" &&
31 mkdir sub && (
32 cd sub &&
33 umask $u &&
34 git init --shared=1 &&
35 test 1 = "$(git config core.sharedrepository)"
36 ) &&
37 actual=$(ls -l sub/.git/HEAD) &&
38 case "$actual" in
39 -rw-rw-r--*)
40 : happy
41 ;;
42 *)
43 echo Oops, .git/HEAD is not 0664 but $actual
44 false
45 ;;
46 esac
47 '
48 done
49
50 test_expect_success 'shared=all' '
51 git init --template= --shared=all &&
52 test 2 = $(git config core.sharedrepository)
53 '
54
55 test_expect_failure 'template can set core.bare' '
56 test_when_finished "rm -rf subdir" &&
57 test_when_finished "rm -rf templates" &&
58 test_config core.bare true &&
59 umask 0022 &&
60 mkdir -p templates/ &&
61 cp .git/config templates/config &&
62 git init --template=templates subdir &&
63 test_path_exists subdir/HEAD
64 '
65
66 test_expect_success 'template can set core.bare but overridden by command line' '
67 test_when_finished "rm -rf subdir" &&
68 test_when_finished "rm -rf templates" &&
69 test_config core.bare true &&
70 umask 0022 &&
71 mkdir -p templates/ &&
72 cp .git/config templates/config &&
73 git init --no-bare --template=templates subdir &&
74 test_path_exists subdir/.git/HEAD
75 '
76
77 test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
78 : > a1 &&
79 git add a1 &&
80 test_tick &&
81 git commit -m a1 &&
82 mkdir .git/info &&
83 umask 0277 &&
84 git update-server-info &&
85 actual="$(ls -l .git/info/refs)" &&
86 case "$actual" in
87 -r--r--r--*)
88 : happy
89 ;;
90 *)
91 echo Oops, .git/info/refs is not 0444
92 false
93 ;;
94 esac
95 '
96
97 for u in 0660:rw-rw---- \
98 0640:rw-r----- \
99 0600:rw------- \
100 0666:rw-rw-rw- \
101 0664:rw-rw-r--
102 do
103 x=$(expr "$u" : ".*:\([rw-]*\)") &&
104 y=$(echo "$x" | sed -e "s/w/-/g") &&
105 u=$(expr "$u" : "\([0-7]*\)") &&
106 git config core.sharedrepository "$u" &&
107 umask 0277 &&
108
109 test_expect_success POSIXPERM "shared = $u ($y) ro" '
110
111 rm -f .git/info/refs &&
112 git update-server-info &&
113 actual="$(test_modebits .git/info/refs)" &&
114 test "x$actual" = "x-$y"
115
116 '
117
118 umask 077 &&
119 test_expect_success POSIXPERM "shared = $u ($x) rw" '
120
121 rm -f .git/info/refs &&
122 git update-server-info &&
123 actual="$(test_modebits .git/info/refs)" &&
124 test "x$actual" = "x-$x"
125
126 '
127
128 done
129
130 test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' '
131 rm -f .git/info/refs &&
132 test_unconfig core.sharedrepository &&
133 umask 002 &&
134 git update-server-info &&
135 echo "-rw-rw-r--" >expect &&
136 test_modebits .git/info/refs >actual &&
137 test_cmp expect actual
138 '
139
140 test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' '
141 umask 077 &&
142 git config core.sharedRepository group &&
143 git reflog expire --all &&
144 actual="$(ls -l .git/logs/refs/heads/main)" &&
145 case "$actual" in
146 -rw-rw-*)
147 : happy
148 ;;
149 *)
150 echo Ooops, .git/logs/refs/heads/main is not 066x [$actual]
151 false
152 ;;
153 esac
154 '
155
156 test_expect_success POSIXPERM 'forced modes' '
157 test_when_finished "rm -rf new" &&
158 mkdir -p templates/hooks &&
159 echo update-server-info >templates/hooks/post-update &&
160 chmod +x templates/hooks/post-update &&
161 echo : >random-file &&
162 mkdir new &&
163 (
164 cd new &&
165 umask 002 &&
166 git init --shared=0660 --template=../templates &&
167 test_path_is_file .git/hooks/post-update &&
168 >frotz &&
169 git add frotz &&
170 git commit -a -m initial &&
171 git repack
172 ) &&
173 # List repository files meant to be protected; note that
174 # COMMIT_EDITMSG does not matter---0mode is not about a
175 # repository with a work tree.
176 find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
177 xargs ls -ld >actual &&
178
179 # Everything must be unaccessible to others
180 test -z "$(sed -e "/^.......---/d" actual)" &&
181
182 # All directories must have either 2770 or 770
183 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
184
185 # post-update hook must be 0770
186 test -z "$(sed -n -e "/post-update/{
187 /^-rwxrwx---/d
188 p
189 }" actual)" &&
190
191 # All files inside objects must be accessible by us
192 test -z "$(sed -n -e "/objects\//{
193 /^d/d
194 /^-r.-r.----/d
195 p
196 }" actual)"
197 '
198
199 test_expect_success POSIXPERM 'remote init does not use config from cwd' '
200 test_when_finished "rm -rf child.git" &&
201 git config core.sharedrepository 0666 &&
202 umask 0022 &&
203 git init --bare child.git &&
204 echo "-rw-r--r--" >expect &&
205 test_modebits child.git/config >actual &&
206 test_cmp expect actual
207 '
208
209 test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' '
210 git config core.sharedrepository 0666 &&
211 umask 0022 &&
212 echo whatever >templates/foo &&
213 git init --template=templates &&
214 echo "-rw-rw-rw-" >expect &&
215 test_modebits .git/foo >actual &&
216 test_cmp expect actual
217 '
218
219 test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' '
220 test_when_finished "rm -rf child.git" &&
221 umask 0022 &&
222 git init --bare --shared=0666 child.git &&
223 test_path_is_missing child.git/foo &&
224 git init --bare --template=templates child.git &&
225 echo "-rw-rw-rw-" >expect &&
226 test_modebits child.git/foo >actual &&
227 test_cmp expect actual
228 '
229
230 test_expect_success POSIXPERM 'template can set core.sharedrepository' '
231 test_when_finished "rm -rf child.git" &&
232 umask 0022 &&
233 git config core.sharedrepository 0666 &&
234 cp .git/config templates/config &&
235 git init --bare --template=templates child.git &&
236 echo "-rw-rw-rw-" >expect &&
237 test_modebits child.git/HEAD >actual &&
238 test_cmp expect actual
239 '
240
241 test_done