3 test_description
='verify safe.directory checks while running as root'
6 .
"$TEST_DIRECTORY"/lib-sudo.sh
8 if [ "$GIT_TEST_ALLOW_SUDO" != "YES" ]
10 skip_all
="You must set env var GIT_TEST_ALLOW_SUDO=YES in order to run this test"
14 if ! test_have_prereq NOT_ROOT
16 skip_all
="These tests do not support running as root"
20 test_lazy_prereq SUDO
'
25 sudo command -v git >r &&
29 if ! test_have_prereq SUDO
31 skip_all
="Your sudo/system configuration is either too strict or unsupported"
35 test_expect_success SUDO
'setup' '
44 test_expect_success SUDO
'sudo git status as original owner' '
52 test_expect_success SUDO
'setup root owned repository' '
53 sudo mkdir -p root/p &&
57 test_expect_success
'cannot access if owned by root' '
60 test_must_fail git status
64 test_expect_success
'can access if addressed explicitly' '
67 GIT_DIR=.git GIT_WORK_TREE=. git status
71 test_expect_success SUDO
'can access with sudo if root' '
78 test_expect_success SUDO
'can access with sudo if root by removing SUDO_UID' '
88 # this MUST be always the last test
89 test_expect_success SUDO
'cleanup' '