1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes Schindelin
4#
5
6test_description='Test shared repository initialization'
7
8. ./test-lib.sh
9
10# User must have read permissions to the repo -> failure on --shared=0400
11test_expect_success 'shared = 0400 (faulty permission u-w)' '
12 mkdir sub && (
13 cd sub && git init --shared=0400
14 )
15 ret="$?"
16 rm -rf sub
17 test $ret != "0"
18'
19
20for u in 002 022
21do
22 test_expect_success "shared=1 does not clear bits preset by umask $u" '
23 mkdir sub && (
24 cd sub &&
25 umask $u &&
26 git init --shared=1 &&
27 test 1 = "$(git config core.sharedrepository)"
28 ) &&
29 actual=$(ls -l sub/.git/HEAD)
30 case "$actual" in
31 -rw-rw-r--*)
32 : happy
33 ;;
34 *)
35 echo Oops, .git/HEAD is not 0664 but $actual
36 false
37 ;;
38 esac
39 '
40 rm -rf sub
41done
42
43test_expect_success 'shared=all' '
44 mkdir sub &&
45 cd sub &&
46 git init --shared=all &&
47 test 2 = $(git config core.sharedrepository)
48'
49
50test_expect_success 'update-server-info honors core.sharedRepository' '
51 : > a1 &&
52 git add a1 &&
53 test_tick &&
54 git commit -m a1 &&
55 umask 0277 &&
56 git update-server-info &&
57 actual="$(ls -l .git/info/refs)" &&
58 case "$actual" in
59 -r--r--r--*)
60 : happy
61 ;;
62 *)
63 echo Oops, .git/info/refs is not 0444
64 false
65 ;;
66 esac
67'
68
69for u in 0660:rw-rw---- \
70 0640:rw-r----- \
71 0600:rw------- \
72 0666:rw-rw-rw- \
73 0664:rw-rw-r--
74do
75 x=$(expr "$u" : ".*:\([rw-]*\)") &&
76 y=$(echo "$x" | sed -e "s/w/-/g") &&
77 u=$(expr "$u" : "\([0-7]*\)") &&
78 git config core.sharedrepository "$u" &&
79 umask 0277 &&
80
81 test_expect_success "shared = $u ($y) ro" '
82
83 rm -f .git/info/refs &&
84 git update-server-info &&
85 actual="$(ls -l .git/info/refs)" &&
86 actual=${actual%% *} &&
87 test "x$actual" = "x-$y" || {
88 ls -lt .git/info
89 false
90 }
91 '
92
93 umask 077 &&
94 test_expect_success "shared = $u ($x) rw" '
95
96 rm -f .git/info/refs &&
97 git update-server-info &&
98 actual="$(ls -l .git/info/refs)" &&
99 actual=${actual%% *} &&
100 test "x$actual" = "x-$x" || {
101 ls -lt .git/info
102 false
103 }
104
105 '
106
107done
108
109test_expect_success 'git reflog expire honors core.sharedRepository' '
110 git config core.sharedRepository group &&
111 git reflog expire --all &&
112 actual="$(ls -l .git/logs/refs/heads/master)" &&
113 case "$actual" in
114 -rw-rw-*)
115 : happy
116 ;;
117 *)
118 echo Ooops, .git/logs/refs/heads/master is not 0662 [$actual]
119 false
120 ;;
121 esac
122'
123
124test_done