t7503: add tests for pre-merge-hook
[git/mjg.git] / t / t1309-early-config.sh
blob3a0de0ddaa553e82b7db8594f4c45489237fb7db
1 #!/bin/sh
3 test_description='Test read_early_config()'
5 . ./test-lib.sh
7 test_expect_success 'read early config' '
8 test_config early.config correct &&
9 test-tool config read_early_config early.config >output &&
10 test correct = "$(cat output)"
13 test_expect_success 'in a sub-directory' '
14 test_config early.config sub &&
15 mkdir -p sub &&
17 cd sub &&
18 test-tool config read_early_config early.config
19 ) >output &&
20 test sub = "$(cat output)"
23 test_expect_success 'ceiling' '
24 test_config early.config ceiling &&
25 mkdir -p sub &&
27 GIT_CEILING_DIRECTORIES="$PWD" &&
28 export GIT_CEILING_DIRECTORIES &&
29 cd sub &&
30 test-tool config read_early_config early.config
31 ) >output &&
32 test -z "$(cat output)"
35 test_expect_success 'ceiling #2' '
36 mkdir -p xdg/git &&
37 git config -f xdg/git/config early.config xdg &&
38 test_config early.config ceiling &&
39 mkdir -p sub &&
41 XDG_CONFIG_HOME="$PWD"/xdg &&
42 GIT_CEILING_DIRECTORIES="$PWD" &&
43 export GIT_CEILING_DIRECTORIES XDG_CONFIG_HOME &&
44 cd sub &&
45 test-tool config read_early_config early.config
46 ) >output &&
47 test xdg = "$(cat output)"
50 cmdline_config="'test.source=cmdline'"
51 test_expect_success 'read config file in right order' '
52 echo "[test]source = home" >>.gitconfig &&
53 git init foo &&
55 cd foo &&
56 echo "[test]source = repo" >>.git/config &&
57 GIT_CONFIG_PARAMETERS=$cmdline_config test-tool config \
58 read_early_config test.source >actual &&
59 cat >expected <<-\EOF &&
60 home
61 repo
62 cmdline
63 EOF
64 test_cmp expected actual
68 test_with_config () {
69 rm -rf throwaway &&
70 git init throwaway &&
72 cd throwaway &&
73 echo "$*" >.git/config &&
74 test-tool config read_early_config early.config
78 test_expect_success 'ignore .git/ with incompatible repository version' '
79 test_with_config "[core]repositoryformatversion = 999999" 2>err &&
80 test_i18ngrep "warning:.* Expected git repo version <= [1-9]" err
83 test_expect_failure 'ignore .git/ with invalid repository version' '
84 test_with_config "[core]repositoryformatversion = invalid"
88 test_expect_failure 'ignore .git/ with invalid config' '
89 test_with_config "["
92 test_expect_success 'early config and onbranch' '
93 echo "[broken" >broken &&
94 test_with_config "[includeif \"onbranch:master\"]path=../broken"
97 test_expect_success 'onbranch config outside of git repo' '
98 test_config_global includeIf.onbranch:master.path non-existent &&
99 nongit git help
102 test_done