Commit 4bb6ffb6 by Carlos Martín Nieto

Merge pull request #2622 from libgit2/refresh-config-snapshot

Refresh git configuration before looking for the tracking branch redux.
parents d676af43 ad5adacb
......@@ -767,12 +767,17 @@ static int config_readonly_open(git_config_backend *cfg, git_config_level_t leve
{
diskfile_readonly_backend *b = (diskfile_readonly_backend *) cfg;
diskfile_backend *src = b->snapshot_from;
diskfile_header *src_header = &src->header;
refcounted_strmap *src_map;
int error;
if (!src_header->readonly && (error = config_refresh(&src_header->parent)) < 0)
return error;
/* We're just copying data, don't care about the level */
GIT_UNUSED(level);
src_map = refcounted_strmap_take(&src->header);
src_map = refcounted_strmap_take(src_header);
b->header.values = src_map;
return 0;
......
......@@ -3,7 +3,7 @@
void test_config_snapshot__create_snapshot(void)
{
int32_t tmp;
git_config *cfg, *snapshot;
git_config *cfg, *snapshot, *new_snapshot;
const char *filename = "config-ext-change";
cl_git_mkfile(filename, "[old]\nvalue = 5\n");
......@@ -23,6 +23,19 @@ void test_config_snapshot__create_snapshot(void)
cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value"));
cl_assert_equal_i(5, tmp);
/* Change the value on the file itself (simulate external process) */
cl_git_mkfile(filename, "[old]\nvalue = 999\n");
cl_git_pass(git_config_snapshot(&new_snapshot, cfg));
/* New snapshot should see new value */
cl_git_pass(git_config_get_int32(&tmp, new_snapshot, "old.value"));
cl_assert_equal_i(999, tmp);
/* Old snapshot should still have the old value */
cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value"));
cl_assert_equal_i(5, tmp);
git_config_free(snapshot);
git_config_free(cfg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment