Commit 3de5df7d8e0e35653d49fb6484a4f0cf98af6c88

Carlos Martín Nieto 2011-06-16T19:56:48

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>

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