summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2015-05-04 11:59:20 +0200
committerPatrick Steinhardt <ps@pks.im>2015-05-31 13:21:53 +0200
commitec0c4c400172e47cb3324c1b78ebc739ee6cc184 (patch)
tree180adcf1de8fd17c774359d50d84f1b4da8c2740 /tests
parenta5670d4f2da38b9f0fde73d44ea8898372c39e40 (diff)
downloadlibgit2-ec0c4c400172e47cb3324c1b78ebc739ee6cc184.tar.gz
remote: apply insteadOf configuration.
A remote's URLs are now modified according to the url.*.insteadOf and url.*.pushInsteadOf configurations. This allows a user to replace URL prefixes by setting the corresponding keys. E.g. "url.foo.insteadOf = bar" would replace the prefix "bar" with the new prefix "foo".
Diffstat (limited to 'tests')
-rw-r--r--tests/remote/insteadof.c60
-rw-r--r--tests/resources/testrepo2/.gitted/config12
2 files changed, 72 insertions, 0 deletions
diff --git a/tests/remote/insteadof.c b/tests/remote/insteadof.c
new file mode 100644
index 000000000..c9b39f098
--- /dev/null
+++ b/tests/remote/insteadof.c
@@ -0,0 +1,60 @@
+#include "clar_libgit2.h"
+#include "remote.h"
+#include "repository.h"
+
+#define REPO_PATH "testrepo2/.gitted"
+#define REMOTE_ORIGIN "origin"
+#define REMOTE_INSTEADOF "insteadof-test"
+
+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);
+}
+
+void test_remote_insteadof__url_insteadof_not_applicable(void)
+{
+ 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");
+}
+
+void test_remote_insteadof__url_insteadof_applicable(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));
+
+ cl_assert_equal_s(
+ git_remote_url(g_remote),
+ "http://github.com/libgit2/libgit2");
+}
+
+void test_remote_insteadof__pushurl_insteadof_not_applicable(void)
+{
+ 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_p(git_remote_pushurl(g_remote), NULL);
+}
+
+void test_remote_insteadof__pushurl_insteadof_applicable(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));
+
+ cl_assert_equal_s(
+ git_remote_pushurl(g_remote),
+ "git@github.com:libgit2/libgit2");
+}
diff --git a/tests/resources/testrepo2/.gitted/config b/tests/resources/testrepo2/.gitted/config
index fc2433caf..4af067f04 100644
--- a/tests/resources/testrepo2/.gitted/config
+++ b/tests/resources/testrepo2/.gitted/config
@@ -8,7 +8,19 @@
[remote "origin"]
url = https://github.com/libgit2/false.git
fetch = +refs/heads/*:refs/remotes/origin/*
+[remote "insteadof-test"]
+ url = http://example.com/libgit2/libgit2
+ pushurl = http://github.com/libgit2/libgit2
+ fetch = +refs/heads/*:refs/remotes/test/*
[branch "master"]
remote = origin
merge = refs/heads/master
rebase = true
+[url "longer-non-prefix-match"]
+ insteadOf = ttp://example.com/li
+[url "shorter-prefix"]
+ insteadOf = http://example.co
+[url "http://github.com"]
+ insteadOf = http://example.com
+[url "git@github.com:"]
+ pushInsteadOf = http://github.com/