summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-12-03 16:45:39 -0800
committerRussell Belfer <rb@github.com>2013-12-11 10:57:49 -0800
commit96869a4edb2872934e0e167a726ab240f4270fea (patch)
tree2d770414acef2d1d45a609e004c0aa6fa56d06d7 /tests
parent9f77b3f6f5ce6944ec49dfc666ef6b8df0af0c6b (diff)
downloadlibgit2-96869a4edb2872934e0e167a726ab240f4270fea.tar.gz
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')
-rw-r--r--tests/config/rename.c82
-rw-r--r--tests/config/validkeyname.c20
-rw-r--r--tests/config/write.c1
-rw-r--r--tests/refs/branches/move.c44
4 files changed, 126 insertions, 21 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");
+}
diff --git a/tests/config/validkeyname.c b/tests/config/validkeyname.c
index 33699737b..0ef4a9ae3 100644
--- a/tests/config/validkeyname.c
+++ b/tests/config/validkeyname.c
@@ -46,23 +46,3 @@ void test_config_validkeyname__accessing_requires_a_valid_name(void)
assert_invalid_config_key_name("dif.dir\nstat.lines");
assert_invalid_config_key_name("dif.dirstat.li\nes");
}
-
-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_validkeyname__renaming_a_section_requires_a_valid_name(void)
-{
- git_repository *repo;
-
- cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
-
- assert_invalid_config_section_name(repo, "");
- assert_invalid_config_section_name(repo, "bra\nch");
- assert_invalid_config_section_name(repo, "branc#");
- assert_invalid_config_section_name(repo, "bra\nch.duh");
- assert_invalid_config_section_name(repo, "branc#.duh");
-
- git_repository_free(repo);
-}
diff --git a/tests/config/write.c b/tests/config/write.c
index 15f750dc0..922d75557 100644
--- a/tests/config/write.c
+++ b/tests/config/write.c
@@ -303,3 +303,4 @@ void test_config_write__updating_a_locked_config_file_returns_ELOCKED(void)
git_config_free(cfg);
}
+
diff --git a/tests/refs/branches/move.c b/tests/refs/branches/move.c
index ecf14e006..9d233de1a 100644
--- a/tests/refs/branches/move.c
+++ b/tests/refs/branches/move.c
@@ -66,12 +66,54 @@ void test_refs_branches_move__can_move_a_local_branch_to_a_partially_colliding_n
void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_collide_with_an_existing_one(void)
{
git_reference *original_ref, *new_ref;
+ git_config *config;
+ const git_config_entry *ce;
+ char *original_remote, *original_merge;
+
+ 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_reference_lookup(&original_ref, repo, "refs/heads/br2"));
- cl_assert_equal_i(GIT_EEXISTS, git_branch_move(&new_ref, original_ref, "master", 0));
+ cl_assert_equal_i(GIT_EEXISTS,
+ 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_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);
+
+ git_reference_free(original_ref);
+ cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/track-local"));
+
+ cl_assert_equal_i(GIT_EEXISTS,
+ 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);
git_reference_free(original_ref);
+ git_config_free(config);
}
void test_refs_branches_move__moving_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)