Sync with 2.36.6
[git/debian.git] / t / t0033-safe-directory.sh
blob3908597d42d705161b5b8808e55c8125f8edffe1
1 #!/bin/sh
3 test_description='verify safe.directory checks'
5 . ./test-lib.sh
7 GIT_TEST_ASSUME_DIFFERENT_OWNER=1
8 export GIT_TEST_ASSUME_DIFFERENT_OWNER
10 expect_rejected_dir () {
11 test_must_fail git status 2>err &&
12 grep "dubious ownership" err
15 test_expect_success 'safe.directory is not set' '
16 expect_rejected_dir
19 test_expect_success 'ignoring safe.directory on the command line' '
20 test_must_fail git -c safe.directory="$(pwd)" status 2>err &&
21 grep "dubious ownership" err
24 test_expect_success 'ignoring safe.directory in the environment' '
25 test_must_fail env GIT_CONFIG_COUNT=1 \
26 GIT_CONFIG_KEY_0="safe.directory" \
27 GIT_CONFIG_VALUE_0="$(pwd)" \
28 git status 2>err &&
29 grep "dubious ownership" err
32 test_expect_success 'ignoring safe.directory in GIT_CONFIG_PARAMETERS' '
33 test_must_fail env \
34 GIT_CONFIG_PARAMETERS="${SQ}safe.directory${SQ}=${SQ}$(pwd)${SQ}" \
35 git status 2>err &&
36 grep "dubious ownership" err
39 test_expect_success 'ignoring safe.directory in repo config' '
41 unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
42 git config safe.directory "$(pwd)"
43 ) &&
44 expect_rejected_dir
47 test_expect_success 'safe.directory does not match' '
48 git config --global safe.directory bogus &&
49 expect_rejected_dir
52 test_expect_success 'path exist as different key' '
53 git config --global foo.bar "$(pwd)" &&
54 expect_rejected_dir
57 test_expect_success 'safe.directory matches' '
58 git config --global --add safe.directory "$(pwd)" &&
59 git status
62 test_expect_success 'safe.directory matches, but is reset' '
63 git config --global --add safe.directory "" &&
64 expect_rejected_dir
67 test_expect_success 'safe.directory=*' '
68 git config --global --add safe.directory "*" &&
69 git status
72 test_expect_success 'safe.directory=*, but is reset' '
73 git config --global --add safe.directory "" &&
74 expect_rejected_dir
77 test_done