| test_description='verify safe.directory checks while running as root' |
| . "$TEST_DIRECTORY"/lib-sudo.sh |
| if [ "$GIT_TEST_ALLOW_SUDO" != "YES" ] |
| skip_all="You must set env var GIT_TEST_ALLOW_SUDO=YES in order to run this test" |
| if ! test_have_prereq NOT_ROOT |
| skip_all="These tests do not support running as root" |
| sudo command -v git >r && |
| if ! test_have_prereq SUDO |
| skip_all="Your sudo/system configuration is either too strict or unsupported" |
| test_expect_success SUDO 'setup' ' |
| test_expect_success SUDO 'sudo git status as original owner' ' |
| test_expect_success SUDO 'setup root owned repository' ' |
| test_expect_success 'cannot access if owned by root' ' |
| test_must_fail git status |
| test_expect_success 'can access if addressed explicitly' ' |
| GIT_DIR=.git GIT_WORK_TREE=. git status |
| test_expect_success SUDO 'can access with sudo if root' ' |
| test_expect_success SUDO 'can access with sudo if root by removing SUDO_UID' ' |
| # this MUST be always the last test |
| test_expect_success SUDO 'cleanup' ' |