]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1309-early-config.sh
The fifteenth batch
[thirdparty/git.git] / t / t1309-early-config.sh
CommitLineData
1a6ec1eb
JS
1#!/bin/sh
2
3test_description='Test read_early_config()'
4
67606301 5TEST_PASSES_SANITIZE_LEAK=true
1a6ec1eb
JS
6. ./test-lib.sh
7
8test_expect_success 'read early config' '
9 test_config early.config correct &&
0e2678af 10 test-tool config read_early_config early.config >output &&
1a6ec1eb
JS
11 test correct = "$(cat output)"
12'
13
14test_expect_success 'in a sub-directory' '
15 test_config early.config sub &&
16 mkdir -p sub &&
17 (
18 cd sub &&
0e2678af 19 test-tool config read_early_config early.config
1a6ec1eb
JS
20 ) >output &&
21 test sub = "$(cat output)"
22'
23
24test_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 &&
0e2678af 31 test-tool config read_early_config early.config
1a6ec1eb 32 ) >output &&
213dabf4 33 test_must_be_empty output
1a6ec1eb
JS
34'
35
36test_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 &&
0e2678af 46 test-tool config read_early_config early.config
1a6ec1eb
JS
47 ) >output &&
48 test xdg = "$(cat output)"
49'
50
e145a0bc
NTND
51cmdline_config="'test.source=cmdline'"
52test_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 &&
0e2678af 58 GIT_CONFIG_PARAMETERS=$cmdline_config test-tool config \
e145a0bc
NTND
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
751d3b94
JS
69test_with_config () {
70 rm -rf throwaway &&
71 git init throwaway &&
72 (
73 cd throwaway &&
74 echo "$*" >.git/config &&
0e2678af 75 test-tool config read_early_config early.config
751d3b94
JS
76 )
77}
78
79test_expect_success 'ignore .git/ with incompatible repository version' '
80 test_with_config "[core]repositoryformatversion = 999999" 2>err &&
6789275d 81 test_grep "warning:.* Expected git repo version <= [1-9]" err
751d3b94
JS
82'
83
84test_expect_failure 'ignore .git/ with invalid repository version' '
85 test_with_config "[core]repositoryformatversion = invalid"
86'
87
88
89test_expect_failure 'ignore .git/ with invalid config' '
90 test_with_config "["
91'
92
85fe0e80
JS
93test_expect_success 'early config and onbranch' '
94 echo "[broken" >broken &&
f1beaaef 95 test_with_config "[includeif \"onbranch:topic\"]path=../broken"
85fe0e80
JS
96'
97
22932d91 98test_expect_success 'onbranch config outside of git repo' '
f1beaaef 99 test_config_global includeIf.onbranch:topic.path non-existent &&
22932d91
JK
100 nongit git help
101'
102
1a6ec1eb 103test_done