Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-12-04 04:45:39 +0400
committerRussell Belfer <rb@github.com>2013-12-11 22:57:49 +0400
commit96869a4edb2872934e0e167a726ab240f4270fea (patch)
tree2d770414acef2d1d45a609e004c0aa6fa56d06d7 /tests/config/rename.c
parent9f77b3f6f5ce6944ec49dfc666ef6b8df0af0c6b (diff)
Improve GIT_EUSER handling
This adds giterr_user_cancel to return GIT_EUSER and clear any error message that is sitting around. As a result of using that in places, we need to be more thorough with capturing errors that happen inside a callback when used internally. To help with that, this also adds giterr_capture and giterr_restore so that when we internally use a foreach-type function that clears errors and converts them to GIT_EUSER, it is easier to restore not just the return value, but the actual error message text.
Diffstat (limited to 'tests/config/rename.c')
-rw-r--r--tests/config/rename.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/config/rename.c b/tests/config/rename.c
new file mode 100644
index 000000000..29ade7b00
--- /dev/null
+++ b/tests/config/rename.c
@@ -0,0 +1,82 @@
+#include "clar_libgit2.h"
+#include "config.h"
+
+static git_repository *g_repo = NULL;
+static git_config *g_config = NULL;
+
+void test_config_rename__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo.git");
+ cl_git_pass(git_repository_config(&g_config, g_repo));
+}
+
+void test_config_rename__cleanup(void)
+{
+ git_config_free(g_config);
+ g_config = NULL;
+
+ cl_git_sandbox_cleanup();
+ g_repo = NULL;
+}
+
+void test_config_rename__can_rename(void)
+{
+ const git_config_entry *ce;
+
+ cl_git_pass(git_config_get_entry(
+ &ce, g_config, "branch.track-local.remote"));
+ cl_assert_equal_s(".", ce->value);
+
+ cl_git_fail(git_config_get_entry(
+ &ce, g_config, "branch.local-track.remote"));
+
+ cl_git_pass(git_config_rename_section(
+ g_repo, "branch.track-local", "branch.local-track"));
+
+ cl_git_pass(git_config_get_entry(
+ &ce, g_config, "branch.local-track.remote"));
+ cl_assert_equal_s(".", ce->value);
+
+ cl_git_fail(git_config_get_entry(
+ &ce, g_config, "branch.track-local.remote"));
+}
+
+void test_config_rename__prevent_overwrite(void)
+{
+ const git_config_entry *ce;
+ const git_error *err;
+
+ cl_git_pass(git_config_set_string(
+ g_config, "branch.local-track.remote", "yellow"));
+
+ cl_git_pass(git_config_get_entry(
+ &ce, g_config, "branch.local-track.remote"));
+ cl_assert_equal_s("yellow", ce->value);
+
+ cl_git_pass(git_config_rename_section(
+ g_repo, "branch.track-local", "branch.local-track"));
+
+ cl_git_pass(git_config_get_entry(
+ &ce, g_config, "branch.local-track.remote"));
+ cl_assert_equal_s(".", ce->value);
+
+// cl_assert((err = giterr_last()) != NULL);
+// cl_assert(err->message != NULL);
+}
+
+static void assert_invalid_config_section_name(
+ git_repository *repo, const char *name)
+{
+ cl_git_fail_with(
+ git_config_rename_section(repo, "branch.remoteless", name),
+ GIT_EINVALIDSPEC);
+}
+
+void test_config_rename__require_a_valid_new_name(void)
+{
+ assert_invalid_config_section_name(g_repo, "");
+ assert_invalid_config_section_name(g_repo, "bra\nch");
+ assert_invalid_config_section_name(g_repo, "branc#");
+ assert_invalid_config_section_name(g_repo, "bra\nch.duh");
+ assert_invalid_config_section_name(g_repo, "branc#.duh");
+}