summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-12-21 15:31:03 +0000
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-03 18:35:12 +0100
commit9a97f49e3aa15edc479fc590f4b28fc44c155c40 (patch)
treeb85de2d396b9d0d408f688212c0cdc74347ea7b3 /tests
parent76f034180aee96fcc1fffd5267ccbc6ada68482a (diff)
downloadlibgit2-cmn/config-borrow-entry.tar.gz
config: borrow refcounted referencescmn/config-borrow-entry
This changes the get_entry() method to return a refcounted version of the config entry, which you have to free when you're done. This allows us to avoid freeing the memory in which the entry is stored on a refresh, which may happen at any time for a live config. For this reason, get_string() has been forbidden on live configs and a new function get_string_buf() has been added, which stores the string in a git_buf which the user then owns. The functions which parse the string value takea advantage of the borrowing to parse safely and then release the entry.
Diffstat (limited to 'tests')
-rw-r--r--tests/clone/nonetwork.c2
-rw-r--r--tests/config/config_helpers.c13
-rw-r--r--tests/config/configlevel.c14
-rw-r--r--tests/config/global.c8
-rw-r--r--tests/config/include.c50
-rw-r--r--tests/config/new.c12
-rw-r--r--tests/config/read.c78
-rw-r--r--tests/config/rename.c8
-rw-r--r--tests/config/stress.c58
-rw-r--r--tests/config/validkeyname.c5
-rw-r--r--tests/config/write.c63
-rw-r--r--tests/network/remote/remotes.c16
-rw-r--r--tests/refs/branches/move.c48
-rw-r--r--tests/refs/branches/upstream.c25
-rw-r--r--tests/repo/init.c15
-rw-r--r--tests/repo/setters.c8
-rw-r--r--tests/submodule/add.c15
-rw-r--r--tests/submodule/init.c12
-rw-r--r--tests/submodule/modify.c17
-rw-r--r--tests/submodule/repository_init.c8
20 files changed, 235 insertions, 240 deletions
diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c
index 46b36ed92..2a3157739 100644
--- a/tests/clone/nonetwork.c
+++ b/tests/clone/nonetwork.c
@@ -291,7 +291,7 @@ void test_clone_nonetwork__clone_from_empty_sets_upstream(void)
cl_set_cleanup(&cleanup_repository, "./repowithunborn");
cl_git_pass(git_clone(&repo, "./test1", "./repowithunborn", NULL));
- cl_git_pass(git_repository_config(&config, repo));
+ cl_git_pass(git_repository_config_snapshot(&config, repo));
cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
cl_assert_equal_s("origin", str);
diff --git a/tests/config/config_helpers.c b/tests/config/config_helpers.c
index 35da720e0..025838ad7 100644
--- a/tests/config/config_helpers.c
+++ b/tests/config/config_helpers.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "config_helpers.h"
#include "repository.h"
+#include "buffer.h"
void assert_config_entry_existence(
git_repository *repo,
@@ -8,12 +9,13 @@ void assert_config_entry_existence(
bool is_supposed_to_exist)
{
git_config *config;
- const char *out;
+ git_config_entry *entry = NULL;
int result;
cl_git_pass(git_repository_config__weakptr(&config, repo));
- result = git_config_get_string(&out, config, name);
+ result = git_config_get_entry(&entry, config, name);
+ git_config_entry_free(entry);
if (is_supposed_to_exist)
cl_git_pass(result);
@@ -27,13 +29,14 @@ void assert_config_entry_value(
const char *expected_value)
{
git_config *config;
- const char *out;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_repository_config__weakptr(&config, repo));
- cl_git_pass(git_config_get_string(&out, config, name));
+ cl_git_pass(git_config_get_string_buf(&buf, config, name));
- cl_assert_equal_s(expected_value, out);
+ cl_assert_equal_s(expected_value, git_buf_cstr(&buf));
+ git_buf_free(&buf);
}
static int count_config_entries_cb(
diff --git a/tests/config/configlevel.c b/tests/config/configlevel.c
index 1c22e8d9f..ca478b1a5 100644
--- a/tests/config/configlevel.c
+++ b/tests/config/configlevel.c
@@ -22,7 +22,7 @@ void test_config_configlevel__adding_the_same_level_twice_returns_EEXISTS(void)
void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(void)
{
git_config *cfg;
- const char *s;
+ git_buf buf = {0};
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
@@ -30,9 +30,10 @@ void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(voi
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
GIT_CONFIG_LEVEL_LOCAL, 1));
- cl_git_pass(git_config_get_string(&s, cfg, "core.stringglobal"));
- cl_assert_equal_s("don't find me!", s);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
+ cl_assert_equal_s("don't find me!", buf.ptr);
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -40,7 +41,7 @@ void test_config_configlevel__can_read_from_a_single_level_focused_file_after_pa
{
git_config *cfg;
git_config *single_level_cfg;
- const char *s;
+ git_buf buf = {0};
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
@@ -52,9 +53,10 @@ void test_config_configlevel__can_read_from_a_single_level_focused_file_after_pa
git_config_free(cfg);
- cl_git_pass(git_config_get_string(&s, single_level_cfg, "core.stringglobal"));
- cl_assert_equal_s("don't find me!", s);
+ cl_git_pass(git_config_get_string_buf(&buf, single_level_cfg, "core.stringglobal"));
+ cl_assert_equal_s("don't find me!", buf.ptr);
+ git_buf_free(&buf);
git_config_free(single_level_cfg);
}
diff --git a/tests/config/global.c b/tests/config/global.c
index fc471f90d..4481308d6 100644
--- a/tests/config/global.c
+++ b/tests/config/global.c
@@ -46,8 +46,9 @@ void test_config_global__open_global(void)
void test_config_global__open_xdg(void)
{
git_config *cfg, *xdg, *selected;
- const char *val, *str = "teststring";
+ const char *str = "teststring";
const char *key = "this.variable";
+ git_buf buf = {0};
cl_git_mkfile("xdg/git/config", "# XDG config\n[core]\n test = 1\n");
@@ -56,9 +57,10 @@ void test_config_global__open_xdg(void)
cl_git_pass(git_config_open_global(&selected, cfg));
cl_git_pass(git_config_set_string(xdg, key, str));
- cl_git_pass(git_config_get_string(&val, selected, key));
- cl_assert_equal_s(str, val);
+ cl_git_pass(git_config_get_string_buf(&buf, selected, key));
+ cl_assert_equal_s(str, buf.ptr);
+ git_buf_free(&buf);
git_config_free(selected);
git_config_free(xdg);
git_config_free(cfg);
diff --git a/tests/config/include.c b/tests/config/include.c
index 8232af489..e9f542afe 100644
--- a/tests/config/include.c
+++ b/tests/config/include.c
@@ -5,20 +5,20 @@
void test_config_include__relative(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include")));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
void test_config_include__absolute(void)
{
git_config *cfg;
- const char *str;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_buf_printf(&buf, "[include]\npath = %s/config-included", cl_fixture("config")));
@@ -27,25 +27,27 @@ void test_config_include__absolute(void)
git_buf_free(&buf);
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-absolute"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
void test_config_include__homedir(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config")));
cl_git_mkfile("config-include-homedir", "[include]\npath = ~/config-included");
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
cl_sandbox_set_search_path_defaults();
@@ -55,7 +57,7 @@ void test_config_include__homedir(void)
void test_config_include__ordering(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_mkfile("included", "[foo \"bar\"]\nbaz = hurrah\nfrotz = hiya");
cl_git_mkfile("including",
@@ -65,11 +67,13 @@ void test_config_include__ordering(void)
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.frotz"));
- cl_assert_equal_s(str, "hiya");
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
- cl_assert_equal_s(str, "huzzah");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.frotz"));
+ cl_assert_equal_s("hiya", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
+ cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -90,16 +94,17 @@ void test_config_include__depth(void)
void test_config_include__missing(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_mkfile("including", "[include]\npath = nonexistentfile\n[foo]\nbar = baz");
giterr_clear();
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(giterr_last() == NULL);
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar"));
- cl_assert_equal_s(str, "baz");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
+ cl_assert_equal_s("baz", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -107,7 +112,7 @@ void test_config_include__missing(void)
void test_config_include__depth2(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
const char *content = "[include]\n" replicate10(replicate10("path=bottom\n"));
cl_git_mkfile("top-level", "[include]\npath = middle\n[foo]\nbar = baz");
@@ -116,11 +121,12 @@ void test_config_include__depth2(void)
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar"));
- cl_assert_equal_s(str, "baz");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
+ cl_assert_equal_s("baz", git_buf_cstr(&buf));
- cl_git_pass(git_config_get_string(&str, cfg, "foo.bar2"));
- cl_assert_equal_s(str, "baz2");
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar2"));
+ cl_assert_equal_s("baz2", git_buf_cstr(&buf));
git_config_free(cfg);
}
diff --git a/tests/config/new.c b/tests/config/new.c
index dd6dbca9e..b39baa0a5 100644
--- a/tests/config/new.c
+++ b/tests/config/new.c
@@ -8,8 +8,8 @@
void test_config_new__write_new_config(void)
{
- const char *out;
git_config *config;
+ git_buf buf = GIT_BUF_INIT;
cl_git_mkfile(TEST_CONFIG, "");
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
@@ -21,11 +21,13 @@ void test_config_new__write_new_config(void)
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&out, config, "color.ui"));
- cl_assert_equal_s(out, "auto");
- cl_git_pass(git_config_get_string(&out, config, "core.editor"));
- cl_assert_equal_s(out, "ed");
+ cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
+ cl_assert_equal_s("auto", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
+ cl_assert_equal_s("ed", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(config);
p_unlink(TEST_CONFIG);
diff --git a/tests/config/read.c b/tests/config/read.c
index 1799970fb..a7b77159e 100644
--- a/tests/config/read.c
+++ b/tests/config/read.c
@@ -2,6 +2,13 @@
#include "buffer.h"
#include "path.h"
+static git_buf buf = GIT_BUF_INIT;
+
+void test_config_read__cleanup(void)
+{
+ git_buf_free(&buf);
+}
+
void test_config_read__simple_read(void)
{
git_config *cfg;
@@ -25,14 +32,15 @@ void test_config_read__case_sensitive(void)
{
git_config *cfg;
int i;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config1")));
- cl_git_pass(git_config_get_string(&str, cfg, "this.that.other"));
- cl_assert_equal_s(str, "true");
- cl_git_pass(git_config_get_string(&str, cfg, "this.That.other"));
- cl_assert_equal_s(str, "yes");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.that.other"));
+ cl_assert_equal_s("true", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
+
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.other"));
+ cl_assert_equal_s("yes", git_buf_cstr(&buf));
cl_git_pass(git_config_get_bool(&i, cfg, "this.that.other"));
cl_assert(i == 1);
@@ -52,12 +60,11 @@ void test_config_read__case_sensitive(void)
void test_config_read__multiline_value(void)
{
git_config *cfg;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2")));
- cl_git_pass(git_config_get_string(&str, cfg, "this.That.and"));
- cl_assert_equal_s(str, "one one one two two three three");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.and"));
+ cl_assert_equal_s("one one one two two three three", git_buf_cstr(&buf));
git_config_free(cfg);
}
@@ -68,15 +75,14 @@ void test_config_read__multiline_value(void)
void test_config_read__subsection_header(void)
{
git_config *cfg;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config3")));
- cl_git_pass(git_config_get_string(&str, cfg, "section.subsection.var"));
- cl_assert_equal_s(str, "hello");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "section.subsection.var"));
+ cl_assert_equal_s("hello", git_buf_cstr(&buf));
/* The subsection is transformed to lower-case */
- cl_must_fail(git_config_get_string(&str, cfg, "section.subSectIon.var"));
+ cl_must_fail(git_config_get_string_buf(&buf, cfg, "section.subSectIon.var"));
git_config_free(cfg);
}
@@ -84,21 +90,21 @@ void test_config_read__subsection_header(void)
void test_config_read__lone_variable(void)
{
git_config *cfg;
- const char *str;
int i;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config4")));
cl_git_fail(git_config_get_int32(&i, cfg, "some.section.variable"));
- cl_git_pass(git_config_get_string(&str, cfg, "some.section.variable"));
- cl_assert_equal_s(str, "");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variable"));
+ cl_assert_equal_s("", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
cl_assert(i == 1);
- cl_git_pass(git_config_get_string(&str, cfg, "some.section.variableeq"));
- cl_assert_equal_s(str, "");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variableeq"));
+ cl_assert_equal_s("", git_buf_cstr(&buf));
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variableeq"));
cl_assert(i == 0);
@@ -184,14 +190,14 @@ void test_config_read__header_in_last_line(void)
void test_config_read__prefixes(void)
{
git_config *cfg;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
- cl_git_pass(git_config_get_string(&str, cfg, "remote.ab.url"));
- cl_assert_equal_s(str, "http://example.com/git/ab");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.ab.url"));
+ cl_assert_equal_s("http://example.com/git/ab", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
- cl_git_pass(git_config_get_string(&str, cfg, "remote.abba.url"));
- cl_assert_equal_s(str, "http://example.com/git/abba");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.abba.url"));
+ cl_assert_equal_s("http://example.com/git/abba", git_buf_cstr(&buf));
git_config_free(cfg);
}
@@ -199,11 +205,10 @@ void test_config_read__prefixes(void)
void test_config_read__escaping_quotes(void)
{
git_config *cfg;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13")));
- cl_git_pass(git_config_get_string(&str, cfg, "core.editor"));
- cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", str);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.editor"));
+ cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", git_buf_cstr(&buf));
git_config_free(cfg);
}
@@ -363,15 +368,15 @@ void test_config_read__iterator_glob(void)
void test_config_read__whitespace_not_required_around_assignment(void)
{
git_config *cfg;
- const char *str;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config14")));
- cl_git_pass(git_config_get_string(&str, cfg, "a.b"));
- cl_assert_equal_s(str, "c");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "a.b"));
+ cl_assert_equal_s("c", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
- cl_git_pass(git_config_get_string(&str, cfg, "d.e"));
- cl_assert_equal_s(str, "f");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "d.e"));
+ cl_assert_equal_s("f", git_buf_cstr(&buf));
git_config_free(cfg);
}
@@ -379,7 +384,7 @@ void test_config_read__whitespace_not_required_around_assignment(void)
void test_config_read__read_git_config_entry(void)
{
git_config *cfg;
- const git_config_entry *entry;
+ git_config_entry *entry;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
@@ -390,6 +395,7 @@ void test_config_read__read_git_config_entry(void)
cl_assert_equal_s("42", entry->value);
cl_assert_equal_i(GIT_CONFIG_LEVEL_SYSTEM, entry->level);
+ git_config_entry_free(entry);
git_config_free(cfg);
}
@@ -480,7 +486,6 @@ void test_config_read__simple_read_from_specific_level(void)
git_config *cfg, *cfg_specific;
int i;
int64_t l, expected = +9223372036854775803;
- const char *s;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
@@ -496,8 +501,8 @@ void test_config_read__simple_read_from_specific_level(void)
cl_assert(l == expected);
cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal"));
cl_assert_equal_b(true, i);
- cl_git_pass(git_config_get_string(&s, cfg_specific, "core.stringglobal"));
- cl_assert_equal_s("I'm a global config value!", s);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg_specific, "core.stringglobal"));
+ cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
git_config_free(cfg_specific);
git_config_free(cfg);
@@ -558,14 +563,13 @@ void test_config_read__corrupt_header3(void)
void test_config_read__override_variable(void)
{
git_config *cfg;
- const char *str;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[some] var = one\nvar = two");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
- cl_git_pass(git_config_get_string(&str, cfg, "some.var"));
- cl_assert_equal_s(str, "two");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
+ cl_assert_equal_s("two", git_buf_cstr(&buf));
git_config_free(cfg);
}
diff --git a/tests/config/rename.c b/tests/config/rename.c
index db07c798f..a4614158a 100644
--- a/tests/config/rename.c
+++ b/tests/config/rename.c
@@ -21,11 +21,12 @@ void test_config_rename__cleanup(void)
void test_config_rename__can_rename(void)
{
- const git_config_entry *ce;
+ git_config_entry *ce;
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.track-local.remote"));
cl_assert_equal_s(".", ce->value);
+ git_config_entry_free(ce);
cl_git_fail(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
@@ -36,6 +37,7 @@ void test_config_rename__can_rename(void)
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s(".", ce->value);
+ git_config_entry_free(ce);
cl_git_fail(git_config_get_entry(
&ce, g_config, "branch.track-local.remote"));
@@ -43,7 +45,7 @@ void test_config_rename__can_rename(void)
void test_config_rename__prevent_overwrite(void)
{
- const git_config_entry *ce;
+ git_config_entry *ce;
cl_git_pass(git_config_set_string(
g_config, "branch.local-track.remote", "yellow"));
@@ -51,6 +53,7 @@ void test_config_rename__prevent_overwrite(void)
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s("yellow", ce->value);
+ git_config_entry_free(ce);
cl_git_pass(git_config_rename_section(
g_repo, "branch.track-local", "branch.local-track"));
@@ -58,6 +61,7 @@ void test_config_rename__prevent_overwrite(void)
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s(".", ce->value);
+ git_config_entry_free(ce);
/* so, we don't currently prevent overwrite... */
/* {
diff --git a/tests/config/stress.c b/tests/config/stress.c
index e8e9d2b61..503f44f03 100644
--- a/tests/config/stress.c
+++ b/tests/config/stress.c
@@ -6,6 +6,8 @@
#define TEST_CONFIG "git-test-config"
+static git_buf buf = GIT_BUF_INIT;
+
void test_config_stress__initialize(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
@@ -20,50 +22,43 @@ void test_config_stress__initialize(void)
void test_config_stress__cleanup(void)
{
+ git_buf_free(&buf);
p_unlink(TEST_CONFIG);
}
void test_config_stress__dont_break_on_invalid_input(void)
{
- const char *editor, *color;
git_config *config;
cl_assert(git_path_exists(TEST_CONFIG));
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&color, config, "color.ui"));
- cl_git_pass(git_config_get_string(&editor, config, "core.editor"));
+ cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
+ cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
git_config_free(config);
}
+void assert_config_value(git_config *config, const char *key, const char *value)
+{
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, config, key));
+ cl_assert_equal_s(value, git_buf_cstr(&buf));
+}
+
void test_config_stress__comments(void)
{
git_config *config;
- const char *str;
cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12")));
- cl_git_pass(git_config_get_string(&str, config, "some.section.test2"));
- cl_assert_equal_s("hello", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.test3"));
- cl_assert_equal_s("welcome", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.other"));
- cl_assert_equal_s("hello! \" ; ; ; ", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.other2"));
- cl_assert_equal_s("cool! \" # # # ", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.multi"));
- cl_assert_equal_s("hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.multi2"));
- cl_assert_equal_s("good, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.back"));
- cl_assert_equal_s("this is \ba phrase", str);
+ assert_config_value(config, "some.section.test2", "hello");
+ assert_config_value(config, "some.section.test3", "welcome");
+ assert_config_value(config, "some.section.other", "hello! \" ; ; ; ");
+ assert_config_value(config, "some.section.other2", "cool! \" # # # ");
+ assert_config_value(config, "some.section.multi", "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
+ assert_config_value(config, "some.section.multi2", "good, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
+ assert_config_value(config, "some.section.back", "this is \ba phrase");
git_config_free(config);
}
@@ -71,7 +66,6 @@ void test_config_stress__comments(void)
void test_config_stress__escape_subsection_names(void)
{
git_config *config;
- const char *str;
cl_assert(git_path_exists("git-test-config"));
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
@@ -81,15 +75,14 @@ void test_config_stress__escape_subsection_names(void)
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&str, config, "some.sec\\tion.other"));
- cl_assert_equal_s("foo", str);
+ assert_config_value(config, "some.sec\\tion.other", "foo");
+
git_config_free(config);
}
void test_config_stress__trailing_backslash(void)
{
git_config *config;
- const char *str;
const char *path = "C:\\iam\\some\\windows\\path\\";
cl_assert(git_path_exists("git-test-config"));
@@ -98,20 +91,19 @@ void test_config_stress__trailing_backslash(void)
git_config_free(config);
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&str, config, "windows.path"));
- cl_assert_equal_s(path, str);
+ assert_config_value(config, "windows.path", path);
+
git_config_free(config);
}
void test_config_stress__complex(void)
{
git_config *config;
- const char *str;
const char *path = "./config-immediate-multiline";
cl_git_mkfile(path, "[imm]\n multi = \"\\\nfoo\"");
cl_git_pass(git_config_open_ondisk(&config, path));
- cl_git_pass(git_config_get_string(&str, config, "imm.multi"));
- cl_assert_equal_s(str, "foo");
+ assert_config_value(config, "imm.multi", "foo");
+
git_config_free(config);
}
diff --git a/tests/config/validkeyname.c b/tests/config/validkeyname.c
index 0ef4a9ae3..4b36509af 100644
--- a/tests/config/validkeyname.c
+++ b/tests/config/validkeyname.c
@@ -3,7 +3,6 @@
#include "config.h"
static git_config *cfg;
-static const char *value;
void test_config_validkeyname__initialize(void)
{
@@ -22,7 +21,9 @@ void test_config_validkeyname__cleanup(void)
static void assert_invalid_config_key_name(const char *name)
{
- cl_git_fail_with(git_config_get_string(&value, cfg, name),
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_fail_with(git_config_get_string_buf(&buf, cfg, name),
GIT_EINVALIDSPEC);
cl_git_fail_with(git_config_set_string(cfg, name, "42"),
GIT_EINVALIDSPEC);
diff --git a/tests/config/write.c b/tests/config/write.c
index 067b7445b..32e6f27b4 100644
--- a/tests/config/write.c
+++ b/tests/config/write.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "buffer.h"
void test_config_write__initialize(void)
{
@@ -108,15 +109,17 @@ void test_config_write__delete_value_at_specific_level(void)
void test_config_write__write_subsection(void)
{
git_config *cfg;
- const char *str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "my.own.var", "works"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_string(&str, cfg, "my.own.var"));
- cl_assert_equal_s("works", str);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "my.own.var"));
+ cl_assert_equal_s("works", git_buf_cstr(&buf));
+
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -132,46 +135,52 @@ void test_config_write__delete_inexistent(void)
void test_config_write__value_containing_quotes(void)
{
git_config *cfg;
- const char* str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this \"has\" quotes");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this \"has\" quotes");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
git_config_free(cfg);
/* The code path for values that already exist is different, check that one as well */
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this also \"has\" quotes"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this also \"has\" quotes");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this also \"has\" quotes");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
void test_config_write__escape_value(void)
{
git_config *cfg;
- const char* str;
+ git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes and \t"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this \"has\" quotes and \t");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this \"has\" quotes and \t", git_buf_cstr(&buf));
+ git_buf_clear(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
- cl_git_pass(git_config_get_string(&str, cfg, "core.somevar"));
- cl_assert_equal_s(str, "this \"has\" quotes and \t");
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
+ cl_assert_equal_s("this \"has\" quotes and \t", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -180,7 +189,7 @@ void test_config_write__add_value_at_specific_level(void)
git_config *cfg, *cfg_specific;
int i;
int64_t l, expected = +9223372036854775803;
- const char *s;
+ git_buf buf = GIT_BUF_INIT;
// open config15 as global level config file
cl_git_pass(git_config_new(&cfg));
@@ -207,9 +216,10 @@ void test_config_write__add_value_at_specific_level(void)
cl_assert(l == expected);
cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal"));
cl_assert_equal_b(true, i);
- cl_git_pass(git_config_get_string(&s, cfg, "core.stringglobal"));
- cl_assert_equal_s("I'm a global config value!", s);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
+ cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
+ git_buf_free(&buf);
git_config_free(cfg);
}
@@ -247,7 +257,7 @@ void test_config_write__add_section_at_file_with_no_clrf_at_the_end(void)
void test_config_write__add_value_which_needs_quotes(void)
{
- git_config *cfg;
+ git_config *cfg, *base;
const char* str1;
const char* str2;
const char* str3;
@@ -262,7 +272,8 @@ void test_config_write__add_value_which_needs_quotes(void)
cl_git_pass(git_config_set_string(cfg, "core.startwhithsapceandcontainsdoublequote", " some\"thing"));
git_config_free(cfg);
- cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
+ cl_git_pass(git_config_open_ondisk(&base, "config17"));
+ cl_git_pass(git_config_snapshot(&cfg, base));
cl_git_pass(git_config_get_string(&str1, cfg, "core.startwithspace"));
cl_assert_equal_s(" Something", str1);
cl_git_pass(git_config_get_string(&str2, cfg, "core.endwithspace"));
@@ -274,6 +285,7 @@ void test_config_write__add_value_which_needs_quotes(void)
cl_git_pass(git_config_get_string(&str5, cfg, "core.startwhithsapceandcontainsdoublequote"));
cl_assert_equal_s(" some\"thing", str5);
git_config_free(cfg);
+ git_config_free(base);
}
void test_config_write__can_set_a_value_to_NULL(void)
@@ -294,15 +306,16 @@ void test_config_write__can_set_an_empty_value(void)
{
git_repository *repository;
git_config *config;
- const char * str;
+ git_buf buf = {0};
repository = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_config(&config, repository));
cl_git_pass(git_config_set_string(config, "core.somevar", ""));
- cl_git_pass(git_config_get_string(&str, config, "core.somevar"));
- cl_assert_equal_s(str, "");
+ cl_git_pass(git_config_get_string_buf(&buf, config, "core.somevar"));
+ cl_assert_equal_s("", buf.ptr);
+ git_buf_free(&buf);
git_config_free(config);
cl_git_sandbox_cleanup();
}
diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c
index 2ae6886bd..e750f7b1e 100644
--- a/tests/network/remote/remotes.c
+++ b/tests/network/remote/remotes.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "config/config_helpers.h"
#include "buffer.h"
#include "refspec.h"
#include "remote.h"
@@ -385,26 +386,17 @@ void test_network_remote_remotes__cannot_add_a_remote_with_an_invalid_name(void)
void test_network_remote_remotes__tagopt(void)
{
- const char *opt;
- git_config *cfg;
-
- cl_git_pass(git_repository_config(&cfg, _repo));
-
git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
cl_git_pass(git_remote_save(_remote));
- cl_git_pass(git_config_get_string(&opt, cfg, "remote.test.tagopt"));
- cl_assert_equal_s("--tags", opt);
+ assert_config_entry_value(_repo, "remote.test.tagopt", "--tags");
git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_NONE);
cl_git_pass(git_remote_save(_remote));
- cl_git_pass(git_config_get_string(&opt, cfg, "remote.test.tagopt"));
- cl_assert_equal_s("--no-tags", opt);
+ assert_config_entry_value(_repo, "remote.test.tagopt", "--no-tags");
git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
cl_git_pass(git_remote_save(_remote));
- cl_assert(git_config_get_string(&opt, cfg, "remote.test.tagopt") == GIT_ENOTFOUND);
-
- git_config_free(cfg);
+ assert_config_entry_existence(_repo, "remote.test.tagopt", false);
}
void test_network_remote_remotes__can_load_with_an_empty_url(void)
diff --git a/tests/refs/branches/move.c b/tests/refs/branches/move.c
index c1d1ae396..6e335d1fa 100644
--- a/tests/refs/branches/move.c
+++ b/tests/refs/branches/move.c
@@ -67,16 +67,17 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
{
git_reference *original_ref, *new_ref;
git_config *config;
- const git_config_entry *ce;
+ git_buf buf = GIT_BUF_INIT;
char *original_remote, *original_merge;
+ const char *str;
- cl_git_pass(git_repository_config(&config, repo));
-
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.remote"));
- original_remote = strdup(ce->value);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.merge"));
- original_merge = strdup(ce->value);
+ cl_git_pass(git_repository_config_snapshot(&config, repo));
+ cl_git_pass(git_config_get_string_buf(&buf, config, "branch.master.remote"));
+ original_remote = git_buf_detach(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, config, "branch.master.merge"));
+ original_merge = git_buf_detach(&buf);
+ git_config_free(config);
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2"));
@@ -84,20 +85,25 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
git_branch_move(&new_ref, original_ref, "master", 0));
cl_assert(giterr_last()->message != NULL);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, ce->value);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, ce->value);
+ cl_git_pass(git_repository_config_snapshot(&config, repo));
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
+ cl_assert_equal_s(original_remote, str);
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
+ cl_assert_equal_s(original_merge, str);
+ git_config_free(config);
cl_assert_equal_i(GIT_EEXISTS,
git_branch_move(&new_ref, original_ref, "cannot-fetch", 0));
cl_assert(giterr_last()->message != NULL);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, ce->value);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, ce->value);
+
+ cl_git_pass(git_repository_config_snapshot(&config, repo));
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
+ cl_assert_equal_s(original_remote, str);
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
+ cl_assert_equal_s(original_merge, str);
+ git_config_free(config);
git_reference_free(original_ref);
cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/track-local"));
@@ -106,12 +112,14 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
git_branch_move(&new_ref, original_ref, "master", 0));
cl_assert(giterr_last()->message != NULL);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.remote"));
- cl_assert_equal_s(original_remote, ce->value);
- cl_git_pass(git_config_get_entry(&ce, config, "branch.master.merge"));
- cl_assert_equal_s(original_merge, ce->value);
- free(original_remote); free(original_merge);
+ cl_git_pass(git_repository_config_snapshot(&config, repo));
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.remote"));
+ cl_assert_equal_s(original_remote, str);
+ cl_git_pass(git_config_get_string(&str, config, "branch.master.merge"));
+ cl_assert_equal_s(original_merge, str);
+
+ git__free(original_remote); git__free(original_merge);
git_reference_free(original_ref);
git_config_free(config);
}
diff --git a/tests/refs/branches/upstream.c b/tests/refs/branches/upstream.c
index f44f563a3..351449416 100644
--- a/tests/refs/branches/upstream.c
+++ b/tests/refs/branches/upstream.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "config/config_helpers.h"
#include "refs.h"
static git_repository *repo;
@@ -123,8 +124,6 @@ void test_refs_branches_upstream__set_unset_upstream(void)
{
git_reference *branch;
git_repository *repository;
- const char *value;
- git_config *config;
repository = cl_git_sandbox_init("testrepo.git");
@@ -132,11 +131,8 @@ void test_refs_branches_upstream__set_unset_upstream(void)
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test"));
cl_git_pass(git_branch_set_upstream(branch, "test/master"));
- cl_git_pass(git_repository_config(&config, repository));
- cl_git_pass(git_config_get_string(&value, config, "branch.test.remote"));
- cl_assert_equal_s(value, "test");
- cl_git_pass(git_config_get_string(&value, config, "branch.test.merge"));
- cl_assert_equal_s(value, "refs/heads/master");
+ assert_config_entry_value(repository, "branch.test.remote", "test");
+ assert_config_entry_value(repository, "branch.test.merge", "refs/heads/master");
git_reference_free(branch);
@@ -144,25 +140,22 @@ void test_refs_branches_upstream__set_unset_upstream(void)
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test"));
cl_git_pass(git_branch_set_upstream(branch, "master"));
- cl_git_pass(git_config_get_string(&value, config, "branch.test.remote"));
- cl_assert_equal_s(value, ".");
- cl_git_pass(git_config_get_string(&value, config, "branch.test.merge"));
- cl_assert_equal_s(value, "refs/heads/master");
+ assert_config_entry_value(repository, "branch.test.remote", ".");
+ assert_config_entry_value(repository, "branch.test.merge", "refs/heads/master");
/* unset */
cl_git_pass(git_branch_set_upstream(branch, NULL));
- cl_git_fail_with(git_config_get_string(&value, config, "branch.test.merge"), GIT_ENOTFOUND);
- cl_git_fail_with(git_config_get_string(&value, config, "branch.test.remote"), GIT_ENOTFOUND);
+ assert_config_entry_existence(repository, "branch.test.remote", false);
+ assert_config_entry_existence(repository, "branch.test.merge", false);
git_reference_free(branch);
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/master"));
cl_git_pass(git_branch_set_upstream(branch, NULL));
- cl_git_fail_with(git_config_get_string(&value, config, "branch.master.merge"), GIT_ENOTFOUND);
- cl_git_fail_with(git_config_get_string(&value, config, "branch.master.remote"), GIT_ENOTFOUND);
+ assert_config_entry_existence(repository, "branch.test.remote", false);
+ assert_config_entry_existence(repository, "branch.test.merge", false);
git_reference_free(branch);
- git_config_free(config);
cl_git_sandbox_cleanup();
}
diff --git a/tests/repo/init.c b/tests/repo/init.c
index 076156817..525020f5a 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -3,6 +3,7 @@
#include "repository.h"
#include "config.h"
#include "path.h"
+#include "config/config_helpers.h"
enum repo_mode {
STANDARD_REPOSITORY = 0,
@@ -370,8 +371,6 @@ void test_repo_init__extended_1(void)
void test_repo_init__relative_gitdir(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_config *cfg;
- const char *worktree_path;
git_buf dot_git_content = GIT_BUF_INIT;
opts.workdir_path = "../c_wd";
@@ -391,24 +390,19 @@ void test_repo_init__relative_gitdir(void)
/* Verify that the gitlink and worktree entries are relative */
/* Verify worktree */
- cl_git_pass(git_repository_config(&cfg, _repo));
- cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
- cl_assert_equal_s("../c_wd/", worktree_path);
+ assert_config_entry_value(_repo, "core.worktree", "../c_wd/");
/* Verify gitlink */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
git_buf_free(&dot_git_content);
- git_config_free(cfg);
cleanup_repository("root");
}
void test_repo_init__relative_gitdir_2(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
- git_config *cfg;
- const char *worktree_path;
git_buf dot_git_content = GIT_BUF_INIT;
git_buf full_path = GIT_BUF_INIT;
@@ -433,16 +427,13 @@ void test_repo_init__relative_gitdir_2(void)
/* Verify that the gitlink and worktree entries are relative */
/* Verify worktree */
- cl_git_pass(git_repository_config(&cfg, _repo));
- cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
- cl_assert_equal_s("../c_wd/", worktree_path);
+ assert_config_entry_value(_repo, "core.worktree", "../c_wd/");
/* Verify gitlink */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
git_buf_free(&dot_git_content);
- git_config_free(cfg);
cleanup_repository("root");
}
diff --git a/tests/repo/setters.c b/tests/repo/setters.c
index f34f1e471..5a83fdbee 100644
--- a/tests/repo/setters.c
+++ b/tests/repo/setters.c
@@ -46,7 +46,7 @@ void test_repo_setters__setting_a_workdir_prettifies_its_path(void)
void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
{
git_config *cfg;
- const char *val;
+ git_buf buf = GIT_BUF_INIT;
git_buf content = GIT_BUF_INIT;
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));
@@ -59,8 +59,10 @@ void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
git_buf_free(&content);
cl_git_pass(git_repository_config(&cfg, repo));
- cl_git_pass(git_config_get_string(&val, cfg, "core.worktree"));
- cl_assert(git__suffixcmp(val, "new_workdir/") == 0);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.worktree"));
+ cl_assert(git__suffixcmp(git_buf_cstr(&buf), "new_workdir/") == 0);
+
+ git_buf_free(&buf);
git_config_free(cfg);
}
diff --git a/tests/submodule/add.c b/tests/submodule/add.c
index 05dbafd88..01625d3aa 100644
--- a/tests/submodule/add.c
+++ b/tests/submodule/add.c
@@ -2,6 +2,7 @@
#include "posix.h"
#include "path.h"
#include "submodule_helpers.h"
+#include "config/config_helpers.h"
#include "fileops.h"
static git_repository *g_repo = NULL;
@@ -13,26 +14,19 @@ void test_submodule_add__cleanup(void)
static void assert_submodule_url(const char* name, const char *url)
{
- git_config *cfg;
- const char *s;
git_buf key = GIT_BUF_INIT;
- cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_buf_printf(&key, "submodule.%s.url", name));
- cl_git_pass(git_config_get_string(&s, cfg, git_buf_cstr(&key)));
- cl_assert_equal_s(s, url);
+ assert_config_entry_value(g_repo, git_buf_cstr(&key), url);
- git_config_free(cfg);
git_buf_free(&key);
}
void test_submodule_add__url_absolute(void)
{
git_submodule *sm;
- git_config *cfg;
git_repository *repo;
- const char *worktree_path;
git_buf dot_git_content = GIT_BUF_INIT;
g_repo = setup_fixture_submod2();
@@ -59,15 +53,12 @@ void test_submodule_add__url_absolute(void)
cl_git_pass(git_repository_open(&repo, "submod2/" "sm_libgit2"));
/* Verify worktree path is relative */
- cl_git_pass(git_repository_config(&cfg, repo));
- cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
- cl_assert_equal_s("../../../sm_libgit2/", worktree_path);
+ assert_config_entry_value(repo, "core.worktree", "../../../sm_libgit2/");
/* Verify gitdir path is relative */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_libgit2" "/.git"));
cl_assert_equal_s("gitdir: ../.git/modules/sm_libgit2/", dot_git_content.ptr);
- git_config_free(cfg);
git_repository_free(repo);
git_buf_free(&dot_git_content);
diff --git a/tests/submodule/init.c b/tests/submodule/init.c
index 3db6dae61..dbde0f284 100644
--- a/tests/submodule/init.c
+++ b/tests/submodule/init.c
@@ -34,9 +34,9 @@ void test_submodule_init__absolute_url(void)
/* init and verify that absolute path is written to .git/config */
cl_git_pass(git_submodule_init(sm, false));
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
- git_config_get_string(&config_url, cfg, "submodule.testrepo.url");
+ cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
git_buf_free(&absolute_url);
@@ -64,9 +64,9 @@ void test_submodule_init__relative_url(void)
/* init and verify that absolute path is written to .git/config */
cl_git_pass(git_submodule_init(sm, false));
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
- git_config_get_string(&config_url, cfg, "submodule.testrepo.url");
+ cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
git_buf_free(&absolute_url);
@@ -102,9 +102,9 @@ void test_submodule_init__relative_url_detached_head(void)
/* init and verify that absolute path is written to .git/config */
cl_git_pass(git_submodule_init(sm, false));
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
- git_config_get_string(&config_url, cfg, "submodule.testrepo.url");
+ cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
cl_assert_equal_s(absolute_url.ptr, config_url);
git_buf_free(&absolute_url);
diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c
index 9bb48bad2..3d7269bff 100644
--- a/tests/submodule/modify.c
+++ b/tests/submodule/modify.c
@@ -2,6 +2,7 @@
#include "posix.h"
#include "path.h"
#include "submodule_helpers.h"
+#include "config/config_helpers.h"
static git_repository *g_repo = NULL;
@@ -51,7 +52,7 @@ void test_submodule_modify__init(void)
git_submodule_reload_all(g_repo, 1);
/* confirm submodule data in config */
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url"));
cl_assert(git__suffixcmp(str, "/submod2_target") == 0);
cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_changed_head.url"));
@@ -72,20 +73,12 @@ static int sync_one_submodule(
static void assert_submodule_url_is_synced(
git_submodule *sm, const char *parent_key, const char *child_key)
{
- git_config *cfg;
- const char *str;
git_repository *smrepo;
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_get_string(&str, cfg, parent_key));
- cl_assert_equal_s(git_submodule_url(sm), str);
- git_config_free(cfg);
+ assert_config_entry_value(g_repo, parent_key, git_submodule_url(sm));
cl_git_pass(git_submodule_open(&smrepo, sm));
- cl_git_pass(git_repository_config(&cfg, smrepo));
- cl_git_pass(git_config_get_string(&str, cfg, child_key));
- cl_assert_equal_s(git_submodule_url(sm), str);
- git_config_free(cfg);
+ assert_config_entry_value(smrepo, child_key, git_submodule_url(sm));
git_repository_free(smrepo);
}
@@ -111,7 +104,7 @@ void test_submodule_modify__sync(void)
*/
/* check submodule info does not match before sync */
- cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM1".url"));
cl_assert(strcmp(git_submodule_url(sm1), str) != 0);
cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM2".url"));
diff --git a/tests/submodule/repository_init.c b/tests/submodule/repository_init.c
index bf1968d66..9be1e0b23 100644
--- a/tests/submodule/repository_init.c
+++ b/tests/submodule/repository_init.c
@@ -2,6 +2,7 @@
#include "posix.h"
#include "path.h"
#include "submodule_helpers.h"
+#include "config/config_helpers.h"
#include "fileops.h"
static git_repository *g_repo = NULL;
@@ -10,8 +11,6 @@ void test_submodule_repository_init__basic(void)
{
git_submodule *sm;
git_repository *repo;
- git_config *cfg;
- const char *worktree_path;
git_buf dot_git_content = GIT_BUF_INIT;
g_repo = setup_fixture_submod2();
@@ -21,9 +20,7 @@ void test_submodule_repository_init__basic(void)
cl_git_pass(git_submodule_repo_init(&repo, sm, 1));
/* Verify worktree */
- cl_git_pass(git_repository_config(&cfg, repo));
- cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
- cl_assert_equal_s("../../../sm_gitmodules_only/", worktree_path);
+ assert_config_entry_value(repo, "core.worktree", "../../../sm_gitmodules_only/");
/* Verify gitlink */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_gitmodules_only" "/.git"));
@@ -35,7 +32,6 @@ void test_submodule_repository_init__basic(void)
cl_assert(git_path_isdir("submod2/.git/modules/" "sm_gitmodules_only"));
cl_assert(git_path_isfile("submod2/.git/modules/" "sm_gitmodules_only" "/HEAD"));
- git_config_free(cfg);
git_submodule_free(sm);
git_repository_free(repo);
git_buf_free(&dot_git_content);