]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1309-early-config.sh
Merge branch 'jc/revision-parse-int' into maint-2.43
[thirdparty/git.git] / t / t1309-early-config.sh
1 #!/bin/sh
2
3 test_description='Test read_early_config()'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'read early config' '
9 test_config early.config correct &&
10 test-tool config read_early_config early.config >output &&
11 test correct = "$(cat output)"
12 '
13
14 test_expect_success 'in a sub-directory' '
15 test_config early.config sub &&
16 mkdir -p sub &&
17 (
18 cd sub &&
19 test-tool config read_early_config early.config
20 ) >output &&
21 test sub = "$(cat output)"
22 '
23
24 test_expect_success 'ceiling' '
25 test_config early.config ceiling &&
26 mkdir -p sub &&
27 (
28 GIT_CEILING_DIRECTORIES="$PWD" &&
29 export GIT_CEILING_DIRECTORIES &&
30 cd sub &&
31 test-tool config read_early_config early.config
32 ) >output &&
33 test_must_be_empty output
34 '
35
36 test_expect_success 'ceiling #2' '
37 mkdir -p xdg/git &&
38 git config -f xdg/git/config early.config xdg &&
39 test_config early.config ceiling &&
40 mkdir -p sub &&
41 (
42 XDG_CONFIG_HOME="$PWD"/xdg &&
43 GIT_CEILING_DIRECTORIES="$PWD" &&
44 export GIT_CEILING_DIRECTORIES XDG_CONFIG_HOME &&
45 cd sub &&
46 test-tool config read_early_config early.config
47 ) >output &&
48 test xdg = "$(cat output)"
49 '
50
51 cmdline_config="'test.source=cmdline'"
52 test_expect_success 'read config file in right order' '
53 echo "[test]source = home" >>.gitconfig &&
54 git init foo &&
55 (
56 cd foo &&
57 echo "[test]source = repo" >>.git/config &&
58 GIT_CONFIG_PARAMETERS=$cmdline_config test-tool config \
59 read_early_config test.source >actual &&
60 cat >expected <<-\EOF &&
61 home
62 repo
63 cmdline
64 EOF
65 test_cmp expected actual
66 )
67 '
68
69 test_with_config () {
70 rm -rf throwaway &&
71 git init throwaway &&
72 (
73 cd throwaway &&
74 echo "$*" >.git/config &&
75 test-tool config read_early_config early.config
76 )
77 }
78
79 test_expect_success 'ignore .git/ with incompatible repository version' '
80 test_with_config "[core]repositoryformatversion = 999999" 2>err &&
81 test_grep "warning:.* Expected git repo version <= [1-9]" err
82 '
83
84 test_expect_failure 'ignore .git/ with invalid repository version' '
85 test_with_config "[core]repositoryformatversion = invalid"
86 '
87
88
89 test_expect_failure 'ignore .git/ with invalid config' '
90 test_with_config "["
91 '
92
93 test_expect_success 'early config and onbranch' '
94 echo "[broken" >broken &&
95 test_with_config "[includeif \"onbranch:topic\"]path=../broken"
96 '
97
98 test_expect_success 'onbranch config outside of git repo' '
99 test_config_global includeIf.onbranch:topic.path non-existent &&
100 nongit git help
101 '
102
103 test_done