]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0033-safe-directory.sh
Git 2.37
[thirdparty/git.git] / t / t0033-safe-directory.sh
CommitLineData
e47363e5
DS
1#!/bin/sh
2
3test_description='verify safe.directory checks'
4
5. ./test-lib.sh
6
7GIT_TEST_ASSUME_DIFFERENT_OWNER=1
8export GIT_TEST_ASSUME_DIFFERENT_OWNER
9
10expect_rejected_dir () {
11 test_must_fail git status 2>err &&
f6256398 12 grep "unsafe repository" err
e47363e5
DS
13}
14
15test_expect_success 'safe.directory is not set' '
16 expect_rejected_dir
17'
18
424f315d
SG
19test_expect_success 'ignoring safe.directory on the command line' '
20 test_must_fail git -c safe.directory="$(pwd)" status 2>err &&
21 grep "unsafe repository" err
22'
23
756d1592
SG
24test_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 "unsafe repository" err
30'
31
32test_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 "unsafe repository" err
37'
38
424f315d
SG
39test_expect_success 'ignoring safe.directory in repo config' '
40 (
41 unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
42 git config safe.directory "$(pwd)"
43 ) &&
44 expect_rejected_dir
45'
46
e47363e5
DS
47test_expect_success 'safe.directory does not match' '
48 git config --global safe.directory bogus &&
49 expect_rejected_dir
50'
51
bb50ec3c
MV
52test_expect_success 'path exist as different key' '
53 git config --global foo.bar "$(pwd)" &&
54 expect_rejected_dir
55'
56
e47363e5
DS
57test_expect_success 'safe.directory matches' '
58 git config --global --add safe.directory "$(pwd)" &&
59 git status
60'
61
62test_expect_success 'safe.directory matches, but is reset' '
63 git config --global --add safe.directory "" &&
64 expect_rejected_dir
65'
66
0f85c4a3
DS
67test_expect_success 'safe.directory=*' '
68 git config --global --add safe.directory "*" &&
69 git status
70'
71
72test_expect_success 'safe.directory=*, but is reset' '
73 git config --global --add safe.directory "" &&
74 expect_rejected_dir
75'
76
e47363e5 77test_done