Skip to content

Commit 7891660

Browse files
committed
update remote/insteadof tests
we want to test: - an anonymous repo (a url) - a named repo with a url - a named repo with a url and pushurl and for each of these matching configuration: - only insteadOf - only pushInsteadOf - both insteadOf and pushInsteadOf this change adds test cases for all of these combinations.
1 parent ceddeed commit 7891660

File tree

2 files changed

+128
-23
lines changed

2 files changed

+128
-23
lines changed

tests/remote/insteadof.c

Lines changed: 96 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
#define REPO_PATH "testrepo2/.gitted"
66
#define REMOTE_ORIGIN "origin"
7-
#define REMOTE_INSTEADOF "insteadof-test"
7+
#define REMOTE_INSTEADOF_URL_FETCH "insteadof-url-fetch"
8+
#define REMOTE_INSTEADOF_URL_PUSH "insteadof-url-push"
9+
#define REMOTE_INSTEADOF_URL_BOTH "insteadof-url-both"
10+
#define REMOTE_INSTEADOF_PUSHURL_FETCH "insteadof-pushurl-fetch"
11+
#define REMOTE_INSTEADOF_PUSHURL_PUSH "insteadof-pushurl-push"
12+
#define REMOTE_INSTEADOF_PUSHURL_BOTH "insteadof-pushurl-both"
813

914
static git_repository *g_repo;
1015
static git_remote *g_remote;
@@ -21,52 +26,129 @@ void test_remote_insteadof__cleanup(void)
2126
git_remote_free(g_remote);
2227
}
2328

24-
void test_remote_insteadof__url_insteadof_not_applicable(void)
29+
void test_remote_insteadof__not_applicable(void)
2530
{
2631
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
2732
cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_ORIGIN));
2833

2934
cl_assert_equal_s(
3035
git_remote_url(g_remote),
3136
"https://github.com/libgit2/false.git");
37+
cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
3238
}
3339

34-
void test_remote_insteadof__url_insteadof_applicable(void)
40+
void test_remote_insteadof__url_insteadof_fetch(void)
3541
{
3642
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));
43+
cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_FETCH));
3844

3945
cl_assert_equal_s(
4046
git_remote_url(g_remote),
41-
"http://github.com/libgit2/libgit2");
47+
"http://github.com/url/fetch/libgit2");
48+
cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
4249
}
4350

44-
void test_remote_insteadof__pushurl_insteadof_not_applicable(void)
51+
void test_remote_insteadof__url_insteadof_push(void)
4552
{
4653
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));
54+
cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_PUSH));
4855

49-
cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
56+
cl_assert_equal_s(
57+
git_remote_url(g_remote),
58+
"http://example.com/url/push/libgit2");
59+
cl_assert_equal_s(
60+
git_remote_pushurl(g_remote),
61+
"git@github.com:url/push/libgit2");
5062
}
5163

52-
void test_remote_insteadof__pushurl_insteadof_applicable(void)
64+
void test_remote_insteadof__url_insteadof_both(void)
5365
{
5466
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));
67+
cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_BOTH));
5668

69+
cl_assert_equal_s(
70+
git_remote_url(g_remote),
71+
"http://github.com/url/both/libgit2");
5772
cl_assert_equal_s(
5873
git_remote_pushurl(g_remote),
59-
"git@github.com:libgit2/libgit2");
74+
"git@github.com:url/both/libgit2");
6075
}
6176

62-
void test_remote_insteadof__anonymous_remote(void)
77+
void test_remote_insteadof__pushurl_insteadof_fetch(void)
78+
{
79+
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
80+
cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_FETCH));
81+
82+
cl_assert_equal_s(
83+
git_remote_url(g_remote),
84+
"http://github.com/url/fetch/libgit2");
85+
cl_assert_equal_s(
86+
git_remote_pushurl(g_remote),
87+
"http://github.com/url/fetch/libgit2-push");
88+
}
89+
90+
void test_remote_insteadof__pushurl_insteadof_push(void)
91+
{
92+
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
93+
cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_PUSH));
94+
95+
cl_assert_equal_s(
96+
git_remote_url(g_remote),
97+
"http://example.com/url/push/libgit2");
98+
cl_assert_equal_s(
99+
git_remote_pushurl(g_remote),
100+
"http://example.com/url/push/libgit2-push");
101+
}
102+
103+
void test_remote_insteadof__pushurl_insteadof_both(void)
104+
{
105+
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
106+
cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_BOTH));
107+
108+
cl_assert_equal_s(
109+
git_remote_url(g_remote),
110+
"http://github.com/url/both/libgit2");
111+
cl_assert_equal_s(
112+
git_remote_pushurl(g_remote),
113+
"http://github.com/url/both/libgit2-push");
114+
}
115+
116+
void test_remote_insteadof__anonymous_remote_fetch(void)
63117
{
64118
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
65119
cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
66-
"http://example.com/libgit2/libgit2"));
120+
"http://example.com/url/fetch/libgit2"));
67121

