Merge branch 'ps/reflog-list' into HEAD
[alt-git.git] / t / t1301-shared-repo.sh
blobb1eb5c01b899daf9a0075393e3e79d47da069d5d
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_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
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
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
91 echo Oops, .git/info/refs is not 0444
92 false
94 esac
97 for u in 0660:rw-rw---- \
98 0640:rw-r----- \
99 0600:rw------- \
100 0666:rw-rw-rw- \
101 0664:rw-rw-r--
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 &&
109 test_expect_success POSIXPERM "shared = $u ($y) ro" '
111 rm -f .git/info/refs &&
112 git update-server-info &&
113 actual="$(test_modebits .git/info/refs)" &&
114 test "x$actual" = "x-$y"
118 umask 077 &&
119 test_expect_success POSIXPERM "shared = $u ($x) rw" '
121 rm -f .git/info/refs &&
122 git update-server-info &&
123 actual="$(test_modebits .git/info/refs)" &&
124 test "x$actual" = "x-$x"
128 done
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
140 test_expect_success POSIXPERM 'forced modes' '
141 test_when_finished "rm -rf new" &&
142 mkdir -p templates/hooks &&
143 echo update-server-info >templates/hooks/post-update &&
144 chmod +x templates/hooks/post-update &&
145 echo : >random-file &&
146 mkdir new &&
148 cd new &&
149 umask 002 &&
150 git init --shared=0660 --template=../templates &&
151 test_path_is_file .git/hooks/post-update &&
152 >frotz &&
153 git add frotz &&
154 git commit -a -m initial &&
155 git repack
156 ) &&
157 # List repository files meant to be protected; note that
158 # COMMIT_EDITMSG does not matter---0mode is not about a
159 # repository with a work tree.
160 find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
161 xargs ls -ld >actual &&
163 # Everything must be unaccessible to others
164 test -z "$(sed -e "/^.......---/d" actual)" &&
166 # All directories must have either 2770 or 770
167 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
169 # post-update hook must be 0770
170 test -z "$(sed -n -e "/post-update/{
171 /^-rwxrwx---/d
173 }" actual)" &&
175 # All files inside objects must be accessible by us
176 test -z "$(sed -n -e "/objects\//{
177 /^d/d
178 /^-r.-r.----/d
180 }" actual)"
183 test_expect_success POSIXPERM 'remote init does not use config from cwd' '
184 test_when_finished "rm -rf child.git" &&
185 git config core.sharedrepository 0666 &&
186 umask 0022 &&
187 git init --bare child.git &&
188 echo "-rw-r--r--" >expect &&
189 test_modebits child.git/config >actual &&
190 test_cmp expect actual
193 test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' '
194 git config core.sharedrepository 0666 &&
195 umask 0022 &&
196 echo whatever >templates/foo &&
197 git init --template=templates &&
198 echo "-rw-rw-rw-" >expect &&
199 test_modebits .git/foo >actual &&
200 test_cmp expect actual
203 test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' '
204 test_when_finished "rm -rf child.git" &&
205 umask 0022 &&
206 git init --bare --shared=0666 child.git &&
207 test_path_is_missing child.git/foo &&
208 git init --bare --template=templates child.git &&
209 echo "-rw-rw-rw-" >expect &&
210 test_modebits child.git/foo >actual &&
211 test_cmp expect actual
214 test_expect_success POSIXPERM 'template can set core.sharedrepository' '
215 test_when_finished "rm -rf child.git" &&
216 umask 0022 &&
217 git config core.sharedrepository 0666 &&
218 cp .git/config templates/config &&
219 git init --bare --template=templates child.git &&
220 echo "-rw-rw-rw-" >expect &&
221 test_modebits child.git/HEAD >actual &&
222 test_cmp expect actual
225 test_done