mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 20:42:23 +00:00
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.
This commit is contained in:
parent
8f24e65ff6
commit
e5a27f039e
@ -481,8 +481,10 @@ static int config_set_multivar(
|
|||||||
|
|
||||||
pos = git_strmap_lookup_index(b->values, key);
|
pos = git_strmap_lookup_index(b->values, key);
|
||||||
if (!git_strmap_valid_index(b->values, pos)) {
|
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);
|
git__free(key);
|
||||||
return GIT_ENOTFOUND;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
var = git_strmap_value_at(b->values, pos);
|
var = git_strmap_value_at(b->values, pos);
|
||||||
|
@ -97,6 +97,22 @@ void test_config_multivar__add(void)
|
|||||||
git_config_free(cfg);
|
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)
|
void test_config_multivar__replace(void)
|
||||||
{
|
{
|
||||||
git_config *cfg;
|
git_config *cfg;
|
||||||
|
Loading…
Reference in New Issue
Block a user