From e5a27f039ee3ae1291fd5084707c3f9c168f10ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 20 Apr 2013 15:25:39 +0200 Subject: [PATCH] config: allow setting multivars when none exist yet Adding a multivar when there are no variables with that name set should set the variable instead of failing. --- src/config_file.c | 4 +++- tests-clar/config/multivar.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/config_file.c b/src/config_file.c index 8b51ab21b..01559221e 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -481,8 +481,10 @@ static int config_set_multivar( pos = git_strmap_lookup_index(b->values, key); if (!git_strmap_valid_index(b->values, pos)) { + /* If we don't have it, behave like a normal set */ + result = config_set(cfg, name, value); git__free(key); - return GIT_ENOTFOUND; + return result; } var = git_strmap_value_at(b->values, pos); diff --git a/tests-clar/config/multivar.c b/tests-clar/config/multivar.c index 26537e20a..0bda6bcec 100644 --- a/tests-clar/config/multivar.c +++ b/tests-clar/config/multivar.c @@ -97,6 +97,22 @@ void test_config_multivar__add(void) git_config_free(cfg); } +void test_config_multivar__add_new(void) +{ + const char *var = "a.brand.new"; + git_config *cfg; + int n; + + cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); + + cl_git_pass(git_config_set_multivar(cfg, var, "", "variable")); + n = 0; + cl_git_pass(git_config_get_multivar(cfg, var, NULL, cb, &n)); + cl_assert(n == 1); + + git_config_free(cfg); +} + void test_config_multivar__replace(void) { git_config *cfg;