diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-13 17:11:34 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-04-18 16:03:01 +0200 |
commit | 55ebd7d369a789f27fe1ad6b8ec8965aa1335d08 (patch) | |
tree | 16ec80013850add231a1c01bdc3de6e93f17cbaa /tests | |
parent | 36913b8cb497487728ee9bab383d4c1205685927 (diff) | |
download | libgit2-55ebd7d369a789f27fe1ad6b8ec8965aa1335d08.tar.gz |
config: implement config snapshotting
In order to have consistent views of the config files for remotes,
submodules et al. and a configuration that represents what is currently
stored on-disk, we need a way to provide a view of the configuration
that does not change.
The goal here is to provide the snapshotting part by creating a
read-only copy of the state of the configuration at a particular point
in time, which does not change when a repository's main config changes.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/config/snapshot.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/config/snapshot.c b/tests/config/snapshot.c new file mode 100644 index 000000000..a9d3eadd3 --- /dev/null +++ b/tests/config/snapshot.c @@ -0,0 +1,69 @@ +#include "clar_libgit2.h" + +void test_config_snapshot__create_snapshot(void) +{ + int32_t tmp; + git_config *cfg, *snapshot; + const char *filename = "config-ext-change"; + + cl_git_mkfile(filename, "[old]\nvalue = 5\n"); + + cl_git_pass(git_config_open_ondisk(&cfg, filename)); + + cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value")); + cl_assert_equal_i(5, tmp); + + cl_git_pass(git_config_snapshot(&snapshot, cfg)); + + /* Change the value on the file itself (simulate external process) */ + cl_git_mkfile(filename, "[old]\nvalue = 56\n"); + + cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value")); + cl_assert_equal_i(5, tmp); + + cl_git_pass(git_config_refresh(cfg)); + + cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value")); + cl_assert_equal_i(56, tmp); + + 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); +} + +static int count_me(const git_config_entry *entry, void *payload) +{ + int *n = (int *) payload; + + GIT_UNUSED(entry); + + (*n)++; + + return 0; +} + +void test_config_snapshot__multivar(void) +{ + int count = 0; + git_config *cfg, *snapshot; + const char *filename = "config-file"; + + cl_git_mkfile(filename, "[old]\nvalue = 5\nvalue = 6\n"); + + cl_git_pass(git_config_open_ondisk(&cfg, filename)); + cl_git_pass(git_config_get_multivar_foreach(cfg, "old.value", NULL, count_me, &count)); + + cl_assert_equal_i(2, count); + + cl_git_pass(git_config_snapshot(&snapshot, cfg)); + git_config_free(cfg); + + count = 0; + cl_git_pass(git_config_get_multivar_foreach(snapshot, "old.value", NULL, count_me, &count)); + + cl_assert_equal_i(2, count); + + git_config_free(snapshot); +} |