Skip to content

Commit 1a6ec1e

Browse files
dschogitster
authored andcommitted
t1309: test read_early_config()
So far, we had no explicit tests of that function. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a27409 commit 1a6ec1e

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

t/helper/test-config.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,28 @@ static int iterate_cb(const char *var, const char *value, void *data)
6666
return 0;
6767
}
6868

69+
static int early_config_cb(const char *var, const char *value, void *vdata)
70+
{
71+
const char *key = vdata;
72+
73+
if (!strcmp(key, var))
74+
printf("%s\n", value);
75+
76+
return 0;
77+
}
78+
6979
int cmd_main(int argc, const char **argv)
7080
{
7181
int i, val;
7282
const char *v;
7383
const struct string_list *strptr;
7484
struct config_set cs;
7585

86+
if (argc == 3 && !strcmp(argv[1], "read_early_config")) {
87+
read_early_config(early_config_cb, (void *)argv[2]);
88+
return 0;
89+
}
90+
7691
setup_git_directory();
7792

7893
git_configset_init(&cs);

t/t1309-early-config.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
3+
test_description='Test read_early_config()'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'read early config' '
8+
test_config early.config correct &&
9+
test-config read_early_config early.config >output &&
10+
test correct = "$(cat output)"
11+
'
12+
13+
test_expect_success 'in a sub-directory' '
14+
test_config early.config sub &&
15+
mkdir -p sub &&
16+
(
17+
cd sub &&
18+
test-config read_early_config early.config
19+
) >output &&
20+
test sub = "$(cat output)"
21+
'
22+
23+
test_expect_success 'ceiling' '
24+
test_config early.config ceiling &&
25+
mkdir -p sub &&
26+
(
27+
GIT_CEILING_DIRECTORIES="$PWD" &&
28+
export GIT_CEILING_DIRECTORIES &&
29+
cd sub &&
30+
test-config read_early_config early.config
31+
) >output &&
32+
test -z "$(cat output)"
33+
'
34+
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 &&
40+
(
41+
XDG_CONFIG_HOME="$PWD"/xdg &&
42+
GIT_CEILING_DIRECTORIES="$PWD" &&
43+
export GIT_CEILING_DIRECTORIES XDG_CONFIG_HOME &&
44+
cd sub &&
45+
test-config read_early_config early.config
46+
) >output &&
47+
test xdg = "$(cat output)"
48+
'
49+
50+
test_done

0 commit comments

Comments
 (0)