From 8897f8fe687f11d327be30873480c5d02a6a00a6 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 5 May 2017 09:47:54 +0200 Subject: remote: reject various actions for detached remotes There are only few actions which actually make sense for a detached remote, like e.g. `git_remote_ls`, `git_remote_prune`. For all the other actions, we have to report an error when the remote has no repository attached to it. This commit does so and implements some tests. --- tests/online/remotes.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/online') diff --git a/tests/online/remotes.c b/tests/online/remotes.c index a86f2d9ae..efab63f1f 100644 --- a/tests/online/remotes.c +++ b/tests/online/remotes.c @@ -53,3 +53,36 @@ void test_online_remotes__restricted_refspecs(void) cl_git_fail_with(GIT_EINVALIDSPEC, git_clone(&repo, "git://github.com/libgit2/TestGitRepository", "./restrict-refspec", &opts)); } + +void test_online_remotes__detached_remote_fails_downloading(void) +{ + git_remote *remote; + + cl_git_pass(git_remote_create_detached(&remote, URL)); + cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL)); + cl_git_fail(git_remote_download(remote, NULL, NULL)); + + git_remote_free(remote); +} + +void test_online_remotes__detached_remote_fails_uploading(void) +{ + git_remote *remote; + + cl_git_pass(git_remote_create_detached(&remote, URL)); + cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL)); + cl_git_fail(git_remote_upload(remote, NULL, NULL)); + + git_remote_free(remote); +} + +void test_online_remotes__detached_remote_fails_pushing(void) +{ + git_remote *remote; + + cl_git_pass(git_remote_create_detached(&remote, URL)); + cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL)); + cl_git_fail(git_remote_push(remote, NULL, NULL)); + + git_remote_free(remote); +} -- cgit v1.2.1 From 34b793910f7c1e68dc2a07f20d9a403aa8ad7268 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 5 May 2017 09:14:20 +0200 Subject: tests: online::remotes: add defines for URL and refspec The repository URL is duplicated several times and can be de-duplicated like this. Furthermore, exchange the static refspec variable with a define to reduce BSS size. --- tests/online/remotes.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tests/online') diff --git a/tests/online/remotes.c b/tests/online/remotes.c index efab63f1f..3a483f79c 100644 --- a/tests/online/remotes.c +++ b/tests/online/remotes.c @@ -1,12 +1,13 @@ #include "clar_libgit2.h" -static const char *refspec = "refs/heads/first-merge:refs/remotes/origin/first-merge"; +#define URL "git://github.com/libgit2/TestGitRepository" +#define REFSPEC "refs/heads/first-merge:refs/remotes/origin/first-merge" static int remote_single_branch(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) { GIT_UNUSED(payload); - cl_git_pass(git_remote_create_with_fetchspec(out, repo, name, url, refspec)); + cl_git_pass(git_remote_create_with_fetchspec(out, repo, name, url, REFSPEC)); return 0; } @@ -22,7 +23,7 @@ void test_online_remotes__single_branch(void) 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_clone(&repo, URL, "./single-branch", &opts)); cl_git_pass(git_reference_list(&refs, repo)); for (i = 0; i < refs.count; i++) { @@ -37,7 +38,7 @@ void test_online_remotes__single_branch(void) cl_git_pass(git_remote_get_fetch_refspecs(&refs, remote)); cl_assert_equal_i(1, refs.count); - cl_assert_equal_s(refspec, refs.strings[0]); + cl_assert_equal_s(REFSPEC, refs.strings[0]); git_strarray_free(&refs); git_remote_free(remote); @@ -51,7 +52,7 @@ void test_online_remotes__restricted_refspecs(void) opts.remote_cb = remote_single_branch; - cl_git_fail_with(GIT_EINVALIDSPEC, git_clone(&repo, "git://github.com/libgit2/TestGitRepository", "./restrict-refspec", &opts)); + cl_git_fail_with(GIT_EINVALIDSPEC, git_clone(&repo, URL, "./restrict-refspec", &opts)); } void test_online_remotes__detached_remote_fails_downloading(void) -- cgit v1.2.1 From 9364f274d7189ec9f39fee6e6b056434dca13b54 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 5 May 2017 09:40:38 +0200 Subject: remote: test creating and fetching detached remotes --- tests/online/remotes.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests/online') diff --git a/tests/online/remotes.c b/tests/online/remotes.c index 3a483f79c..d79eb1f59 100644 --- a/tests/online/remotes.c +++ b/tests/online/remotes.c @@ -87,3 +87,41 @@ void test_online_remotes__detached_remote_fails_pushing(void) git_remote_free(remote); } + +void test_online_remotes__detached_remote_succeeds_ls(void) +{ + const char *refs[] = { + "HEAD", + "refs/heads/first-merge", + "refs/heads/master", + "refs/heads/no-parent", + "refs/tags/annotated_tag", + "refs/tags/annotated_tag^{}", + "refs/tags/blob", + "refs/tags/commit_tree", + "refs/tags/nearly-dangling", + }; + const git_remote_head **heads; + git_remote *remote; + size_t i, j, n; + + cl_git_pass(git_remote_create_detached(&remote, URL)); + cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL)); + cl_git_pass(git_remote_ls(&heads, &n, remote)); + + cl_assert_equal_sz(n, 9); + for (i = 0; i < n; i++) { + char found = false; + + for (j = 0; j < ARRAY_SIZE(refs); j++) { + if (!strcmp(heads[i]->name, refs[j])) { + found = true; + break; + } + } + + cl_assert_(found, heads[i]->name); + } + + git_remote_free(remote); +} -- cgit v1.2.1