]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1301-shared-repo.sh
t/lib-gpg: require GPGSSH for GPGSSH_VERIFYTIME prereq
[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_success POSIXPERM 'update-server-info honors core.sharedRepository' '
56 : > a1 &&
57 git add a1 &&
58 test_tick &&
59 git commit -m a1 &&
60 mkdir .git/info &&
61 umask 0277 &&
62 git update-server-info &&
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
73 '
74
75 for u in 0660:rw-rw---- \
76 0640:rw-r----- \
77 0600:rw------- \
78 0666:rw-rw-rw- \
79 0664:rw-rw-r--
80 do
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
87 test_expect_success POSIXPERM "shared = $u ($y) ro" '
88
89 rm -f .git/info/refs &&
90 git update-server-info &&
91 actual="$(test_modebits .git/info/refs)" &&
92 verbose test "x$actual" = "x-$y"
93
94 '
95
96 umask 077 &&
97 test_expect_success POSIXPERM "shared = $u ($x) rw" '
98
99 rm -f .git/info/refs &&
100 git update-server-info &&
101 actual="$(test_modebits .git/info/refs)" &&
102 verbose test "x$actual" = "x-$x"
103
104 '
105
106 done
107
108 test_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 &&
114 test_modebits .git/info/refs >actual &&
115 test_cmp expect actual
116 '
117
118 test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' '
119 umask 077 &&
120 git config core.sharedRepository group &&
121 git reflog expire --all &&
122 actual="$(ls -l .git/logs/refs/heads/main)" &&
123 case "$actual" in
124 -rw-rw-*)
125 : happy
126 ;;
127 *)
128 echo Ooops, .git/logs/refs/heads/main is not 066x [$actual]
129 false
130 ;;
131 esac
132 '
133
134 test_expect_success POSIXPERM 'forced modes' '
135 test_when_finished "rm -rf new" &&
136 mkdir -p templates/hooks &&
137 echo update-server-info >templates/hooks/post-update &&
138 chmod +x templates/hooks/post-update &&
139 echo : >random-file &&
140 mkdir new &&
141 (
142 cd new &&
143 umask 002 &&
144 git init --shared=0660 --template=../templates &&
145 test_path_is_file .git/hooks/post-update &&
146 >frotz &&
147 git add frotz &&
148 git commit -a -m initial &&
149 git repack
150 ) &&
151 # List repository files meant to be protected; note that
152 # COMMIT_EDITMSG does not matter---0mode is not about a
153 # repository with a work tree.
154 find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
155 xargs ls -ld >actual &&
156
157 # Everything must be unaccessible to others
158 test -z "$(sed -e "/^.......---/d" actual)" &&
159
160 # All directories must have either 2770 or 770
161 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
162
163 # post-update hook must be 0770
164 test -z "$(sed -n -e "/post-update/{
165 /^-rwxrwx---/d
166 p
167 }" actual)" &&
168
169 # All files inside objects must be accessible by us
170 test -z "$(sed -n -e "/objects\//{
171 /^d/d
172 /^-r.-r.----/d
173 p
174 }" actual)"
175 '
176
177 test_expect_success POSIXPERM 'remote init does not use config from cwd' '
178 test_when_finished "rm -rf child.git" &&
179 git config core.sharedrepository 0666 &&
180 umask 0022 &&
181 git init --bare child.git &&
182 echo "-rw-r--r--" >expect &&
183 test_modebits child.git/config >actual &&
184 test_cmp expect actual
185 '
186
187 test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' '
188 git config core.sharedrepository 0666 &&
189 umask 0022 &&
190 echo whatever >templates/foo &&
191 git init --template=templates &&
192 echo "-rw-rw-rw-" >expect &&
193 test_modebits .git/foo >actual &&
194 test_cmp expect actual
195 '
196
197 test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' '
198 test_when_finished "rm -rf child.git" &&
199 umask 0022 &&
200 git init --bare --shared=0666 child.git &&
201 test_path_is_missing child.git/foo &&
202 git init --bare --template=templates child.git &&
203 echo "-rw-rw-rw-" >expect &&
204 test_modebits child.git/foo >actual &&
205 test_cmp expect actual
206 '
207
208 test_expect_success POSIXPERM 'template can set core.sharedrepository' '
209 test_when_finished "rm -rf child.git" &&
210 umask 0022 &&
211 git config core.sharedrepository 0666 &&
212 cp .git/config templates/config &&
213 git init --bare --template=templates child.git &&
214 echo "-rw-rw-rw-" >expect &&
215 test_modebits child.git/HEAD >actual &&
216 test_cmp expect actual
217 '
218
219 test_done