diff options
author | Vicent Martà <vicent@github.com> | 2013-11-11 18:47:15 +0400 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2013-11-11 18:47:15 +0400 |
commit | 6414fd338df89eaa5bd4c64f7ab310fb7d5758bb (patch) | |
tree | 4af0ea37b387c791bd89e73edea10e3353c54423 /tests-clar | |
parent | 5e1281f873e7eb5b51569ef33218dd20b69ff707 (diff) | |
parent | a6192d7c98976edb0ce4fd10438ac7a19c283598 (diff) |
Merge pull request #1956 from libgit2/cmn/fetch-default-head
Remote revamp (director's cut)
Diffstat (limited to 'tests-clar')
-rw-r--r-- | tests-clar/network/remote/local.c | 51 | ||||
-rw-r--r-- | tests-clar/online/fetch.c | 19 | ||||
-rw-r--r-- | tests-clar/online/push.c | 15 | ||||
-rw-r--r-- | tests-clar/online/push_util.c | 40 | ||||
-rw-r--r-- | tests-clar/online/push_util.h | 14 |
5 files changed, 65 insertions, 74 deletions
diff --git a/tests-clar/network/remote/local.c b/tests-clar/network/remote/local.c index 6d658a2e4..309142925 100644 --- a/tests-clar/network/remote/local.c +++ b/tests-clar/network/remote/local.c @@ -26,26 +26,6 @@ void test_network_remote_local__cleanup(void) cl_fixture_cleanup("remotelocal"); } -static int count_ref__cb(git_remote_head *head, void *payload) -{ - int *count = (int *)payload; - - (void)head; - (*count)++; - - return 0; -} - -static int ensure_peeled__cb(git_remote_head *head, void *payload) -{ - GIT_UNUSED(payload); - - if(strcmp(head->name, "refs/tags/test^{}") != 0) - return 0; - - return git_oid_streq(&head->oid, "e90810b8df3e80c413d903f631643c716887138d"); -} - static void connect_to_local_repository(const char *local_repository) { git_buf_sets(&file_path_buf, cl_git_path_url(local_repository)); @@ -65,39 +45,42 @@ void test_network_remote_local__connected(void) void test_network_remote_local__retrieve_advertised_references(void) { - int how_many_refs = 0; + const git_remote_head **refs; + size_t refs_len; connect_to_local_repository(cl_fixture("testrepo.git")); - cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); + cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); - cl_assert_equal_i(how_many_refs, 28); + cl_assert_equal_i(refs_len, 28); } void test_network_remote_local__retrieve_advertised_references_after_disconnect(void) { - int how_many_refs = 0; + const git_remote_head **refs; + size_t refs_len; connect_to_local_repository(cl_fixture("testrepo.git")); git_remote_disconnect(remote); - cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); + cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); - cl_assert_equal_i(how_many_refs, 28); + cl_assert_equal_i(refs_len, 28); } void test_network_remote_local__retrieve_advertised_references_from_spaced_repository(void) { - int how_many_refs = 0; + const git_remote_head **refs; + size_t refs_len; cl_fixture_sandbox("testrepo.git"); cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git")); connect_to_local_repository("spaced testrepo.git"); - cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); + cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); - cl_assert_equal_i(how_many_refs, 28); + cl_assert_equal_i(refs_len, 28); git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */ remote = NULL; @@ -107,9 +90,17 @@ void test_network_remote_local__retrieve_advertised_references_from_spaced_repos void test_network_remote_local__nested_tags_are_completely_peeled(void) { + const git_remote_head **refs; + size_t refs_len, i; + connect_to_local_repository(cl_fixture("testrepo.git")); - cl_git_pass(git_remote_ls(remote, &ensure_peeled__cb, NULL)); + cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); + + for (i = 0; i < refs_len; i++) { + if (!strcmp(refs[i]->name, "refs/tags/test^{}")) + cl_git_pass(git_oid_streq(&refs[i]->oid, "e90810b8df3e80c413d903f631643c716887138d")); + } } void test_network_remote_local__shorthand_fetch_refspec0(void) diff --git a/tests-clar/online/fetch.c b/tests-clar/online/fetch.c index df1b2e288..5153a7ae0 100644 --- a/tests-clar/online/fetch.c +++ b/tests-clar/online/fetch.c @@ -152,29 +152,20 @@ void test_online_fetch__can_cancel(void) git_remote_free(remote); } -int ls_cb(git_remote_head *rhead, void *payload) -{ - int *nr = payload; - GIT_UNUSED(rhead); - - (*nr)++; - - return 0; -} - void test_online_fetch__ls_disconnected(void) { + const git_remote_head **refs; + size_t refs_len_before, refs_len_after; git_remote *remote; - int nr_before = 0, nr_after = 0; cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git")); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); - cl_git_pass(git_remote_ls(remote, ls_cb, &nr_before)); + cl_git_pass(git_remote_ls(&refs, &refs_len_before, remote)); git_remote_disconnect(remote); - cl_git_pass(git_remote_ls(remote, ls_cb, &nr_after)); + cl_git_pass(git_remote_ls(&refs, &refs_len_after, remote)); - cl_assert_equal_i(nr_before, nr_after); + cl_assert_equal_i(refs_len_before, refs_len_after); git_remote_free(remote); } diff --git a/tests-clar/online/push.c b/tests-clar/online/push.c index d9ffe8aa9..aeb1ab47d 100644 --- a/tests-clar/online/push.c +++ b/tests-clar/online/push.c @@ -155,12 +155,11 @@ static void do_verify_push_status(git_push *push, const push_status expected[], */ static void verify_refs(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len) { - git_vector actual_refs = GIT_VECTOR_INIT; - - git_remote_ls(remote, record_ref_cb, &actual_refs); - verify_remote_refs(&actual_refs, expected_refs, expected_refs_len); + const git_remote_head **actual_refs; + size_t actual_refs_len; - git_vector_free(&actual_refs); + git_remote_ls(&actual_refs, &actual_refs_len, remote); + verify_remote_refs(actual_refs, actual_refs_len, expected_refs, expected_refs_len); } /** @@ -257,7 +256,8 @@ failed: void test_online_push__initialize(void) { git_vector delete_specs = GIT_VECTOR_INIT; - size_t i; + const git_remote_head **heads; + size_t i, heads_len; char *curr_del_spec; _repo = cl_git_sandbox_init("push_src"); @@ -314,7 +314,8 @@ void test_online_push__initialize(void) * order to delete the remote branch pointed to by HEAD (usually master). * See: https://raw.github.com/git/git/master/Documentation/RelNotes/1.7.0.txt */ - cl_git_pass(git_remote_ls(_remote, delete_ref_cb, &delete_specs)); + cl_git_pass(git_remote_ls(&heads, &heads_len, _remote)); + cl_git_pass(create_deletion_refspecs(&delete_specs, heads, heads_len)); if (delete_specs.length) { git_push *push; diff --git a/tests-clar/online/push_util.c b/tests-clar/online/push_util.c index 2e457844d..038c144db 100644 --- a/tests-clar/online/push_util.c +++ b/tests-clar/online/push_util.c @@ -44,20 +44,23 @@ int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid * return 0; } -int delete_ref_cb(git_remote_head *head, void *payload) +int create_deletion_refspecs(git_vector *out, const git_remote_head **heads, size_t heads_len) { - git_vector *delete_specs = (git_vector *)payload; git_buf del_spec = GIT_BUF_INIT; + size_t i; - /* Ignore malformed ref names (which also saves us from tag^{} */ - if (!git_reference_is_valid_name(head->name)) - return 0; - - /* Create a refspec that deletes a branch in the remote */ - if (strcmp(head->name, "refs/heads/master")) { - cl_git_pass(git_buf_putc(&del_spec, ':')); - cl_git_pass(git_buf_puts(&del_spec, head->name)); - cl_git_pass(git_vector_insert(delete_specs, git_buf_detach(&del_spec))); + for (i = 0; i < heads_len; i++) { + const git_remote_head *head = heads[i]; + /* Ignore malformed ref names (which also saves us from tag^{} */ + if (!git_reference_is_valid_name(head->name)) + return 0; + + /* Create a refspec that deletes a branch in the remote */ + if (strcmp(head->name, "refs/heads/master")) { + cl_git_pass(git_buf_putc(&del_spec, ':')); + cl_git_pass(git_buf_puts(&del_spec, head->name)); + cl_git_pass(git_vector_insert(out, git_buf_detach(&del_spec))); + } } return 0; @@ -69,26 +72,28 @@ int record_ref_cb(git_remote_head *head, void *payload) return git_vector_insert(refs, head); } -void verify_remote_refs(git_vector *actual_refs, const expected_ref expected_refs[], size_t expected_refs_len) +void verify_remote_refs(const git_remote_head *actual_refs[], size_t actual_refs_len, const expected_ref expected_refs[], size_t expected_refs_len) { size_t i, j = 0; git_buf msg = GIT_BUF_INIT; - git_remote_head *actual; + const git_remote_head *actual; char *oid_str; bool master_present = false; /* We don't care whether "master" is present on the other end or not */ - git_vector_foreach(actual_refs, i, actual) { + for (i = 0; i < actual_refs_len; i++) { + actual = actual_refs[i]; if (!strcmp(actual->name, "refs/heads/master")) { master_present = true; break; } } - if (expected_refs_len + (master_present ? 1 : 0) != actual_refs->length) + if (expected_refs_len + (master_present ? 1 : 0) != actual_refs_len) goto failed; - git_vector_foreach(actual_refs, i, actual) { + for (i = 0; i < actual_refs_len; i++) { + actual = actual_refs[i]; if (master_present && !strcmp(actual->name, "refs/heads/master")) continue; @@ -111,7 +116,8 @@ failed: } git_buf_puts(&msg, "\nACTUAL:\n"); - git_vector_foreach(actual_refs, i, actual) { + for (i = 0; i < actual_refs_len; i++) { + actual = actual_refs[i]; if (master_present && !strcmp(actual->name, "refs/heads/master")) continue; diff --git a/tests-clar/online/push_util.h b/tests-clar/online/push_util.h index 64f02cf2f..a7207c49e 100644 --- a/tests-clar/online/push_util.h +++ b/tests-clar/online/push_util.h @@ -41,12 +41,13 @@ void record_callbacks_data_clear(record_callbacks_data *data); int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, void *data); /** - * Callback for git_remote_list that adds refspecs to delete each ref + * Create a set of refspecs that deletes each of the inputs * - * @param head a ref on the remote - * @param payload a git_push instance + * @param out the vector in which to store the refspecs + * @param heads the remote heads + * @param heads_len the size of the array */ -int delete_ref_cb(git_remote_head *head, void *payload); +int create_deletion_refspecs(git_vector *out, const git_remote_head **heads, size_t heads_len); /** * Callback for git_remote_list that adds refspecs to vector @@ -60,10 +61,11 @@ int record_ref_cb(git_remote_head *head, void *payload); * Verifies that refs on remote stored by record_ref_cb match the expected * names, oids, and order. * - * @param actual_refs actual refs stored by record_ref_cb() + * @param actual_refs actual refs in the remote + * @param actual_refs_len length of actual_refs * @param expected_refs expected remote refs * @param expected_refs_len length of expected_refs */ -void verify_remote_refs(git_vector *actual_refs, const expected_ref expected_refs[], size_t expected_refs_len); +void verify_remote_refs(const git_remote_head *actual_refs[], size_t actual_refs_len, const expected_ref expected_refs[], size_t expected_refs_len); #endif /* INCLUDE_cl_push_util_h__ */ |