summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/checkout/head.c6
-rw-r--r--tests-clar/config/configlevel.c59
-rw-r--r--tests-clar/config/multivar.c10
-rw-r--r--tests-clar/config/new.c9
-rw-r--r--tests-clar/config/read.c174
-rw-r--r--tests-clar/config/stress.c27
-rw-r--r--tests-clar/config/write.c92
-rw-r--r--tests-clar/network/remotes.c24
-rw-r--r--tests-clar/refs/branches/delete.c18
-rw-r--r--tests-clar/refs/branches/ishead.c11
-rw-r--r--tests-clar/repo/head.c33
-rw-r--r--tests-clar/repo/repo_helpers.c11
-rw-r--r--tests-clar/repo/repo_helpers.h5
-rw-r--r--tests-clar/reset/soft.c34
-rw-r--r--tests-clar/resources/config/config153
-rw-r--r--tests-clar/resources/config/config163
-rw-r--r--tests-clar/resources/config/config173
-rw-r--r--tests-clar/resources/config/config185
-rw-r--r--tests-clar/resources/config/config195
-rw-r--r--tests-clar/submodule/modify.c6
20 files changed, 420 insertions, 118 deletions
diff --git a/tests-clar/checkout/head.c b/tests-clar/checkout/head.c
index f2f81e5e2..d36034c52 100644
--- a/tests-clar/checkout/head.c
+++ b/tests-clar/checkout/head.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "refs.h"
+#include "repo/repo_helpers.h"
static git_repository *g_repo;
@@ -15,10 +16,7 @@ void test_checkout_head__cleanup(void)
void test_checkout_head__checking_out_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void)
{
- git_reference *head;
-
- cl_git_pass(git_reference_create_symbolic(&head, g_repo, GIT_HEAD_FILE, "refs/heads/hide/and/seek", 1));
- git_reference_free(head);
+ make_head_orphaned(g_repo, NON_EXISTING_HEAD);
cl_assert_equal_i(GIT_EORPHANEDHEAD, git_checkout_head(g_repo, NULL, NULL));
}
diff --git a/tests-clar/config/configlevel.c b/tests-clar/config/configlevel.c
new file mode 100644
index 000000000..d947856fa
--- /dev/null
+++ b/tests-clar/config/configlevel.c
@@ -0,0 +1,59 @@
+#include "clar_libgit2.h"
+
+void test_config_configlevel__adding_the_same_level_twice_returns_EEXISTS(void)
+{
+ int error;
+ git_config *cfg;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+ error = git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0);
+
+ cl_git_fail(error);
+ cl_assert_equal_i(GIT_EEXISTS, error);
+
+ git_config_free(cfg);
+}
+
+void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(void)
+{
+ git_config *cfg;
+ const char *s;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
+ GIT_CONFIG_LEVEL_LOCAL, 1));
+ 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);
+
+ git_config_free(cfg);
+}
+
+void test_config_configlevel__can_read_from_a_single_level_focused_file_after_parent_config_has_been_freed(void)
+{
+ git_config *cfg;
+ git_config *single_level_cfg;
+ const char *s;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+
+ cl_git_pass(git_config_open_level(&single_level_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL));
+
+ 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);
+
+ git_config_free(single_level_cfg);
+}
diff --git a/tests-clar/config/multivar.c b/tests-clar/config/multivar.c
index 3b40cd09a..26537e20a 100644
--- a/tests-clar/config/multivar.c
+++ b/tests-clar/config/multivar.c
@@ -12,13 +12,11 @@ void test_config_multivar__cleanup(void)
cl_fixture_cleanup("config");
}
-static int mv_read_cb(const char *name, const char *value, void *data)
+static int mv_read_cb(const git_config_entry *entry, void *data)
{
int *n = (int *) data;
- GIT_UNUSED(value);
-
- if (!strcmp(name, _name))
+ if (!strcmp(entry->name, _name))
(*n)++;
return 0;
@@ -37,11 +35,11 @@ void test_config_multivar__foreach(void)
git_config_free(cfg);
}
-static int cb(const char *val, void *data)
+static int cb(const git_config_entry *entry, void *data)
{
int *n = (int *) data;
- GIT_UNUSED(val);
+ GIT_UNUSED(entry);
(*n)++;
diff --git a/tests-clar/config/new.c b/tests-clar/config/new.c
index fae3ce941..6bd719fba 100644
--- a/tests-clar/config/new.c
+++ b/tests-clar/config/new.c
@@ -9,21 +9,16 @@
void test_config_new__write_new_config(void)
{
const char *out;
- struct git_config_file *file;
git_config *config;
- cl_git_pass(git_config_file__ondisk(&file, TEST_CONFIG));
- cl_git_pass(git_config_new(&config));
- cl_git_pass(git_config_add_file(config, file, 0));
+ cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_set_string(config, "color.ui", "auto"));
cl_git_pass(git_config_set_string(config, "core.editor", "ed"));
git_config_free(config);
- cl_git_pass(git_config_file__ondisk(&file, TEST_CONFIG));
- cl_git_pass(git_config_new(&config));
- cl_git_pass(git_config_add_file(config, file, 0));
+ 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");
diff --git a/tests-clar/config/read.c b/tests-clar/config/read.c
index fcd22463d..cf781e6bf 100644
--- a/tests-clar/config/read.c
+++ b/tests-clar/config/read.c
@@ -191,22 +191,24 @@ void test_config_read__escaping_quotes(void)
git_config_free(cfg);
}
-static int count_cfg_entries(
- const char *var_name, const char *value, void *payload)
+static int count_cfg_entries_and_compare_levels(
+ const git_config_entry *entry, void *payload)
{
int *count = payload;
- GIT_UNUSED(var_name);
- GIT_UNUSED(value);
+
+ if (!strcmp(entry->value, "7") || !strcmp(entry->value, "17"))
+ cl_assert(entry->level == GIT_CONFIG_LEVEL_GLOBAL);
+ else
+ cl_assert(entry->level == GIT_CONFIG_LEVEL_SYSTEM);
+
(*count)++;
return 0;
}
-static int cfg_callback_countdown(
- const char *var_name, const char *value, void *payload)
+static int cfg_callback_countdown(const git_config_entry *entry, void *payload)
{
int *count = payload;
- GIT_UNUSED(var_name);
- GIT_UNUSED(value);
+ GIT_UNUSED(entry);
(*count)--;
if (*count == 0)
return -100;
@@ -218,11 +220,15 @@ void test_config_read__foreach(void)
git_config *cfg;
int count, ret;
- cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
count = 0;
- cl_git_pass(git_config_foreach(cfg, count_cfg_entries, &count));
- cl_assert_equal_i(5, count);
+ cl_git_pass(git_config_foreach(cfg, count_cfg_entries_and_compare_levels, &count));
+ cl_assert_equal_i(7, count);
count = 3;
cl_git_fail(ret = git_config_foreach(cfg, cfg_callback_countdown, &count));
@@ -231,6 +237,14 @@ void test_config_read__foreach(void)
git_config_free(cfg);
}
+static int count_cfg_entries(const git_config_entry *entry, void *payload)
+{
+ int *count = payload;
+ GIT_UNUSED(entry);
+ (*count)++;
+ return 0;
+}
+
void test_config_read__foreach_match(void)
{
git_config *cfg;
@@ -282,31 +296,129 @@ void test_config_read__whitespace_not_required_around_assignment(void)
git_config_free(cfg);
}
-#if 0
+void test_config_read__read_git_config_entry(void)
+{
+ git_config *cfg;
+ const git_config_entry *entry;
-BEGIN_TEST(config10, "a repo's config overrides the global config")
- git_repository *repo;
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+
+ cl_git_pass(git_config_get_config_entry(&entry, cfg, "core.dummy2"));
+ cl_assert_equal_s("core.dummy2", entry->name);
+ cl_assert_equal_s("42", entry->value);
+ cl_assert_equal_i(GIT_CONFIG_LEVEL_SYSTEM, entry->level);
+
+ git_config_free(cfg);
+}
+
+/*
+ * At the beginning of the test:
+ * - config9 has: core.dummy2=42
+ * - config15 has: core.dummy2=7
+ * - config16 has: core.dummy2=28
+ */
+void test_config_read__local_config_overrides_global_config_overrides_system_config(void)
+{
git_config *cfg;
- int32_t version;
+ int32_t i;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
+ cl_assert_equal_i(28, i);
+
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
+ cl_assert_equal_i(7, i);
- cl_git_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- cl_git_pass(git_repository_config(&cfg, repo, GLOBAL_CONFIG, NULL));
- cl_git_pass(git_config_get_int32(cfg, "core.repositoryformatversion", &version));
- cl_assert(version == 0);
git_config_free(cfg);
- git_repository_free(repo);
-END_TEST
+}
-BEGIN_TEST(config11, "fall back to the global config")
- git_repository *repo;
+/*
+ * At the beginning of the test:
+ * - config9 has: core.global does not exist
+ * - config15 has: core.global=17
+ * - config16 has: core.global=29
+ *
+ * And also:
+ * - config9 has: core.system does not exist
+ * - config15 has: core.system does not exist
+ * - config16 has: core.system=11
+ */
+void test_config_read__fallback_from_local_to_global_and_from_global_to_system(void)
+{
git_config *cfg;
- int32_t num;
+ int32_t i;
- cl_git_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- cl_git_pass(git_repository_config(&cfg, repo, GLOBAL_CONFIG, NULL));
- cl_git_pass(git_config_get_int32(cfg, "core.something", &num));
- cl_assert(num == 2);
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.global"));
+ cl_assert_equal_i(17, i);
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.system"));
+ cl_assert_equal_i(11, i);
+
+ git_config_free(cfg);
+}
+
+/*
+ * At the beginning of the test, config18 has:
+ * int32global = 28
+ * int64global = 9223372036854775803
+ * boolglobal = true
+ * stringglobal = I'm a global config value!
+ *
+ * And config19 has:
+ * int32global = -1
+ * int64global = -2
+ * boolglobal = false
+ * stringglobal = don't find me!
+ *
+ */
+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"),
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
+ GIT_CONFIG_LEVEL_SYSTEM, 0));
+
+ cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));
+
+ cl_git_pass(git_config_get_int32(&i, cfg_specific, "core.int32global"));
+ cl_assert_equal_i(28, i);
+ cl_git_pass(git_config_get_int64(&l, cfg_specific, "core.int64global"));
+ 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);
+
+ git_config_free(cfg_specific);
git_config_free(cfg);
- git_repository_free(repo);
-END_TEST
-#endif
+}
diff --git a/tests-clar/config/stress.c b/tests-clar/config/stress.c
index 6e7db6e8f..317e877f7 100644
--- a/tests-clar/config/stress.c
+++ b/tests-clar/config/stress.c
@@ -4,11 +4,13 @@
#include "fileops.h"
#include "posix.h"
+#define TEST_CONFIG "git-test-config"
+
void test_config_stress__initialize(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
- cl_git_pass(git_filebuf_open(&file, "git-test-config", 0));
+ cl_git_pass(git_filebuf_open(&file, TEST_CONFIG, 0));
git_filebuf_printf(&file, "[color]\n\tui = auto\n");
git_filebuf_printf(&file, "[core]\n\teditor = \n");
@@ -18,19 +20,16 @@ void test_config_stress__initialize(void)
void test_config_stress__cleanup(void)
{
- p_unlink("git-test-config");
+ p_unlink(TEST_CONFIG);
}
void test_config_stress__dont_break_on_invalid_input(void)
{
const char *editor, *color;
- struct git_config_file *file;
git_config *config;
- cl_assert(git_path_exists("git-test-config"));
- cl_git_pass(git_config_file__ondisk(&file, "git-test-config"));
- cl_git_pass(git_config_new(&config));
- cl_git_pass(git_config_add_file(config, file, 0));
+ 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"));
@@ -40,13 +39,10 @@ void test_config_stress__dont_break_on_invalid_input(void)
void test_config_stress__comments(void)
{
- struct git_config_file *file;
git_config *config;
const char *str;
- cl_git_pass(git_config_file__ondisk(&file, cl_fixture("config/config12")));
- cl_git_pass(git_config_new(&config));
- cl_git_pass(git_config_add_file(config, file, 0));
+ cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12")));
cl_git_pass(git_config_get_string(&str, config, "some.section.other"));
cl_assert(!strcmp(str, "hello! \" ; ; ; "));
@@ -62,21 +58,16 @@ void test_config_stress__comments(void)
void test_config_stress__escape_subsection_names(void)
{
- struct git_config_file *file;
git_config *config;
const char *str;
cl_assert(git_path_exists("git-test-config"));
- cl_git_pass(git_config_file__ondisk(&file, "git-test-config"));
- cl_git_pass(git_config_new(&config));
- cl_git_pass(git_config_add_file(config, file, 0));
+ cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo"));
git_config_free(config);
- cl_git_pass(git_config_file__ondisk(&file, "git-test-config"));
- cl_git_pass(git_config_new(&config));
- cl_git_pass(git_config_add_file(config, file, 0));
+ 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(!strcmp("foo", str));
diff --git a/tests-clar/config/write.c b/tests-clar/config/write.c
index 13b669cb2..d98d1dd53 100644
--- a/tests-clar/config/write.c
+++ b/tests-clar/config/write.c
@@ -3,11 +3,15 @@
void test_config_write__initialize(void)
{
cl_fixture_sandbox("config/config9");
+ cl_fixture_sandbox("config/config15");
+ cl_fixture_sandbox("config/config17");
}
void test_config_write__cleanup(void)
{
cl_fixture_cleanup("config9");
+ cl_fixture_cleanup("config15");
+ cl_fixture_cleanup("config17");
}
void test_config_write__replace_value(void)
@@ -67,6 +71,40 @@ void test_config_write__delete_value(void)
git_config_free(cfg);
}
+/*
+ * At the beginning of the test:
+ * - config9 has: core.dummy2=42
+ * - config15 has: core.dummy2=7
+ */
+void test_config_write__delete_value_at_specific_level(void)
+{
+ git_config *cfg, *cfg_specific;
+ int32_t i;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config15"));
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
+ cl_assert(i == 7);
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, "config9",
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, "config15",
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+
+ cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));
+
+ cl_git_pass(git_config_delete(cfg_specific, "core.dummy2"));
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config15"));
+ cl_assert(git_config_get_int32(&i, cfg, "core.dummy2") == GIT_ENOTFOUND);
+ cl_git_pass(git_config_set_int32(cfg, "core.dummy2", 7));
+
+ git_config_free(cfg_specific);
+ git_config_free(cfg);
+}
+
void test_config_write__write_subsection(void)
{
git_config *cfg;
@@ -136,3 +174,57 @@ void test_config_write__escape_value(void)
cl_assert_equal_s(str, "this \"has\" quotes and \t");
git_config_free(cfg);
}
+
+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;
+
+ // open config15 as global level config file
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_add_file_ondisk(cfg, "config9",
+ GIT_CONFIG_LEVEL_LOCAL, 0));
+ cl_git_pass(git_config_add_file_ondisk(cfg, "config15",
+ GIT_CONFIG_LEVEL_GLOBAL, 0));
+
+ cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));
+
+ cl_git_pass(git_config_set_int32(cfg_specific, "core.int32global", 28));
+ cl_git_pass(git_config_set_int64(cfg_specific, "core.int64global", expected));
+ cl_git_pass(git_config_set_bool(cfg_specific, "core.boolglobal", true));
+ cl_git_pass(git_config_set_string(cfg_specific, "core.stringglobal", "I'm a global config value!"));
+ git_config_free(cfg_specific);
+ git_config_free(cfg);
+
+ // open config15 as local level config file
+ cl_git_pass(git_config_open_ondisk(&cfg, "config15"));
+
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.int32global"));
+ cl_assert_equal_i(28, i);
+ cl_git_pass(git_config_get_int64(&l, cfg, "core.int64global"));
+ 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);
+
+ git_config_free(cfg);
+}
+
+void test_config_write__add_value_at_file_with_no_clrf_at_the_end(void)
+{
+ git_config *cfg;
+ int i;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
+ cl_git_pass(git_config_set_int32(cfg, "core.newline", 7));
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
+ cl_git_pass(git_config_get_int32(&i, cfg, "core.newline"));
+ cl_assert_equal_i(7, i);
+
+ git_config_free(cfg);
+}
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index c7ee863e7..91c3e879d 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -225,3 +225,27 @@ void test_network_remotes__add(void)
cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/remotes/addtest/*"));
cl_assert_equal_s(git_remote_url(_remote), "http://github.com/libgit2/libgit2");
}
+
+void test_network_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(!strcmp(opt, "--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(!strcmp(opt, "--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);
+}
diff --git a/tests-clar/refs/branches/delete.c b/tests-clar/refs/branches/delete.c
index 99af44ef4..4e9c70904 100644
--- a/tests-clar/refs/branches/delete.c
+++ b/tests-clar/refs/branches/delete.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "refs.h"
+#include "repo/repo_helpers.h"
static git_repository *repo;
static git_reference *fake_remote;
@@ -52,11 +53,9 @@ void test_refs_branches_delete__can_delete_a_branch_even_if_HEAD_is_missing(void
void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_orphaned(void)
{
- git_reference *head;
git_reference *branch;
- cl_git_pass(git_reference_create_symbolic(&head, repo, GIT_HEAD_FILE, "refs/heads/hide/and/seek", 1));
- git_reference_free(head);
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
cl_git_pass(git_branch_delete(branch));
@@ -64,13 +63,15 @@ void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_orphaned(void)
void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(void)
{
- git_reference *master, *head, *branch;
+ git_reference *head, *branch;
- /* Detach HEAD and make it target the commit that "master" points to */
- cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
- cl_git_pass(git_reference_create_oid(&head, repo, "HEAD", git_reference_oid(master), 1));
+ cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
+ cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
+ cl_assert_equal_s("refs/heads/master", git_reference_target(head));
git_reference_free(head);
- git_reference_free(master);
+
+ /* Detach HEAD and make it target the commit that "master" points to */
+ git_repository_detach_head(repo);
cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
cl_git_pass(git_branch_delete(branch));
@@ -89,4 +90,3 @@ void test_refs_branches_delete__can_delete_a_remote_branch(void)
cl_git_pass(git_branch_lookup(&branch, repo, "nulltoken/master", GIT_BRANCH_REMOTE));
cl_git_pass(git_branch_delete(branch));
}
-
diff --git a/tests-clar/refs/branches/ishead.c b/tests-clar/refs/branches/ishead.c
index 0d57f00a3..ab17482b8 100644
--- a/tests-clar/refs/branches/ishead.c
+++ b/tests-clar/refs/branches/ishead.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "refs.h"
+#include "repo/repo_helpers.h"
static git_repository *repo;
static git_reference *branch;
@@ -22,21 +23,13 @@ void test_refs_branches_ishead__can_tell_if_a_branch_is_pointed_at_by_HEAD(void)
cl_assert_equal_i(true, git_branch_is_head(branch));
}
-static void make_head_orphaned(void)
-{
- git_reference *head;
-
- cl_git_pass(git_reference_create_symbolic(&head, repo, GIT_HEAD_FILE, "refs/heads/hide/and/seek", 1));
- git_reference_free(head);
-}
-
void test_refs_branches_ishead__can_properly_handle_orphaned_HEAD(void)
{
git_repository_free(repo);
repo = cl_git_sandbox_init("testrepo.git");
- make_head_orphaned();
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
diff --git a/tests-clar/repo/head.c b/tests-clar/repo/head.c
index 4113289f0..58f525e2b 100644
--- a/tests-clar/repo/head.c
+++ b/tests-clar/repo/head.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "refs.h"
+#include "repo_helpers.h"
git_repository *repo;
@@ -16,29 +17,18 @@ void test_repo_head__cleanup(void)
void test_repo_head__head_detached(void)
{
git_reference *ref;
- git_oid oid;
cl_assert(git_repository_head_detached(repo) == 0);
- /* detach the HEAD */
- git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd");
- cl_git_pass(git_reference_create_oid(&ref, repo, "HEAD", &oid, 1));
- cl_assert(git_repository_head_detached(repo) == 1);
- git_reference_free(ref);
+ git_repository_detach_head(repo);
+
+ cl_assert_equal_i(true, git_repository_head_detached(repo));
/* take the reop back to it's original state */
cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
- cl_assert(git_repository_head_detached(repo) == 0);
-
git_reference_free(ref);
-}
-static void make_head_orphaned(void)
-{
- git_reference *head;
-
- cl_git_pass(git_reference_create_symbolic(&head, repo, GIT_HEAD_FILE, "refs/heads/hide/and/seek", 1));
- git_reference_free(head);
+ cl_assert_equal_i(false, git_repository_head_detached(repo));
}
void test_repo_head__head_orphan(void)
@@ -47,7 +37,7 @@ void test_repo_head__head_orphan(void)
cl_assert(git_repository_head_orphan(repo) == 0);
- make_head_orphaned();
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
cl_assert(git_repository_head_orphan(repo) == 1);
@@ -174,7 +164,7 @@ void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void
void test_repo_head__detaching_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void)
{
- make_head_orphaned();
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_detach_head(repo));
}
@@ -183,7 +173,14 @@ void test_repo_head__retrieving_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void)
{
git_reference *head;
- make_head_orphaned();
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head(&head, repo));
}
+
+void test_repo_head__can_tell_if_an_orphaned_head_is_detached(void)
+{
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_assert_equal_i(false, git_repository_head_detached(repo));
+}
diff --git a/tests-clar/repo/repo_helpers.c b/tests-clar/repo/repo_helpers.c
new file mode 100644
index 000000000..35271feaa
--- /dev/null
+++ b/tests-clar/repo/repo_helpers.c
@@ -0,0 +1,11 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+#include "repo_helpers.h"
+
+void make_head_orphaned(git_repository* repo, const char *target)
+{
+ git_reference *head;
+
+ cl_git_pass(git_reference_create_symbolic(&head, repo, GIT_HEAD_FILE, target, 1));
+ git_reference_free(head);
+}
diff --git a/tests-clar/repo/repo_helpers.h b/tests-clar/repo/repo_helpers.h
new file mode 100644
index 000000000..e6aeb4873
--- /dev/null
+++ b/tests-clar/repo/repo_helpers.h
@@ -0,0 +1,5 @@
+#include "common.h"
+
+#define NON_EXISTING_HEAD "refs/heads/hide/and/seek"
+
+extern void make_head_orphaned(git_repository* repo, const char *target);
diff --git a/tests-clar/reset/soft.c b/tests-clar/reset/soft.c
index 3200c1591..1872baf3b 100644
--- a/tests-clar/reset/soft.c
+++ b/tests-clar/reset/soft.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "reset_helpers.h"
+#include "repo/repo_helpers.h"
static git_repository *repo;
static git_object *target;
@@ -39,20 +40,9 @@ void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(vo
assert_reset_soft(false);
}
-static void detach_head(void)
-{
- git_reference *head;
- git_oid oid;
-
- cl_git_pass(git_reference_name_to_oid(&oid, repo, "HEAD"));
-
- cl_git_pass(git_reference_create_oid(&head, repo, "HEAD", &oid, true));
- git_reference_free(head);
-}
-
void test_reset_soft__can_reset_the_detached_Head_to_the_specified_commit(void)
{
- detach_head();
+ git_repository_detach_head(repo);
assert_reset_soft(true);
}
@@ -100,3 +90,23 @@ void test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit(void)
retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91");
cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT));
}
+
+void test_reset_soft__resetting_against_an_orphaned_head_repo_makes_the_head_no_longer_orphaned(void)
+{
+ git_reference *head;
+
+ retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
+
+ make_head_orphaned(repo, NON_EXISTING_HEAD);
+
+ cl_assert_equal_i(true, git_repository_head_orphan(repo));
+
+ cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
+
+ cl_assert_equal_i(false, git_repository_head_orphan(repo));
+
+ cl_git_pass(git_reference_lookup(&head, repo, NON_EXISTING_HEAD));
+ cl_assert_equal_i(0, git_oid_streq(git_reference_oid(head), KNOWN_COMMIT_IN_BARE_REPO));
+
+ git_reference_free(head);
+}
diff --git a/tests-clar/resources/config/config15 b/tests-clar/resources/config/config15
new file mode 100644
index 000000000..6d34f817b
--- /dev/null
+++ b/tests-clar/resources/config/config15
@@ -0,0 +1,3 @@
+[core]
+ dummy2 = 7
+ global = 17
diff --git a/tests-clar/resources/config/config16 b/tests-clar/resources/config/config16
new file mode 100644
index 000000000..f25cdb728
--- /dev/null
+++ b/tests-clar/resources/config/config16
@@ -0,0 +1,3 @@
+[core]
+ dummy2 = 28
+ system = 11
diff --git a/tests-clar/resources/config/config17 b/tests-clar/resources/config/config17
new file mode 100644
index 000000000..ca25a86af
--- /dev/null
+++ b/tests-clar/resources/config/config17
@@ -0,0 +1,3 @@
+[core]
+ dummy2 = 7
+ global = 17 \ No newline at end of file
diff --git a/tests-clar/resources/config/config18 b/tests-clar/resources/config/config18
new file mode 100644
index 000000000..cb6fd5ebc
--- /dev/null
+++ b/tests-clar/resources/config/config18
@@ -0,0 +1,5 @@
+[core]
+ int32global = 28
+ int64global = 9223372036854775803
+ boolglobal = true
+ stringglobal = I'm a global config value! \ No newline at end of file
diff --git a/tests-clar/resources/config/config19 b/tests-clar/resources/config/config19
new file mode 100644
index 000000000..f3ae5a640
--- /dev/null
+++ b/tests-clar/resources/config/config19
@@ -0,0 +1,5 @@
+[core]
+ int32global = -1
+ int64global = -2
+ boolglobal = false
+ stringglobal = don't find me! \ No newline at end of file
diff --git a/tests-clar/submodule/modify.c b/tests-clar/submodule/modify.c
index 0fd732cc3..bfb8c8aaf 100644
--- a/tests-clar/submodule/modify.c
+++ b/tests-clar/submodule/modify.c
@@ -73,12 +73,10 @@ void test_submodule_modify__add(void)
git_config_free(cfg);
}
-static int delete_one_config(
- const char *var_name, const char *value, void *payload)
+static int delete_one_config(const git_config_entry *entry, void *payload)
{
git_config *cfg = payload;
- GIT_UNUSED(value);
- return git_config_delete(cfg, var_name);
+ return git_config_delete(cfg, entry->name);
}
static int init_one_submodule(