insteadof.c 4.61 KB
Newer Older
1 2 3 4 5 6
#include "clar_libgit2.h"
#include "remote.h"
#include "repository.h"

#define REPO_PATH "testrepo2/.gitted"
#define REMOTE_ORIGIN "origin"
7 8 9 10 11 12
#define REMOTE_INSTEADOF_URL_FETCH "insteadof-url-fetch"
#define REMOTE_INSTEADOF_URL_PUSH "insteadof-url-push"
#define REMOTE_INSTEADOF_URL_BOTH "insteadof-url-both"
#define REMOTE_INSTEADOF_PUSHURL_FETCH "insteadof-pushurl-fetch"
#define REMOTE_INSTEADOF_PUSHURL_PUSH "insteadof-pushurl-push"
#define REMOTE_INSTEADOF_PUSHURL_BOTH "insteadof-pushurl-both"
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

static git_repository *g_repo;
static git_remote *g_remote;

void test_remote_insteadof__initialize(void)
{
	g_repo = NULL;
	g_remote = NULL;
}

void test_remote_insteadof__cleanup(void)
{
	git_repository_free(g_repo);
	git_remote_free(g_remote);
}

29
void test_remote_insteadof__not_applicable(void)
30 31 32 33 34 35 36
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_ORIGIN));

	cl_assert_equal_s(
		git_remote_url(g_remote),
		"https://github.com/libgit2/false.git");
37
	cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
38 39
}

40
void test_remote_insteadof__url_insteadof_fetch(void)
41 42
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
43
	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_FETCH));
44 45 46

	cl_assert_equal_s(
	    git_remote_url(g_remote),
47 48
	    "http://github.com/url/fetch/libgit2");
	cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
49 50
}

51
void test_remote_insteadof__url_insteadof_push(void)
52 53
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
54
	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_PUSH));
55

56 57 58 59 60 61
	cl_assert_equal_s(
	    git_remote_url(g_remote),
	    "http://example.com/url/push/libgit2");
	cl_assert_equal_s(
	    git_remote_pushurl(g_remote),
	    "git@github.com:url/push/libgit2");
62 63
}

64
void test_remote_insteadof__url_insteadof_both(void)
65 66
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
67
	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_BOTH));
68 69

	cl_assert_equal_s(
70 71 72
	    git_remote_url(g_remote),
	    "http://github.com/url/both/libgit2");
	cl_assert_equal_s(
73
	    git_remote_pushurl(g_remote),
74
	    "git@github.com:url/both/libgit2");
75
}
76

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
void test_remote_insteadof__pushurl_insteadof_fetch(void)
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_FETCH));

	cl_assert_equal_s(
	    git_remote_url(g_remote),
	    "http://github.com/url/fetch/libgit2");
	cl_assert_equal_s(
	    git_remote_pushurl(g_remote),
	    "http://github.com/url/fetch/libgit2-push");
}

void test_remote_insteadof__pushurl_insteadof_push(void)
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_PUSH));

	cl_assert_equal_s(
	    git_remote_url(g_remote),
	    "http://example.com/url/push/libgit2");
	cl_assert_equal_s(
	    git_remote_pushurl(g_remote),
	    "http://example.com/url/push/libgit2-push");
}

void test_remote_insteadof__pushurl_insteadof_both(void)
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_BOTH));

	cl_assert_equal_s(
	    git_remote_url(g_remote),
	    "http://github.com/url/both/libgit2");
	cl_assert_equal_s(
	    git_remote_pushurl(g_remote),
	    "http://github.com/url/both/libgit2-push");
}

void test_remote_insteadof__anonymous_remote_fetch(void)
117 118 119
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
	cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
120
	    "http://example.com/url/fetch/libgit2"));
121 122 123

	cl_assert_equal_s(
	    git_remote_url(g_remote),
124
	    "http://github.com/url/fetch/libgit2");
125 126
	cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
}
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

void test_remote_insteadof__anonymous_remote_push(void)
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
	cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
	    "http://example.com/url/push/libgit2"));

	cl_assert_equal_s(
	    git_remote_url(g_remote),
	    "http://example.com/url/push/libgit2");
	cl_assert_equal_s(
	    git_remote_pushurl(g_remote),
	    "git@github.com:url/push/libgit2");
}

void test_remote_insteadof__anonymous_remote_both(void)
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
	cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
	    "http://example.com/url/both/libgit2"));

	cl_assert_equal_s(
	    git_remote_url(g_remote),
	    "http://github.com/url/both/libgit2");
	cl_assert_equal_s(
	    git_remote_pushurl(g_remote),
	    "git@github.com:url/both/libgit2");
}