1 #include "clar_libgit2.h"
2 #include "remote.h"
3 #include "repository.h"
4 
5 #define REPO_PATH "testrepo2/.gitted"
6 #define REMOTE_ORIGIN "origin"
7 #define REMOTE_INSTEADOF "insteadof-test"
8 
9 static git_repository *g_repo;
10 static git_remote *g_remote;
11 
test_remote_insteadof__initialize(void)12 void test_remote_insteadof__initialize(void)
13 {
14 	g_repo = NULL;
15 	g_remote = NULL;
16 }
17 
test_remote_insteadof__cleanup(void)18 void test_remote_insteadof__cleanup(void)
19 {
20 	git_repository_free(g_repo);
21 	git_remote_free(g_remote);
22 }
23 
test_remote_insteadof__url_insteadof_not_applicable(void)24 void test_remote_insteadof__url_insteadof_not_applicable(void)
25 {
26 	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
27 	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_ORIGIN));
28 
29 	cl_assert_equal_s(
30 		git_remote_url(g_remote),
31 		"https://github.com/libgit2/false.git");
32 }
33 
test_remote_insteadof__url_insteadof_applicable(void)34 void test_remote_insteadof__url_insteadof_applicable(void)
35 {
36 	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
37 	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF));
38 
39 	cl_assert_equal_s(
40 	    git_remote_url(g_remote),
41 	    "http://github.com/libgit2/libgit2");
42 }
43 
test_remote_insteadof__pushurl_insteadof_not_applicable(void)44 void test_remote_insteadof__pushurl_insteadof_not_applicable(void)
45 {
46 	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
47 	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_ORIGIN));
48 
49 	cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
50 }
51 
test_remote_insteadof__pushurl_insteadof_applicable(void)52 void test_remote_insteadof__pushurl_insteadof_applicable(void)
53 {
54 	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
55 	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF));
56 
57 	cl_assert_equal_s(
58 	    git_remote_pushurl(g_remote),
59 	    "git@github.com:libgit2/libgit2");
60 }
61 
test_remote_insteadof__anonymous_remote(void)62 void test_remote_insteadof__anonymous_remote(void)
63 {
64 	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
65 	cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
66 	    "http://example.com/libgit2/libgit2"));
67 
68 	cl_assert_equal_s(
69 	    git_remote_url(g_remote),
70 	    "http://github.com/libgit2/libgit2");
71 	cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
72 }
73