Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2013-09-06 23:12:26 +0400
committerCarlos Martín Nieto <cmn@dwim.me>2013-09-07 22:51:26 +0400
commit73fc5e01c2ad4af7912201fc938b234a2dc854ac (patch)
tree7ccd668e96d940c3f0f5bb70f424b5834ac5d407 /tests-clar/config
parenta9fb79896e59f4e58cd7d174e7835e8a9c850a33 (diff)
config: fix variable overriding
When two or more variables of the same name exist and the user asks for a scalar, we must return the latest value assign to it.
Diffstat (limited to 'tests-clar/config')
-rw-r--r--tests-clar/config/include.c22
-rw-r--r--tests-clar/config/read.c15
2 files changed, 37 insertions, 0 deletions
diff --git a/tests-clar/config/include.c b/tests-clar/config/include.c
index 94669a57c..f1019a9dc 100644
--- a/tests-clar/config/include.c
+++ b/tests-clar/config/include.c
@@ -71,3 +71,25 @@ void test_config_include__refresh(void)
git_config_free(cfg);
cl_fixture_cleanup("config");
}
+
+/* We need to pretend that the variables were defined where the file was included */
+void test_config_include__ordering(void)
+{
+ git_config *cfg;
+ const char *str;
+
+ cl_git_mkfile("included", "[foo \"bar\"]\nbaz = hurrah\nfrotz = hiya");
+ cl_git_mkfile("including",
+ "[foo \"bar\"]\nfrotz = hello\n"
+ "[include]\npath = included\n"
+ "[foo \"bar\"]\nbaz = huzzah\n");
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "including"));
+
+ cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.frotz"));
+ cl_assert_equal_s(str, "hiya");
+ cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
+ cl_assert_equal_s(str, "huzzah");
+
+ git_config_free(cfg);
+}
diff --git a/tests-clar/config/read.c b/tests-clar/config/read.c
index 395f1cfdb..722a15a71 100644
--- a/tests-clar/config/read.c
+++ b/tests-clar/config/read.c
@@ -523,3 +523,18 @@ void test_config_read__corrupt_header(void)
git_config_free(cfg);
}
+
+void test_config_read__override_variable(void)
+{
+ git_config *cfg;
+ const char *str;
+
+ cl_set_cleanup(&clean_test_config, NULL);
+ cl_git_mkfile("./testconfig", "[some] var = one\nvar = two");
+ cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
+
+ cl_git_pass(git_config_get_string(&str, cfg, "some.var"));
+ cl_assert_equal_s(str, "two");
+
+ git_config_free(cfg);
+}