summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-09-01 16:35:10 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-09-02 12:47:12 +0200
commit538f908175a0912e0119f0ea8935e2d2b2dc416c (patch)
treefa93328c0aad5b2ecb64857d56474b3b533ded61
parentf2ffab618ad536bbd0da15d191bd9c488916761a (diff)
downloadlibgit2-538f908175a0912e0119f0ea8935e2d2b2dc416c.tar.gz
remote: add test for single-branch clone
When cloning, we may be asking for a particular branch or subset of branches. Make sure we test for that.
-rw-r--r--tests/network/remote/remotes.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c
index 21c57119a..4e274d889 100644
--- a/tests/network/remote/remotes.c
+++ b/tests/network/remote/remotes.c
@@ -511,3 +511,64 @@ void test_network_remote_remotes__query_refspecs(void)
git_remote_free(remote);
}
+
+static int remote_single_branch(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload)
+{
+ char *fetch_refspecs[] = {
+ "refs/heads/first-merge:refs/remotes/origin/first-merge",
+ };
+ git_strarray fetch_refspecs_strarray = {
+ fetch_refspecs,
+ 1,
+ };
+
+ GIT_UNUSED(payload);
+
+ cl_git_pass(git_remote_create(out, repo, name, url));
+ cl_git_pass(git_remote_set_fetch_refspecs(*out, &fetch_refspecs_strarray));
+
+ return 0;
+}
+
+void test_network_remote_remotes__single_branch(void)
+{
+ git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
+ git_repository *repo;
+ git_strarray refs;
+ size_t i, count = 0;
+
+ opts.remote_cb = remote_single_branch;
+ opts.checkout_branch = "first-merge";
+
+ cl_git_pass(git_clone(&repo, "git://github.com/libgit2/TestGitRepository", "./single-branch", &opts));
+ cl_git_pass(git_reference_list(&refs, repo));
+
+ for (i = 0; i < refs.count; i++) {
+ if (!git__prefixcmp(refs.strings[i], "refs/heads/"))
+ count++;
+ }
+ cl_assert_equal_i(1, count);
+
+ git_repository_free(repo);
+}
+
+void test_network_remote_remotes__restricted_refspecs(void)
+{
+ git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
+ git_repository *repo;
+ git_strarray refs;
+ size_t i, count = 0;
+
+ opts.remote_cb = remote_single_branch;
+
+ cl_git_pass(git_clone(&repo, "git://github.com/libgit2/TestGitRepository", "./restrict-refspec", &opts));
+ cl_git_pass(git_reference_list(&refs, repo));
+
+ for (i = 0; i < refs.count; i++) {
+ if (!git__prefixcmp(refs.strings[i], "refs/heads/"))
+ count++;
+ }
+ cl_assert_equal_i(1, count);
+
+ git_repository_free(repo);
+}