]>
git.proxmox.com Git - libgit2.git/blob - tests/config/snapshot.c
3ea07c11841d327a5c20edc1d743796aeb127849
1 #include "clar_libgit2.h"
3 void test_config_snapshot__create_snapshot(void)
6 git_config
*cfg
, *snapshot
, *new_snapshot
;
7 const char *filename
= "config-ext-change";
9 cl_git_mkfile(filename
, "[old]\nvalue = 5\n");
11 cl_git_pass(git_config_open_ondisk(&cfg
, filename
));
13 cl_git_pass(git_config_get_int32(&tmp
, cfg
, "old.value"));
14 cl_assert_equal_i(5, tmp
);
16 cl_git_pass(git_config_snapshot(&snapshot
, cfg
));
18 /* Change the value on the file itself (simulate external process) */
19 cl_git_mkfile(filename
, "[old]\nvalue = 56\n");
21 cl_git_pass(git_config_get_int32(&tmp
, cfg
, "old.value"));
22 cl_assert_equal_i(56, tmp
);
24 cl_git_pass(git_config_get_int32(&tmp
, snapshot
, "old.value"));
25 cl_assert_equal_i(5, tmp
);
27 /* Change the value on the file itself (simulate external process) */
28 cl_git_mkfile(filename
, "[old]\nvalue = 999\n");
30 cl_git_pass(git_config_snapshot(&new_snapshot
, cfg
));
32 /* New snapshot should see new value */
33 cl_git_pass(git_config_get_int32(&tmp
, new_snapshot
, "old.value"));
34 cl_assert_equal_i(999, tmp
);
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
);
40 git_config_free(new_snapshot
);
41 git_config_free(snapshot
);
45 static int count_me(const git_config_entry
*entry
, void *payload
)
47 int *n
= (int *) payload
;
56 void test_config_snapshot__multivar(void)
59 git_config
*cfg
, *snapshot
;
60 const char *filename
= "config-file";
62 cl_git_mkfile(filename
, "[old]\nvalue = 5\nvalue = 6\n");
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
));
67 cl_assert_equal_i(2, count
);
69 cl_git_pass(git_config_snapshot(&snapshot
, cfg
));
73 cl_git_pass(git_config_get_multivar_foreach(snapshot
, "old.value", NULL
, count_me
, &count
));
75 cl_assert_equal_i(2, count
);
77 git_config_free(snapshot
);