summaryrefslogtreecommitdiff
path: root/tests/libgit2/refs/branches/remote.c
diff options
context:
space:
mode:
authoryuangli <yuangli@mathworks.com>2022-07-12 15:07:54 +0100
committeryuangli <yuangli@mathworks.com>2022-07-12 15:07:54 +0100
commit760a5acc73c8da3780fcbc4b5de6f4397e22191e (patch)
tree92017c128fbf56eb66163312ce9c653d29005b2e /tests/libgit2/refs/branches/remote.c
parent1912f145e1e183f850d7611c0bc7e609cbc0a87a (diff)
parent92ffdd2cd243a49fafb317ea3a819dbe8a6dd3c9 (diff)
downloadlibgit2-760a5acc73c8da3780fcbc4b5de6f4397e22191e.tar.gz
Merge branch 'main' into fix-invalid-branch-name
Diffstat (limited to 'tests/libgit2/refs/branches/remote.c')
-rw-r--r--tests/libgit2/refs/branches/remote.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/libgit2/refs/branches/remote.c b/tests/libgit2/refs/branches/remote.c
new file mode 100644
index 000000000..e2bd3485a
--- /dev/null
+++ b/tests/libgit2/refs/branches/remote.c
@@ -0,0 +1,65 @@
+#include "clar_libgit2.h"
+#include "branch.h"
+#include "remote.h"
+
+static git_repository *g_repo;
+static const char *remote_tracking_branch_name = "refs/remotes/test/master";
+static const char *expected_remote_name = "test";
+static int expected_remote_name_length;
+
+void test_refs_branches_remote__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo");
+
+ expected_remote_name_length = (int)strlen(expected_remote_name) + 1;
+}
+
+void test_refs_branches_remote__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_branches_remote__can_get_remote_for_branch(void)
+{
+ git_buf remotename = {0};
+
+ cl_git_pass(git_branch_remote_name(&remotename, g_repo, remote_tracking_branch_name));
+
+ cl_assert_equal_s("test", remotename.ptr);
+ git_buf_dispose(&remotename);
+}
+
+void test_refs_branches_remote__no_matching_remote_returns_error(void)
+{
+ const char *unknown = "refs/remotes/nonexistent/master";
+ git_buf buf = GIT_BUF_INIT;
+
+ git_error_clear();
+ cl_git_fail_with(git_branch_remote_name(&buf, g_repo, unknown), GIT_ENOTFOUND);
+ cl_assert(git_error_last() != NULL);
+}
+
+void test_refs_branches_remote__local_remote_returns_error(void)
+{
+ const char *local = "refs/heads/master";
+ git_buf buf = GIT_BUF_INIT;
+
+ git_error_clear();
+ cl_git_fail_with(git_branch_remote_name(&buf, g_repo, local), GIT_ERROR);
+ cl_assert(git_error_last() != NULL);
+}
+
+void test_refs_branches_remote__ambiguous_remote_returns_error(void)
+{
+ git_remote *remote;
+ git_buf buf = GIT_BUF_INIT;
+
+ /* Create the remote */
+ cl_git_pass(git_remote_create_with_fetchspec(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2", "refs/heads/*:refs/remotes/test/*"));
+
+ git_remote_free(remote);
+
+ git_error_clear();
+ cl_git_fail_with(git_branch_remote_name(&buf, g_repo, remote_tracking_branch_name), GIT_EAMBIGUOUS);
+ cl_assert(git_error_last() != NULL);
+}