Merge branch 'rj/cygwin-has-dev-tty'
[git/gitster.git] / t / t1309-early-config.sh
blob523aa99a1e264661c9af03e450ff14c345831617
1 #!/bin/sh
3 test_description='Test read_early_config()'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
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)"
14 test_expect_success 'in a sub-directory' '
15 test_config early.config sub &&
16 mkdir -p sub &&
18 cd sub &&
19 test-tool config read_early_config early.config
20 ) >output &&
21 test sub = "$(cat output)"
24 test_expect_success 'ceiling' '
25 test_config early.config ceiling &&
26 mkdir -p sub &&
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
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 &&
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)"
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 &&
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
69 test_with_config () {
70 rm -rf throwaway &&
71 git init throwaway &&
73 cd throwaway &&
74 echo "$*" >.git/config &&
75 test-tool config read_early_config early.config
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
84 test_expect_failure 'ignore .git/ with invalid repository version' '
85 test_with_config "[core]repositoryformatversion = invalid"
89 test_expect_failure 'ignore .git/ with invalid config' '
90 test_with_config "["
93 test_expect_success 'early config and onbranch' '
94 echo "[broken" >broken &&
95 test_with_config "[includeif \"onbranch:topic\"]path=../broken"
98 test_expect_success 'onbranch config outside of git repo' '
99 test_config_global includeIf.onbranch:topic.path non-existent &&
100 nongit git help
103 test_done