Add a test for overriding config The repo's configuration should take precedence over the global one. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/tests/resources/config/.gitconfig b/tests/resources/config/.gitconfig
new file mode 100644
index 0000000..8f8075b
--- /dev/null
+++ b/tests/resources/config/.gitconfig
@@ -0,0 +1,2 @@
+[core]
+ repositoryformatversion = 5
diff --git a/tests/resources/testrepo.git/config b/tests/resources/testrepo.git/config
new file mode 100644
index 0000000..2f89580
--- /dev/null
+++ b/tests/resources/testrepo.git/config
@@ -0,0 +1,5 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+ logallrefupdates = true
diff --git a/tests/t15-config.c b/tests/t15-config.c
index c11c5a9..04b2fde 100644
--- a/tests/t15-config.c
+++ b/tests/t15-config.c
@@ -210,6 +210,26 @@ BEGIN_TEST
END_TEST
+BEGIN_TEST(config10, "a repo's config overrides the global config")
+ git_repository *repo;
+ char home_orig[GIT_PATH_MAX];
+ char *home;
+ git_config *cfg;
+ int version;
+
+ home = getenv("HOME");
+ strcpy(home_orig, home);
+ setenv("HOME", CONFIG_BASE, 1);
+
+ must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
+ must_pass(git_repository_config(&cfg, repo));
+ setenv("HOME", home_orig, 1);
+ must_pass(git_config_get_int(cfg, "core.repositoryformatversion", &version));
+ must_be_true(version == 0);
+ git_config_free(cfg);
+ git_repository_free(repo);
+END_TEST
+
BEGIN_SUITE(config)
ADD_TEST(config0);
ADD_TEST(config1);
@@ -221,4 +241,5 @@ BEGIN_SUITE(config)
ADD_TEST(config7);
ADD_TEST(config8);
ADD_TEST(config9);
+ ADD_TEST(config10);
END_SUITE