Commit 7891660a by Martin Kühl

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.
parent ceddeed8
...@@ -4,7 +4,12 @@ ...@@ -4,7 +4,12 @@
#define REPO_PATH "testrepo2/.gitted" #define REPO_PATH "testrepo2/.gitted"
#define REMOTE_ORIGIN "origin" #define REMOTE_ORIGIN "origin"
#define REMOTE_INSTEADOF "insteadof-test" #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"
static git_repository *g_repo; static git_repository *g_repo;
static git_remote *g_remote; static git_remote *g_remote;
...@@ -21,7 +26,7 @@ void test_remote_insteadof__cleanup(void) ...@@ -21,7 +26,7 @@ void test_remote_insteadof__cleanup(void)
git_remote_free(g_remote); git_remote_free(g_remote);
} }
void test_remote_insteadof__url_insteadof_not_applicable(void) void test_remote_insteadof__not_applicable(void)
{ {
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); 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_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_ORIGIN));
...@@ -29,44 +34,121 @@ void test_remote_insteadof__url_insteadof_not_applicable(void) ...@@ -29,44 +34,121 @@ void test_remote_insteadof__url_insteadof_not_applicable(void)
cl_assert_equal_s( cl_assert_equal_s(
git_remote_url(g_remote), git_remote_url(g_remote),
"https://github.com/libgit2/false.git"); "https://github.com/libgit2/false.git");
cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
} }
void test_remote_insteadof__url_insteadof_applicable(void) void test_remote_insteadof__url_insteadof_fetch(void)
{ {
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF)); cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_FETCH));
cl_assert_equal_s( cl_assert_equal_s(
git_remote_url(g_remote), git_remote_url(g_remote),
"http://github.com/libgit2/libgit2"); "http://github.com/url/fetch/libgit2");
cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
} }
void test_remote_insteadof__pushurl_insteadof_not_applicable(void) void test_remote_insteadof__url_insteadof_push(void)
{ {
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); 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_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_PUSH));
cl_assert_equal_p(git_remote_pushurl(g_remote), NULL); 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__pushurl_insteadof_applicable(void) void test_remote_insteadof__url_insteadof_both(void)
{ {
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF)); cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_BOTH));
cl_assert_equal_s( 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_remote_pushurl(g_remote),
"git@github.com:libgit2/libgit2"); "git@github.com:url/both/libgit2");
} }
void test_remote_insteadof__anonymous_remote(void) 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)
{ {
cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH))); cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo, cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
"http://example.com/libgit2/libgit2")); "http://example.com/url/fetch/libgit2"));
cl_assert_equal_s( cl_assert_equal_s(
git_remote_url(g_remote), git_remote_url(g_remote),
"http://github.com/libgit2/libgit2"); "http://github.com/url/fetch/libgit2");
cl_assert_equal_p(git_remote_pushurl(g_remote), NULL); cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
} }
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");
}
...@@ -8,19 +8,42 @@ ...@@ -8,19 +8,42 @@
[remote "origin"] [remote "origin"]
url = https://github.com/libgit2/false.git url = https://github.com/libgit2/false.git
fetch = +refs/heads/*:refs/remotes/origin/* fetch = +refs/heads/*:refs/remotes/origin/*
[remote "insteadof-test"] [remote "insteadof-url-fetch"]
url = http://example.com/libgit2/libgit2 url = http://example.com/url/fetch/libgit2
pushurl = http://github.com/libgit2/libgit2 fetch = +refs/heads/*:refs/remotes/test/*
[remote "insteadof-url-push"]
url = http://example.com/url/push/libgit2
fetch = +refs/heads/*:refs/remotes/test/*
[remote "insteadof-url-both"]
url = http://example.com/url/both/libgit2
fetch = +refs/heads/*:refs/remotes/test/*
[remote "insteadof-pushurl-fetch"]
url = http://example.com/url/fetch/libgit2
pushurl = http://example.com/url/fetch/libgit2-push
fetch = +refs/heads/*:refs/remotes/test/*
[remote "insteadof-pushurl-push"]
url = http://example.com/url/push/libgit2
pushurl = http://example.com/url/push/libgit2-push
fetch = +refs/heads/*:refs/remotes/test/*
[remote "insteadof-pushurl-both"]
url = http://example.com/url/both/libgit2
pushurl = http://example.com/url/both/libgit2-push
fetch = +refs/heads/*:refs/remotes/test/* fetch = +refs/heads/*:refs/remotes/test/*
[branch "master"] [branch "master"]
remote = origin remote = origin
merge = refs/heads/master merge = refs/heads/master
rebase = true rebase = true
[url "longer-non-prefix-match"] [url "longer-non-prefix-match"]
insteadOf = ttp://example.com/li # not applicable because it's not a prefix match
insteadOf = ttp://example.com/url/fetch/li
[url "shorter-prefix"] [url "shorter-prefix"]
insteadOf = http://example.co # not applicable because the matched prefix is shorter
[url "http://github.com"] insteadOf = http://example.com/url/fe
insteadOf = http://example.com [url "http://github.com/url/fetch"]
[url "git@github.com:"] insteadOf = http://example.com/url/fetch
pushInsteadOf = http://github.com/ [url "http://github.com/url/both"]
insteadOf = http://example.com/url/both
[url "git@github.com:url/push"]
pushInsteadOf = http://example.com/url/push
[url "git@github.com:url/both"]
pushInsteadOf = http://example.com/url/both
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment