]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1301-shared-repo.sh
update-server-info: create info/* with mode 0666
[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
8. ./test-lib.sh
9
8ed0a740
MM
10# Remove a default ACL from the test dir if possible.
11setfacl -k . 2>/dev/null
12
06cbe855
HO
13# User must have read permissions to the repo -> failure on --shared=0400
14test_expect_success 'shared = 0400 (faulty permission u-w)' '
15 mkdir sub && (
16 cd sub && git init --shared=0400
17 )
18 ret="$?"
19 rm -rf sub
20 test $ret != "0"
21'
22
5610e3b0
JH
23modebits () {
24 ls -l "$1" | sed -e 's|^\(..........\).*|\1|'
25}
26
8c6202d8
PB
27for u in 002 022
28do
ee9fb68c 29 test_expect_success POSIXPERM "shared=1 does not clear bits preset by umask $u" '
8c6202d8
PB
30 mkdir sub && (
31 cd sub &&
32 umask $u &&
33 git init --shared=1 &&
34 test 1 = "$(git config core.sharedrepository)"
35 ) &&
36 actual=$(ls -l sub/.git/HEAD)
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 '
47 rm -rf sub
48done
49
83525227
JS
50test_expect_success 'shared=all' '
51 mkdir sub &&
52 cd sub &&
53 git init --shared=all &&
54 test 2 = $(git config core.sharedrepository)
55'
56
ee9fb68c 57test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
83525227
JS
58 : > a1 &&
59 git add a1 &&
60 test_tick &&
61 git commit -m a1 &&
62 umask 0277 &&
63 git update-server-info &&
19b28bf5
AL
64 actual="$(ls -l .git/info/refs)" &&
65 case "$actual" in
66 -r--r--r--*)
67 : happy
68 ;;
69 *)
70 echo Oops, .git/info/refs is not 0444
71 false
72 ;;
73 esac
83525227
JS
74'
75
06cbe855
HO
76for u in 0660:rw-rw---- \
77 0640:rw-r----- \
78 0600:rw------- \
79 0666:rw-rw-rw- \
80 0664:rw-rw-r--
81do
82 x=$(expr "$u" : ".*:\([rw-]*\)") &&
83 y=$(echo "$x" | sed -e "s/w/-/g") &&
84 u=$(expr "$u" : "\([0-7]*\)") &&
85 git config core.sharedrepository "$u" &&
86 umask 0277 &&
87
ee9fb68c 88 test_expect_success POSIXPERM "shared = $u ($y) ro" '
06cbe855
HO
89
90 rm -f .git/info/refs &&
91 git update-server-info &&
5610e3b0 92 actual="$(modebits .git/info/refs)" &&
06cbe855
HO
93 test "x$actual" = "x-$y" || {
94 ls -lt .git/info
95 false
96 }
97 '
98
99 umask 077 &&
ee9fb68c 100 test_expect_success POSIXPERM "shared = $u ($x) rw" '
06cbe855
HO
101
102 rm -f .git/info/refs &&
103 git update-server-info &&
5610e3b0 104 actual="$(modebits .git/info/refs)" &&
06cbe855
HO
105 test "x$actual" = "x-$x" || {
106 ls -lt .git/info
107 false
108 }
109
110 '
111
112done
113
d91175b2
JK
114test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' '
115 rm -f .git/info/refs &&
116 test_unconfig core.sharedrepository &&
117 umask 002 &&
118 git update-server-info &&
119 echo "-rw-rw-r--" >expect &&
120 modebits .git/info/refs >actual &&
121 test_cmp expect actual
122'
123
ee9fb68c 124test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' '
d05c77cc 125 umask 077 &&
336d09da
PH
126 git config core.sharedRepository group &&
127 git reflog expire --all &&
128 actual="$(ls -l .git/logs/refs/heads/master)" &&
129 case "$actual" in
130 -rw-rw-*)
131 : happy
132 ;;
133 *)
134 echo Ooops, .git/logs/refs/heads/master is not 0662 [$actual]
135 false
136 ;;
137 esac
138'
139
7d5a1806 140test_expect_success POSIXPERM 'forced modes' '
5a688fe4
JH
141 mkdir -p templates/hooks &&
142 echo update-server-info >templates/hooks/post-update &&
143 chmod +x templates/hooks/post-update &&
144 echo : >random-file &&
145 mkdir new &&
146 (
147 cd new &&
148 umask 002 &&
149 git init --shared=0660 --template=../templates &&
150 >frotz &&
151 git add frotz &&
152 git commit -a -m initial &&
153 git repack
154 ) &&
07868821
JS
155 # List repository files meant to be protected; note that
156 # COMMIT_EDITMSG does not matter---0mode is not about a
157 # repository with a work tree.
158 find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
5a688fe4
JH
159 xargs ls -ld >actual &&
160
161 # Everything must be unaccessible to others
07868821 162 test -z "$(sed -e "/^.......---/d" actual)" &&
5a688fe4 163
1b89eaa4
JK
164 # All directories must have either 2770 or 770
165 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
5a688fe4
JH
166
167 # post-update hook must be 0770
168 test -z "$(sed -n -e "/post-update/{
169 /^-rwxrwx---/d
170 p
171 }" actual)" &&
172
07868821 173 # All files inside objects must be accessible by us
5a688fe4
JH
174 test -z "$(sed -n -e "/objects\//{
175 /^d/d
07868821
JS
176 /^-r.-r.----/d
177 p
5a688fe4
JH
178 }" actual)"
179'
180
83525227 181test_done