]> git.proxmox.com Git - libgit2.git/blame - tests/config/snapshot.c
rebase: correctly finish rebasing detached heads
[libgit2.git] / tests / config / snapshot.c
CommitLineData
55ebd7d3
CMN
1#include "clar_libgit2.h"
2
3void test_config_snapshot__create_snapshot(void)
4{
5 int32_t tmp;
5490c9d4 6 git_config *cfg, *snapshot, *new_snapshot;
55ebd7d3
CMN
7 const char *filename = "config-ext-change";
8
9 cl_git_mkfile(filename, "[old]\nvalue = 5\n");
10
11 cl_git_pass(git_config_open_ondisk(&cfg, filename));
12
13 cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
14 cl_assert_equal_i(5, tmp);
15
16 cl_git_pass(git_config_snapshot(&snapshot, cfg));
17
18 /* Change the value on the file itself (simulate external process) */
19 cl_git_mkfile(filename, "[old]\nvalue = 56\n");
20
55ebd7d3
CMN
21 cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
22 cl_assert_equal_i(56, tmp);
23
24 cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value"));
25 cl_assert_equal_i(5, tmp);
5490c9d4
AR
26
27 /* Change the value on the file itself (simulate external process) */
1e2fe921 28 cl_git_mkfile(filename, "[old]\nvalue = 999\n");
5490c9d4
AR
29
30 cl_git_pass(git_config_snapshot(&new_snapshot, cfg));
31
32 /* New snapshot should see new value */
33 cl_git_pass(git_config_get_int32(&tmp, new_snapshot, "old.value"));
1e2fe921 34 cl_assert_equal_i(999, tmp);
5490c9d4
AR
35
36 /* Old snapshot should still have the old value */
37 cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value"));
38 cl_assert_equal_i(5, tmp);
55ebd7d3 39
90aa2bf3 40 git_config_free(new_snapshot);
55ebd7d3
CMN
41 git_config_free(snapshot);
42 git_config_free(cfg);
43}
44
45static int count_me(const git_config_entry *entry, void *payload)
46{
47 int *n = (int *) payload;
48
49 GIT_UNUSED(entry);
50
51 (*n)++;
52
53 return 0;
54}
55
56void test_config_snapshot__multivar(void)
57{
58 int count = 0;
59 git_config *cfg, *snapshot;
60 const char *filename = "config-file";
61
62 cl_git_mkfile(filename, "[old]\nvalue = 5\nvalue = 6\n");
63
64 cl_git_pass(git_config_open_ondisk(&cfg, filename));
65 cl_git_pass(git_config_get_multivar_foreach(cfg, "old.value", NULL, count_me, &count));
66
67 cl_assert_equal_i(2, count);
68
69 cl_git_pass(git_config_snapshot(&snapshot, cfg));
70 git_config_free(cfg);
71
72 count = 0;
73 cl_git_pass(git_config_get_multivar_foreach(snapshot, "old.value", NULL, count_me, &count));
74
75 cl_assert_equal_i(2, count);
76
77 git_config_free(snapshot);
78}