t / t1301-shared-repo.shon commit Merge branch 'jk/ident-ai-canonname-could-be-null' into maint (11738dd)
   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# Remove a default ACL from the test dir if possible.
  11setfacl -k . 2>/dev/null
  12
  13# User must have read permissions to the repo -> failure on --shared=0400
  14test_expect_success 'shared = 0400 (faulty permission u-w)' '
  15        test_when_finished "rm -rf sub" &&
  16        mkdir sub && (
  17                cd sub &&
  18                test_must_fail git init --shared=0400
  19        )
  20'
  21
  22modebits () {
  23        ls -l "$1" | sed -e 's|^\(..........\).*|\1|'
  24}
  25
  26for u in 002 022
  27do
  28        test_expect_success POSIXPERM "shared=1 does not clear bits preset by umask $u" '
  29                mkdir sub && (
  30                        cd sub &&
  31                        umask $u &&
  32                        git init --shared=1 &&
  33                        test 1 = "$(git config core.sharedrepository)"
  34                ) &&
  35                actual=$(ls -l sub/.git/HEAD) &&
  36                case "$actual" in
  37                -rw-rw-r--*)
  38                        : happy
  39                        ;;
  40                *)
  41                        echo Oops, .git/HEAD is not 0664 but $actual
  42                        false
  43                        ;;
  44                esac
  45        '
  46        rm -rf sub
  47done
  48
  49test_expect_success 'shared=all' '
  50        mkdir sub &&
  51        cd sub &&
  52        git init --shared=all &&
  53        test 2 = $(git config core.sharedrepository)
  54'
  55
  56test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
  57        : > a1 &&
  58        git add a1 &&
  59        test_tick &&
  60        git commit -m a1 &&
  61        umask 0277 &&
  62        git update-server-info &&
  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
  73'
  74
  75for u in        0660:rw-rw---- \
  76                0640:rw-r----- \
  77                0600:rw------- \
  78                0666:rw-rw-rw- \
  79                0664:rw-rw-r--
  80do
  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
  87        test_expect_success POSIXPERM "shared = $u ($y) ro" '
  88
  89                rm -f .git/info/refs &&
  90                git update-server-info &&
  91                actual="$(modebits .git/info/refs)" &&
  92                verbose test "x$actual" = "x-$y"
  93
  94        '
  95
  96        umask 077 &&
  97        test_expect_success POSIXPERM "shared = $u ($x) rw" '
  98
  99                rm -f .git/info/refs &&
 100                git update-server-info &&
 101                actual="$(modebits .git/info/refs)" &&
 102                verbose test "x$actual" = "x-$x"
 103
 104        '
 105
 106done
 107
 108test_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 &&
 114        modebits .git/info/refs >actual &&
 115        test_cmp expect actual
 116'
 117
 118test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' '
 119        umask 077 &&
 120        git config core.sharedRepository group &&
 121        git reflog expire --all &&
 122        actual="$(ls -l .git/logs/refs/heads/master)" &&
 123        case "$actual" in
 124        -rw-rw-*)
 125                : happy
 126                ;;
 127        *)
 128                echo Ooops, .git/logs/refs/heads/master is not 0662 [$actual]
 129                false
 130                ;;
 131        esac
 132'
 133
 134test_expect_success POSIXPERM 'forced modes' '
 135        mkdir -p templates/hooks &&
 136        echo update-server-info >templates/hooks/post-update &&
 137        chmod +x templates/hooks/post-update &&
 138        echo : >random-file &&
 139        mkdir new &&
 140        (
 141                cd new &&
 142                umask 002 &&
 143                git init --shared=0660 --template=../templates &&
 144                >frotz &&
 145                git add frotz &&
 146                git commit -a -m initial &&
 147                git repack
 148        ) &&
 149        # List repository files meant to be protected; note that
 150        # COMMIT_EDITMSG does not matter---0mode is not about a
 151        # repository with a work tree.
 152        find new/.git -type f -name COMMIT_EDITMSG -prune -o -print |
 153        xargs ls -ld >actual &&
 154
 155        # Everything must be unaccessible to others
 156        test -z "$(sed -e "/^.......---/d" actual)" &&
 157
 158        # All directories must have either 2770 or 770
 159        test -z "$(sed -n -e "/^drwxrw[sx]---/d" -e "/^d/p" actual)" &&
 160
 161        # post-update hook must be 0770
 162        test -z "$(sed -n -e "/post-update/{
 163                /^-rwxrwx---/d
 164                p
 165        }" actual)" &&
 166
 167        # All files inside objects must be accessible by us
 168        test -z "$(sed -n -e "/objects\//{
 169                /^d/d
 170                /^-r.-r.----/d
 171                p
 172        }" actual)"
 173'
 174
 175test_done