Johannes Schindelin | 8352522 | 2007-07-11 15:18:17 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Johannes Schindelin |
| 4 | # |
| 5 | |
| 6 | test_description='Test shared repository initialization' |
| 7 | |
Johannes Schindelin | 06d5314 | 2020-11-18 23:44:21 +0000 | [diff] [blame] | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
Jiang Xin | bcb71d4 | 2022-11-29 21:15:11 +0800 | [diff] [blame] | 11 | TEST_CREATE_REPO_NO_TEMPLATE=1 |
Ævar Arnfjörð Bjarmason | b2e5d75 | 2023-02-07 00:07:36 +0100 | [diff] [blame] | 12 | TEST_PASSES_SANITIZE_LEAK=true |
Johannes Schindelin | 8352522 | 2007-07-11 15:18:17 +0100 | [diff] [blame] | 13 | . ./test-lib.sh |
| 14 | |
Matt McCutchen | 8ed0a74 | 2008-10-16 22:32:14 -0400 | [diff] [blame] | 15 | # Remove a default ACL from the test dir if possible. |
| 16 | setfacl -k . 2>/dev/null |
| 17 | |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 18 | # User must have read permissions to the repo -> failure on --shared=0400 |
| 19 | test_expect_success 'shared = 0400 (faulty permission u-w)' ' |
Jeff King | 95508a0 | 2015-03-20 06:13:11 -0400 | [diff] [blame] | 20 | test_when_finished "rm -rf sub" && |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 21 | mkdir sub && ( |
Jeff King | 95508a0 | 2015-03-20 06:13:11 -0400 | [diff] [blame] | 22 | cd sub && |
| 23 | test_must_fail git init --shared=0400 |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 24 | ) |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 25 | ' |
| 26 | |
Petr Baudis | 8c6202d | 2008-07-12 03:15:03 +0200 | [diff] [blame] | 27 | for u in 002 022 |
| 28 | do |
Johannes Sixt | ee9fb68 | 2009-03-13 22:55:27 +0100 | [diff] [blame] | 29 | test_expect_success POSIXPERM "shared=1 does not clear bits preset by umask $u" ' |
Jiang Xin | 5d64229 | 2022-11-29 21:15:10 +0800 | [diff] [blame] | 30 | test_when_finished "rm -rf sub" && |
Petr Baudis | 8c6202d | 2008-07-12 03:15:03 +0200 | [diff] [blame] | 31 | mkdir sub && ( |
| 32 | cd sub && |
| 33 | umask $u && |
| 34 | git init --shared=1 && |
| 35 | test 1 = "$(git config core.sharedrepository)" |
| 36 | ) && |
Jeff King | 95508a0 | 2015-03-20 06:13:11 -0400 | [diff] [blame] | 37 | actual=$(ls -l sub/.git/HEAD) && |
Petr Baudis | 8c6202d | 2008-07-12 03:15:03 +0200 | [diff] [blame] | 38 | case "$actual" in |
| 39 | -rw-rw-r--*) |
| 40 | : happy |
| 41 | ;; |
| 42 | *) |
| 43 | echo Oops, .git/HEAD is not 0664 but $actual |
| 44 | false |
| 45 | ;; |
| 46 | esac |
| 47 | ' |
Petr Baudis | 8c6202d | 2008-07-12 03:15:03 +0200 | [diff] [blame] | 48 | done |
| 49 | |
Johannes Schindelin | 8352522 | 2007-07-11 15:18:17 +0100 | [diff] [blame] | 50 | test_expect_success 'shared=all' ' |
Ævar Arnfjörð Bjarmason | ce5369e | 2022-06-03 13:15:07 +0200 | [diff] [blame] | 51 | git init --template= --shared=all && |
Johannes Schindelin | 8352522 | 2007-07-11 15:18:17 +0100 | [diff] [blame] | 52 | test 2 = $(git config core.sharedrepository) |
| 53 | ' |
| 54 | |
Johannes Sixt | ee9fb68 | 2009-03-13 22:55:27 +0100 | [diff] [blame] | 55 | test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' ' |
Johannes Schindelin | 8352522 | 2007-07-11 15:18:17 +0100 | [diff] [blame] | 56 | : > a1 && |
| 57 | git add a1 && |
| 58 | test_tick && |
| 59 | git commit -m a1 && |
Ævar Arnfjörð Bjarmason | ce5369e | 2022-06-03 13:15:07 +0200 | [diff] [blame] | 60 | mkdir .git/info && |
Johannes Schindelin | 8352522 | 2007-07-11 15:18:17 +0100 | [diff] [blame] | 61 | umask 0277 && |
| 62 | git update-server-info && |
Arjen Laarhoven | 19b28bf | 2007-08-17 00:02:17 +0200 | [diff] [blame] | 63 | actual="$(ls -l .git/info/refs)" && |
| 64 | case "$actual" in |
| 65 | -r--r--r--*) |
| 66 | : happy |
| 67 | ;; |
| 68 | *) |
| 69 | echo Oops, .git/info/refs is not 0444 |
| 70 | false |
| 71 | ;; |
| 72 | esac |
Johannes Schindelin | 8352522 | 2007-07-11 15:18:17 +0100 | [diff] [blame] | 73 | ' |
| 74 | |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 75 | for u in 0660:rw-rw---- \ |
| 76 | 0640:rw-r----- \ |
| 77 | 0600:rw------- \ |
| 78 | 0666:rw-rw-rw- \ |
| 79 | 0664:rw-rw-r-- |
| 80 | do |
| 81 | x=$(expr "$u" : ".*:\([rw-]*\)") && |
| 82 | y=$(echo "$x" | sed -e "s/w/-/g") && |
| 83 | u=$(expr "$u" : "\([0-7]*\)") && |
| 84 | git config core.sharedrepository "$u" && |
| 85 | umask 0277 && |
| 86 | |
Johannes Sixt | ee9fb68 | 2009-03-13 22:55:27 +0100 | [diff] [blame] | 87 | test_expect_success POSIXPERM "shared = $u ($y) ro" ' |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 88 | |
| 89 | rm -f .git/info/refs && |
| 90 | git update-server-info && |
Christian Couder | 73de1c9 | 2017-06-25 06:34:28 +0200 | [diff] [blame] | 91 | actual="$(test_modebits .git/info/refs)" && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 92 | test "x$actual" = "x-$y" |
Jeff King | 95508a0 | 2015-03-20 06:13:11 -0400 | [diff] [blame] | 93 | |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 94 | ' |
| 95 | |
| 96 | umask 077 && |
Johannes Sixt | ee9fb68 | 2009-03-13 22:55:27 +0100 | [diff] [blame] | 97 | test_expect_success POSIXPERM "shared = $u ($x) rw" ' |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 98 | |
| 99 | rm -f .git/info/refs && |
| 100 | git update-server-info && |
Christian Couder | 73de1c9 | 2017-06-25 06:34:28 +0200 | [diff] [blame] | 101 | actual="$(test_modebits .git/info/refs)" && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 102 | test "x$actual" = "x-$x" |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 103 | |
| 104 | ' |
| 105 | |
| 106 | done |
| 107 | |
Jeff King | d91175b | 2015-01-05 22:50:49 -0500 | [diff] [blame] | 108 | test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' ' |
| 109 | rm -f .git/info/refs && |
| 110 | test_unconfig core.sharedrepository && |
| 111 | umask 002 && |
| 112 | git update-server-info && |
| 113 | echo "-rw-rw-r--" >expect && |
Christian Couder | 73de1c9 | 2017-06-25 06:34:28 +0200 | [diff] [blame] | 114 | test_modebits .git/info/refs >actual && |
Jeff King | d91175b | 2015-01-05 22:50:49 -0500 | [diff] [blame] | 115 | test_cmp expect actual |
| 116 | ' |
| 117 | |
Johannes Sixt | ee9fb68 | 2009-03-13 22:55:27 +0100 | [diff] [blame] | 118 | test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' ' |
Jeff King | d05c77c | 2015-01-05 22:49:43 -0500 | [diff] [blame] | 119 | umask 077 && |
Pierre Habouzit | 336d09d | 2008-06-15 23:37:42 +0200 | [diff] [blame] | 120 | git config core.sharedRepository group && |
| 121 | git reflog expire --all && |
Johannes Schindelin | 06d5314 | 2020-11-18 23:44:21 +0000 | [diff] [blame] | 122 | actual="$(ls -l .git/logs/refs/heads/main)" && |
Pierre Habouzit | 336d09d | 2008-06-15 23:37:42 +0200 | [diff] [blame] | 123 | case "$actual" in |
| 124 | -rw-rw-*) |
| 125 | : happy |
| 126 | ;; |
| 127 | *) |
Han-Wen Nienhuys | 0218ad5 | 2021-05-31 16:56:23 +0000 | [diff] [blame] | 128 | echo Ooops, .git/logs/refs/heads/main is not 066x [$actual] |
Pierre Habouzit | 336d09d | 2008-06-15 23:37:42 +0200 | [diff] [blame] | 129 | false |
| 130 | ;; |
| 131 | esac |
| 132 | ' |
| 133 | |
Junio C Hamano | 7d5a180 | 2009-04-12 17:55:18 -0700 | [diff] [blame] | 134 | test_expect_success POSIXPERM 'forced modes' ' |
Jiang Xin | 5d64229 | 2022-11-29 21:15:10 +0800 | [diff] [blame] | 135 | test_when_finished "rm -rf new" && |
Junio C Hamano | 5a688fe | 2009-03-25 16:19:36 -0700 | [diff] [blame] | 136 | mkdir -p templates/hooks && |
| 137 | echo update-server-info >templates/hooks/post-update && |
| 138 | chmod +x templates/hooks/post-update && |
| 139 | echo : >random-file && |
| 140 | mkdir new && |
| 141 | ( |
| 142 | cd new && |
| 143 | umask 002 && |
Jiang Xin | a0883a2 | 2022-11-29 21:15:09 +0800 | [diff] [blame] | 144 | git init --shared=0660 --template=../templates && |
| 145 | test_path_is_file .git/hooks/post-update && |
Junio C Hamano | 5a688fe | 2009-03-25 16:19:36 -0700 | [diff] [blame] | 146 | >frotz && |
| 147 | git add frotz && |
| 148 | git commit -a -m initial && |
| 149 | git repack |
| 150 | ) && |
Johannes Sixt | 0786882 | 2009-04-12 21:22:02 +0200 | [diff] [blame] | 151 | # List repository files meant to be protected; note that |
| 152 | # COMMIT_EDITMSG does not matter---0mode is not about a |
| 153 | # repository with a work tree. |
| 154 | find new/.git -type f -name COMMIT_EDITMSG -prune -o -print | |
Junio C Hamano | 5a688fe | 2009-03-25 16:19:36 -0700 | [diff] [blame] | 155 | xargs ls -ld >actual && |
| 156 | |
| 157 | # Everything must be unaccessible to others |
Johannes Sixt | 0786882 | 2009-04-12 21:22:02 +0200 | [diff] [blame] | 158 | test -z "$(sed -e "/^.......---/d" actual)" && |
Junio C Hamano | 5a688fe | 2009-03-25 16:19:36 -0700 | [diff] [blame] | 159 | |
Jeff King | 1b89eaa | 2009-03-31 16:36:00 -0400 | [diff] [blame] | 160 | # All directories must have either 2770 or 770 |
| 161 | test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" && |
Junio C Hamano | 5a688fe | 2009-03-25 16:19:36 -0700 | [diff] [blame] | 162 | |
| 163 | # post-update hook must be 0770 |
| 164 | test -z "$(sed -n -e "/post-update/{ |
| 165 | /^-rwxrwx---/d |
| 166 | p |
| 167 | }" actual)" && |
| 168 | |
Johannes Sixt | 0786882 | 2009-04-12 21:22:02 +0200 | [diff] [blame] | 169 | # All files inside objects must be accessible by us |
Junio C Hamano | 5a688fe | 2009-03-25 16:19:36 -0700 | [diff] [blame] | 170 | test -z "$(sed -n -e "/objects\//{ |
| 171 | /^d/d |
Johannes Sixt | 0786882 | 2009-04-12 21:22:02 +0200 | [diff] [blame] | 172 | /^-r.-r.----/d |
| 173 | p |
Junio C Hamano | 5a688fe | 2009-03-25 16:19:36 -0700 | [diff] [blame] | 174 | }" actual)" |
| 175 | ' |
| 176 | |
Jeff King | b9605bc | 2016-09-12 20:24:15 -0700 | [diff] [blame] | 177 | test_expect_success POSIXPERM 'remote init does not use config from cwd' ' |
Jiang Xin | 5d64229 | 2022-11-29 21:15:10 +0800 | [diff] [blame] | 178 | test_when_finished "rm -rf child.git" && |
Jeff King | b9605bc | 2016-09-12 20:24:15 -0700 | [diff] [blame] | 179 | git config core.sharedrepository 0666 && |
| 180 | umask 0022 && |
| 181 | git init --bare child.git && |
| 182 | echo "-rw-r--r--" >expect && |
Christian Couder | 73de1c9 | 2017-06-25 06:34:28 +0200 | [diff] [blame] | 183 | test_modebits child.git/config >actual && |
Jeff King | b9605bc | 2016-09-12 20:24:15 -0700 | [diff] [blame] | 184 | test_cmp expect actual |
| 185 | ' |
| 186 | |
Jeff King | 4543926 | 2016-09-12 20:24:23 -0700 | [diff] [blame] | 187 | test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' ' |
| 188 | git config core.sharedrepository 0666 && |
| 189 | umask 0022 && |
| 190 | echo whatever >templates/foo && |
| 191 | git init --template=templates && |
| 192 | echo "-rw-rw-rw-" >expect && |
Christian Couder | 73de1c9 | 2017-06-25 06:34:28 +0200 | [diff] [blame] | 193 | test_modebits .git/foo >actual && |
Jeff King | 4543926 | 2016-09-12 20:24:23 -0700 | [diff] [blame] | 194 | test_cmp expect actual |
| 195 | ' |
| 196 | |
| 197 | test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' ' |
Jiang Xin | 5d64229 | 2022-11-29 21:15:10 +0800 | [diff] [blame] | 198 | test_when_finished "rm -rf child.git" && |
Jeff King | 4543926 | 2016-09-12 20:24:23 -0700 | [diff] [blame] | 199 | umask 0022 && |
| 200 | git init --bare --shared=0666 child.git && |
| 201 | test_path_is_missing child.git/foo && |
Nguyễn Thái Ngọc Duy | e1df7fe | 2019-05-10 17:46:57 +0700 | [diff] [blame] | 202 | git init --bare --template=templates child.git && |
Jeff King | 4543926 | 2016-09-12 20:24:23 -0700 | [diff] [blame] | 203 | echo "-rw-rw-rw-" >expect && |
Christian Couder | 73de1c9 | 2017-06-25 06:34:28 +0200 | [diff] [blame] | 204 | test_modebits child.git/foo >actual && |
Jeff King | 4543926 | 2016-09-12 20:24:23 -0700 | [diff] [blame] | 205 | test_cmp expect actual |
| 206 | ' |
| 207 | |
| 208 | test_expect_success POSIXPERM 'template can set core.sharedrepository' ' |
Jiang Xin | 5d64229 | 2022-11-29 21:15:10 +0800 | [diff] [blame] | 209 | test_when_finished "rm -rf child.git" && |
Jeff King | 4543926 | 2016-09-12 20:24:23 -0700 | [diff] [blame] | 210 | umask 0022 && |
| 211 | git config core.sharedrepository 0666 && |
| 212 | cp .git/config templates/config && |
Nguyễn Thái Ngọc Duy | e1df7fe | 2019-05-10 17:46:57 +0700 | [diff] [blame] | 213 | git init --bare --template=templates child.git && |
Jeff King | 4543926 | 2016-09-12 20:24:23 -0700 | [diff] [blame] | 214 | echo "-rw-rw-rw-" >expect && |
Christian Couder | 73de1c9 | 2017-06-25 06:34:28 +0200 | [diff] [blame] | 215 | test_modebits child.git/HEAD >actual && |
Jeff King | 4543926 | 2016-09-12 20:24:23 -0700 | [diff] [blame] | 216 | test_cmp expect actual |
| 217 | ' |
| 218 | |
Johannes Schindelin | 8352522 | 2007-07-11 15:18:17 +0100 | [diff] [blame] | 219 | test_done |