remote.c 1.79 KB
Newer Older
1 2 3 4 5
#include "clar_libgit2.h"
#include "branch.h"
#include "remote.h"

static git_repository *g_repo;
6 7 8
static const char *remote_tracking_branch_name = "refs/remotes/test/master";
static const char *expected_remote_name = "test";
static int expected_remote_name_length;
9 10 11 12 13

void test_refs_branches_remote__initialize(void)
{
	g_repo = cl_git_sandbox_init("testrepo");

14
	expected_remote_name_length = (int)strlen(expected_remote_name) + 1;
15 16 17 18 19 20 21 22 23
}

void test_refs_branches_remote__cleanup(void)
{
	cl_git_sandbox_cleanup();
}

void test_refs_branches_remote__can_get_remote_for_branch(void)
{
24
	git_buf remotename = {0};
25

26
	cl_git_pass(git_branch_remote_name(&remotename, g_repo, remote_tracking_branch_name));
27

28
	cl_assert_equal_s("test", remotename.ptr);
29
	git_buf_dispose(&remotename);
30 31 32 33
}

void test_refs_branches_remote__no_matching_remote_returns_error(void)
{
34
	const char *unknown = "refs/remotes/nonexistent/master";
35
	git_buf buf = GIT_BUF_INIT;
36

37
	git_error_clear();
38
	cl_git_fail_with(git_branch_remote_name(&buf, g_repo, unknown), GIT_ENOTFOUND);
39
	cl_assert(git_error_last() != NULL);
40 41 42 43
}

void test_refs_branches_remote__local_remote_returns_error(void)
{
44
	const char *local = "refs/heads/master";
45
	git_buf buf = GIT_BUF_INIT;
46

47
	git_error_clear();
48
	cl_git_fail_with(git_branch_remote_name(&buf, g_repo, local), GIT_ERROR);
49
	cl_assert(git_error_last() != NULL);
50 51 52 53 54
}

void test_refs_branches_remote__ambiguous_remote_returns_error(void)
{
	git_remote *remote;
55
	git_buf buf = GIT_BUF_INIT;
56 57

	/* Create the remote */
58
	cl_git_pass(git_remote_create_with_fetchspec(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2", "refs/heads/*:refs/remotes/test/*"));
59 60 61

	git_remote_free(remote);

62
	git_error_clear();
63
	cl_git_fail_with(git_branch_remote_name(&buf, g_repo, remote_tracking_branch_name), GIT_EAMBIGUOUS);
64
	cl_assert(git_error_last() != NULL);
65
}