Merge 'git-gui' into HEAD
[git/mingw/4msysgit.git] / t / t1301-shared-repo.sh
blobde42d21c922045415abedf3c81163682d0754eb5
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes Schindelin
6 test_description='Test shared repository initialization'
8 . ./test-lib.sh
10 # Remove a default ACL from the test dir if possible.
11 setfacl -k . 2>/dev/null
13 # User must have read permissions to the repo -> failure on --shared=0400
14 test_expect_success 'shared = 0400 (faulty permission u-w)' '
15 mkdir sub && (
16 cd sub && git init --shared=0400
18 ret="$?"
19 rm -rf sub
20 test $ret != "0"
23 modebits () {
24 ls -l "$1" | sed -e 's|^\(..........\).*|\1|'
27 for u in 002 022
29 test_expect_success POSIXPERM "shared=1 does not clear bits preset by umask $u" '
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
42 echo Oops, .git/HEAD is not 0664 but $actual
43 false
45 esac
47 rm -rf sub
48 done
50 test_expect_success 'shared=all' '
51 mkdir sub &&
52 cd sub &&
53 git init --shared=all &&
54 test 2 = $(git config core.sharedrepository)
57 test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
58 : > a1 &&
59 git add a1 &&
60 test_tick &&
61 git commit -m a1 &&
62 umask 0277 &&
63 git update-server-info &&
64 actual="$(ls -l .git/info/refs)" &&
65 case "$actual" in
66 -r--r--r--*)
67 : happy
70 echo Oops, .git/info/refs is not 0444
71 false
73 esac
76 for u in 0660:rw-rw---- \
77 0640:rw-r----- \
78 0600:rw------- \
79 0666:rw-rw-rw- \
80 0664:rw-rw-r--
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 &&
88 test_expect_success POSIXPERM "shared = $u ($y) ro" '
90 rm -f .git/info/refs &&
91 git update-server-info &&
92 actual="$(modebits .git/info/refs)" &&
93 test "x$actual" = "x-$y" || {
94 ls -lt .git/info
95 false
99 umask 077 &&
100 test_expect_success POSIXPERM "shared = $u ($x) rw" '
102 rm -f .git/info/refs &&
103 git update-server-info &&
104 actual="$(modebits .git/info/refs)" &&
105 test "x$actual" = "x-$x" || {
106 ls -lt .git/info
107 false
112 done
114 test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' '
115 git config core.sharedRepository group &&
116 git reflog expire --all &&
117 actual="$(ls -l .git/logs/refs/heads/master)" &&
118 case "$actual" in
119 -rw-rw-*)
120 : happy
123 echo Ooops, .git/logs/refs/heads/master is not 0662 [$actual]
124 false
126 esac
129 test_expect_success POSIXPERM 'forced modes' '
130 mkdir -p templates/hooks &&
131 echo update-server-info >templates/hooks/post-update &&
132 chmod +x templates/hooks/post-update &&
133 echo : >random-file &&
134 mkdir new &&
136 cd new &&
137 umask 002 &&
138 git init --shared=0660 --template=../templates &&
139 >frotz &&
140 git add frotz &&
141 git commit -a -m initial &&
142 git repack
143 ) &&
144 # List repository files meant to be protected; note that
145 # COMMIT_EDITMSG does not matter---0mode is not about a
146 # repository with a work tree.
147 find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
148 xargs ls -ld >actual &&
150 # Everything must be unaccessible to others
151 test -z "$(sed -e "/^.......---/d" actual)" &&
153 # All directories must have either 2770 or 770
154 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
156 # post-update hook must be 0770
157 test -z "$(sed -n -e "/post-update/{
158 /^-rwxrwx---/d
160 }" actual)" &&
162 # All files inside objects must be accessible by us
163 test -z "$(sed -n -e "/objects\//{
164 /^d/d
165 /^-r.-r.----/d
167 }" actual)"
170 test_done