win32: fix building with NO_UNIX_SOCKETS
[alt-git.git] / t / t1301-shared-repo.sh
blob29cf8a966133a7851722c8cdf828fe3c524a12ec
1 #!/bin/sh
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
11 TEST_CREATE_REPO_NO_TEMPLATE=1
12 TEST_PASSES_SANITIZE_LEAK=true
13 . ./test-lib.sh
15 # Remove a default ACL from the test dir if possible.
16 setfacl -k . 2>/dev/null
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
27 for u in 002 022
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
43 echo Oops, .git/HEAD is not 0664 but $actual
44 false
46 esac
48 done
50 test_expect_success 'shared=all' '
51 git init --template= --shared=all &&
52 test 2 = $(git config core.sharedrepository)
55 test_expect_success 'template cannot 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_is_missing subdir/HEAD
66 test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
67 : > a1 &&
68 git add a1 &&
69 test_tick &&
70 git commit -m a1 &&
71 mkdir .git/info &&
72 umask 0277 &&
73 git update-server-info &&
74 actual="$(ls -l .git/info/refs)" &&
75 case "$actual" in
76 -r--r--r--*)
77 : happy
80 echo Oops, .git/info/refs is not 0444
81 false
83 esac
86 for u in 0660:rw-rw---- \
87 0640:rw-r----- \
88 0600:rw------- \
89 0666:rw-rw-rw- \
90 0664:rw-rw-r--
92 x=$(expr "$u" : ".*:\([rw-]*\)") &&
93 y=$(echo "$x" | sed -e "s/w/-/g") &&
94 u=$(expr "$u" : "\([0-7]*\)") &&
95 git config core.sharedrepository "$u" &&
96 umask 0277 &&
98 test_expect_success POSIXPERM "shared = $u ($y) ro" '
100 rm -f .git/info/refs &&
101 git update-server-info &&
102 actual="$(test_modebits .git/info/refs)" &&
103 test "x$actual" = "x-$y"
107 umask 077 &&
108 test_expect_success POSIXPERM "shared = $u ($x) rw" '
110 rm -f .git/info/refs &&
111 git update-server-info &&
112 actual="$(test_modebits .git/info/refs)" &&
113 test "x$actual" = "x-$x"
117 done
119 test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' '
120 rm -f .git/info/refs &&
121 test_unconfig core.sharedrepository &&
122 umask 002 &&
123 git update-server-info &&
124 echo "-rw-rw-r--" >expect &&
125 test_modebits .git/info/refs >actual &&
126 test_cmp expect actual
129 test_expect_success POSIXPERM 'forced modes' '
130 test_when_finished "rm -rf new" &&
131 mkdir -p templates/hooks &&
132 echo update-server-info >templates/hooks/post-update &&
133 chmod +x templates/hooks/post-update &&
134 echo : >random-file &&
135 mkdir new &&
137 cd new &&
138 umask 002 &&
139 git init --shared=0660 --template=../templates &&
140 test_path_is_file .git/hooks/post-update &&
141 >frotz &&
142 git add frotz &&
143 git commit -a -m initial &&
144 git repack
145 ) &&
146 # List repository files meant to be protected; note that
147 # COMMIT_EDITMSG does not matter---0mode is not about a
148 # repository with a work tree.
149 find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
150 xargs ls -ld >actual &&
152 # Everything must be unaccessible to others
153 test -z "$(sed -e "/^.......---/d" actual)" &&
155 # All directories must have either 2770 or 770
156 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
158 # post-update hook must be 0770
159 test -z "$(sed -n -e "/post-update/{
160 /^-rwxrwx---/d
162 }" actual)" &&
164 # All files inside objects must be accessible by us
165 test -z "$(sed -n -e "/objects\//{
166 /^d/d
167 /^-r.-r.----/d
169 }" actual)"
172 test_expect_success POSIXPERM 'remote init does not use config from cwd' '
173 test_when_finished "rm -rf child.git" &&
174 git config core.sharedrepository 0666 &&
175 umask 0022 &&
176 git init --bare child.git &&
177 echo "-rw-r--r--" >expect &&
178 test_modebits child.git/config >actual &&
179 test_cmp expect actual
182 test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' '
183 git config core.sharedrepository 0666 &&
184 umask 0022 &&
185 echo whatever >templates/foo &&
186 git init --template=templates &&
187 echo "-rw-rw-rw-" >expect &&
188 test_modebits .git/foo >actual &&
189 test_cmp expect actual
192 test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' '
193 test_when_finished "rm -rf child.git" &&
194 umask 0022 &&
195 git init --bare --shared=0666 child.git &&
196 test_path_is_missing child.git/foo &&
197 git init --bare --template=templates child.git &&
198 echo "-rw-rw-rw-" >expect &&
199 test_modebits child.git/foo >actual &&
200 test_cmp expect actual
203 test_expect_success POSIXPERM 'template can set core.sharedrepository' '
204 test_when_finished "rm -rf child.git" &&
205 umask 0022 &&
206 git config core.sharedrepository 0666 &&
207 cp .git/config templates/config &&
208 git init --bare --template=templates child.git &&
209 echo "-rw-rw-rw-" >expect &&
210 test_modebits child.git/HEAD >actual &&
211 test_cmp expect actual
214 test_done