Git fork
at reftables-rust 213 lines 5.2 kB view raw
1#!/bin/sh 2# 3# Copyright (c) 2007 Johannes Schindelin 4# 5 6test_description='Test shared repository initialization' 7 8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 10 11TEST_CREATE_REPO_NO_TEMPLATE=1 12. ./test-lib.sh 13 14# Remove a default ACL from the test dir if possible. 15setfacl -k . 2>/dev/null 16 17# User must have read permissions to the repo -> failure on --shared=0400 18test_expect_success 'shared = 0400 (faulty permission u-w)' ' 19 test_when_finished "rm -rf sub" && 20 mkdir sub && ( 21 cd sub && 22 test_must_fail git init --shared=0400 23 ) 24' 25 26for u in 002 022 27do 28 test_expect_success POSIXPERM "shared=1 does not clear bits preset by umask $u" ' 29 test_when_finished "rm -rf sub" && 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 ' 47done 48 49test_expect_success 'shared=all' ' 50 git init --template= --shared=all && 51 test 2 = $(git config core.sharedrepository) 52' 53 54test_expect_success 'template cannot set core.bare' ' 55 test_when_finished "rm -rf subdir" && 56 test_when_finished "rm -rf templates" && 57 test_config core.bare true && 58 umask 0022 && 59 mkdir -p templates/ && 60 cp .git/config templates/config && 61 git init --template=templates subdir && 62 test_path_is_missing subdir/HEAD 63' 64 65test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' ' 66 : > a1 && 67 git add a1 && 68 test_tick && 69 git commit -m a1 && 70 mkdir .git/info && 71 umask 0277 && 72 git update-server-info && 73 actual="$(ls -l .git/info/refs)" && 74 case "$actual" in 75 -r--r--r--*) 76 : happy 77 ;; 78 *) 79 echo Oops, .git/info/refs is not 0444 80 false 81 ;; 82 esac 83' 84 85for u in 0660:rw-rw---- \ 86 0640:rw-r----- \ 87 0600:rw------- \ 88 0666:rw-rw-rw- \ 89 0664:rw-rw-r-- 90do 91 x=$(expr "$u" : ".*:\([rw-]*\)") && 92 y=$(echo "$x" | sed -e "s/w/-/g") && 93 u=$(expr "$u" : "\([0-7]*\)") && 94 git config core.sharedrepository "$u" && 95 umask 0277 && 96 97 test_expect_success POSIXPERM "shared = $u ($y) ro" ' 98 99 rm -f .git/info/refs && 100 git update-server-info && 101 actual="$(test_modebits .git/info/refs)" && 102 test "x$actual" = "x-$y" 103 104 ' 105 106 umask 077 && 107 test_expect_success POSIXPERM "shared = $u ($x) rw" ' 108 109 rm -f .git/info/refs && 110 git update-server-info && 111 actual="$(test_modebits .git/info/refs)" && 112 test "x$actual" = "x-$x" 113 114 ' 115 116done 117 118test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' ' 119 rm -f .git/info/refs && 120 test_unconfig core.sharedrepository && 121 umask 002 && 122 git update-server-info && 123 echo "-rw-rw-r--" >expect && 124 test_modebits .git/info/refs >actual && 125 test_cmp expect actual 126' 127 128test_expect_success POSIXPERM 'forced modes' ' 129 test_when_finished "rm -rf new" && 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 && 135 ( 136 cd new && 137 umask 002 && 138 git init --shared=0660 --template=../templates && 139 test_path_is_file .git/hooks/post-update && 140 >frotz && 141 git add frotz && 142 git commit -a -m initial && 143 git repack 144 ) && 145 # List repository files meant to be protected; note that 146 # COMMIT_EDITMSG does not matter---0mode is not about a 147 # repository with a work tree. 148 find new/.git -type f -name COMMIT_EDITMSG -prune -o -print | 149 xargs ls -ld >actual && 150 151 # Everything must be unaccessible to others 152 test -z "$(sed -e "/^.......---/d" actual)" && 153 154 # All directories must have either 2770 or 770 155 test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" && 156 157 # post-update hook must be 0770 158 test -z "$(sed -n -e "/post-update/{ 159 /^-rwxrwx---/d 160 p 161 }" actual)" && 162 163 # All files inside objects must be accessible by us 164 test -z "$(sed -n -e "/objects\//{ 165 /^d/d 166 /^-r.-r.----/d 167 p 168 }" actual)" 169' 170 171test_expect_success POSIXPERM 'remote init does not use config from cwd' ' 172 test_when_finished "rm -rf child.git" && 173 git config core.sharedrepository 0666 && 174 umask 0022 && 175 git init --bare child.git && 176 echo "-rw-r--r--" >expect && 177 test_modebits child.git/config >actual && 178 test_cmp expect actual 179' 180 181test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' ' 182 git config core.sharedrepository 0666 && 183 umask 0022 && 184 echo whatever >templates/foo && 185 git init --template=templates && 186 echo "-rw-rw-rw-" >expect && 187 test_modebits .git/foo >actual && 188 test_cmp expect actual 189' 190 191test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' ' 192 test_when_finished "rm -rf child.git" && 193 umask 0022 && 194 git init --bare --shared=0666 child.git && 195 test_path_is_missing child.git/foo && 196 git init --bare --template=templates child.git && 197 echo "-rw-rw-rw-" >expect && 198 test_modebits child.git/foo >actual && 199 test_cmp expect actual 200' 201 202test_expect_success POSIXPERM 'template can set core.sharedrepository' ' 203 test_when_finished "rm -rf child.git" && 204 umask 0022 && 205 git config core.sharedrepository 0666 && 206 cp .git/config templates/config && 207 git init --bare --template=templates child.git && 208 echo "-rw-rw-rw-" >expect && 209 test_modebits child.git/HEAD >actual && 210 test_cmp expect actual 211' 212 213test_done