68122
cl_assert_equal_s(
69123
git_remote_url(g_remote),
70-
"http://github.com/libgit2/libgit2");
124+
"http://github.com/url/fetch/libgit2");
71125
cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
72126
}
127+
128+
void test_remote_insteadof__anonymous_remote_push(void)
129+
{
130+
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
131+
cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
132+
"http://example.com/url/push/libgit2"));
133+
134+
cl_assert_equal_s(
135+
git_remote_url(g_remote),
136+
"http://example.com/url/push/libgit2");
137+
cl_assert_equal_s(
138+
git_remote_pushurl(g_remote),
139+
"git@github.com:url/push/libgit2");
140+
}
141+
142+
void test_remote_insteadof__anonymous_remote_both(void)
143+
{
144+
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
145+
cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
146+
"http://example.com/url/both/libgit2"));
147+
148+
cl_assert_equal_s(
149+
git_remote_url(g_remote),
150+
"http://github.com/url/both/libgit2");
151+
cl_assert_equal_s(
152+
git_remote_pushurl(g_remote),
153+
"git@github.com:url/both/libgit2");
154+
}

tests/resources/testrepo2/.gitted/config

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,42 @@
88
[remote "origin"]
99
url = https://github.com/libgit2/false.git
1010
fetch = +refs/heads/*:refs/remotes/origin/*
11-
[remote "insteadof-test"]
12-
url = http://example.com/libgit2/libgit2
13-
pushurl = http://github.com/libgit2/libgit2
11+
[remote "insteadof-url-fetch"]
12+
url = http://example.com/url/fetch/libgit2
13+
fetch = +refs/heads/*:refs/remotes/test/*
14+
[remote "insteadof-url-push"]
15+
url = http://example.com/url/push/libgit2
16+
fetch = +refs/heads/*:refs/remotes/test/*
17+
[remote "insteadof-url-both"]
18+
url = http://example.com/url/both/libgit2
19+
fetch = +refs/heads/*:refs/remotes/test/*
20+
[remote "insteadof-pushurl-fetch"]
21+
url = http://example.com/url/fetch/libgit2
22+
pushurl = http://example.com/url/fetch/libgit2-push
23+
fetch = +refs/heads/*:refs/remotes/test/*
24+
[remote "insteadof-pushurl-push"]
25+
url = http://example.com/url/push/libgit2
26+
pushurl = http://example.com/url/push/libgit2-push
27+
fetch = +refs/heads/*:refs/remotes/test/*
28+
[remote "insteadof-pushurl-both"]
29+
url = http://example.com/url/both/libgit2
30+
pushurl = http://example.com/url/both/libgit2-push
1431
fetch = +refs/heads/*:refs/remotes/test/*
1532
[branch "master"]
1633
remote = origin
1734
merge = refs/heads/master
1835
rebase = true
1936
[url "longer-non-prefix-match"]
20-
insteadOf = ttp://example.com/li
37+
# not applicable because it's not a prefix match
38+
insteadOf = ttp://example.com/url/fetch/li
2139
[url "shorter-prefix"]
22-
insteadOf = http://example.co
23-
[url "http://github.com"]
24-
insteadOf = http://example.com
25-
[url "git@github.com:"]
26-
pushInsteadOf = http://github.com/
40+
# not applicable because the matched prefix is shorter
41+
insteadOf = http://example.com/url/fe
42+
[url "http://github.com/url/fetch"]
43+
insteadOf = http://example.com/url/fetch
44+
[url "http://github.com/url/both"]
45+
insteadOf = http://example.com/url/both
46+
[url "git@github.com:url/push"]
47+
pushInsteadOf = http://example.com/url/push
48+
[url "git@github.com:url/both"]
49+
pushInsteadOf = http://example.com/url/both

0 commit comments

Comments
 (0)