diff options
| author | Vicent Marti <tanoku@gmail.com> | 2013-01-03 04:24:12 +0100 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2013-01-03 04:24:12 +0100 |
| commit | 7761ce21625564b6526b89326c14a9843a1403d4 (patch) | |
| tree | 7982836b366da36a70017d8ce15856e08d7d27a2 /tests-clar/online | |
| parent | 4236164a77b57c42641530a523590a913ba299f9 (diff) | |
| parent | 922dd9788cfec2ec4727e1b264a2ad6a7f4849ba (diff) | |
| download | libgit2-7761ce21625564b6526b89326c14a9843a1403d4.tar.gz | |
Merge branch 'development' into clar2
Conflicts:
tests-clar/clone/nonetwork.c
tests-clar/online/clone.c
tests-clar/online/fetchhead.c
Diffstat (limited to 'tests-clar/online')
| -rw-r--r-- | tests-clar/online/clone.c | 121 | ||||
| -rw-r--r-- | tests-clar/online/fetch.c | 10 | ||||
| -rw-r--r-- | tests-clar/online/fetchhead.c | 14 | ||||
| -rw-r--r-- | tests-clar/online/push.c | 4 |
4 files changed, 79 insertions, 70 deletions
diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c index bf35fac04..c216a1ea7 100644 --- a/tests-clar/online/clone.c +++ b/tests-clar/online/clone.c @@ -7,79 +7,58 @@ #define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository" static git_repository *g_repo; -static git_remote *g_origin; static git_clone_options g_options; void test_online_clone__initialize(void) { + git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT; + g_repo = NULL; memset(&g_options, 0, sizeof(git_clone_options)); g_options.version = GIT_CLONE_OPTIONS_VERSION; - cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_REPO_URL, GIT_REMOTE_DEFAULT_FETCH)); + g_options.checkout_opts = dummy_opts; + g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; } void test_online_clone__cleanup(void) { - git_remote_free(g_origin); -} - -static void cleanup_repository(void *path) -{ if (g_repo) { git_repository_free(g_repo); g_repo = NULL; } - cl_fixture_cleanup((const char *)path); + cl_fixture_cleanup("./foo"); } - void test_online_clone__network_full(void) { git_remote *origin; - cl_set_cleanup(&cleanup_repository, "./foo"); - - cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options)); + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); cl_assert(!git_repository_is_bare(g_repo)); cl_git_pass(git_remote_load(&origin, g_repo, "origin")); git_remote_free(origin); } - void test_online_clone__network_bare(void) { git_remote *origin; - cl_set_cleanup(&cleanup_repository, "./foo"); g_options.bare = true; - cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options)); + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); cl_assert(git_repository_is_bare(g_repo)); cl_git_pass(git_remote_load(&origin, g_repo, "origin")); git_remote_free(origin); } -void test_online_clone__cope_with_already_existing_directory(void) -{ - cl_set_cleanup(&cleanup_repository, "./foo"); - - p_mkdir("./foo", GIT_DIR_MODE); - cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options)); -} - void test_online_clone__empty_repository(void) { git_reference *head; - cl_set_cleanup(&cleanup_repository, "./foo"); - - git_remote_free(g_origin); - cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_EMPTYREPO_URL, GIT_REMOTE_DEFAULT_FETCH)); - - cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options)); + cl_git_pass(git_clone(&g_repo, LIVE_EMPTYREPO_URL, "./foo", &g_options)); cl_assert_equal_i(true, git_repository_is_empty(g_repo)); cl_assert_equal_i(true, git_repository_head_orphan(g_repo)); @@ -91,19 +70,6 @@ void test_online_clone__empty_repository(void) git_reference_free(head); } -void test_online_clone__can_prevent_the_checkout_of_a_standard_repo(void) -{ - git_buf path = GIT_BUF_INIT; - cl_set_cleanup(&cleanup_repository, "./foo"); - - cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options)); - - cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt")); - cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&path))); - - git_buf_free(&path); -} - static void checkout_progress(const char *path, size_t cur, size_t tot, void *payload) { bool *was_called = (bool*)payload; @@ -120,22 +86,18 @@ static void fetch_progress(const git_transfer_progress *stats, void *payload) void test_online_clone__can_checkout_a_cloned_repo(void) { - git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; git_buf path = GIT_BUF_INIT; git_reference *head; bool checkout_progress_cb_was_called = false, fetch_progress_cb_was_called = false; - opts.checkout_strategy = GIT_CHECKOUT_SAFE; - opts.progress_cb = &checkout_progress; - opts.progress_payload = &checkout_progress_cb_was_called; - g_options.checkout_opts = &opts; + g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; + g_options.checkout_opts.progress_cb = &checkout_progress; + g_options.checkout_opts.progress_payload = &checkout_progress_cb_was_called; g_options.fetch_progress_cb = &fetch_progress; g_options.fetch_progress_payload = &fetch_progress_cb_was_called; - cl_set_cleanup(&cleanup_repository, "./foo"); - - cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options)); + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt")); cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&path))); @@ -150,3 +112,62 @@ void test_online_clone__can_checkout_a_cloned_repo(void) git_reference_free(head); git_buf_free(&path); } + +static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *payload) +{ + int *callcount = (int*)payload; + GIT_UNUSED(refname); GIT_UNUSED(a); GIT_UNUSED(b); + *callcount = *callcount + 1; + return 0; +} + +void test_clone_network__custom_remote_callbacks(void) +{ + git_remote_callbacks remote_callbacks = GIT_REMOTE_CALLBACKS_INIT; + int callcount = 0; + + g_options.remote_callbacks = &remote_callbacks; + remote_callbacks.update_tips = update_tips; + remote_callbacks.payload = &callcount; + + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); + cl_assert(callcount > 0); +} + +struct cred_user_pass { + const char *user; + const char *pass; +}; + +static int cred_acquire( + git_cred **cred, + const char *url, + unsigned int allowed_types, + void *payload) +{ + struct cred_user_pass *user_pass = (struct cred_user_pass*)payload; + + GIT_UNUSED(url); + if ((GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) == 0 || + git_cred_userpass_plaintext_new(cred, user_pass->user, user_pass->pass) < 0) + return -1; + + return 0; +} + +void test_clone_network__credentials(void) +{ + /* Remote URL environment variable must be set. User and password are optional. */ + const char *remote_url = cl_getenv("GITTEST_REMOTE_URL"); + struct cred_user_pass user_pass = { + cl_getenv("GITTEST_REMOTE_USER"), + cl_getenv("GITTEST_REMOTE_PASS") + }; + + if (!remote_url) return; + + g_options.cred_acquire_cb = cred_acquire; + g_options.cred_acquire_payload = &user_pass; + + cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options)); +} diff --git a/tests-clar/online/fetch.c b/tests-clar/online/fetch.c index 6fcea2512..41cdb30e1 100644 --- a/tests-clar/online/fetch.c +++ b/tests-clar/online/fetch.c @@ -40,7 +40,7 @@ static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n) callbacks.update_tips = update_tips; counter = 0; - cl_git_pass(git_remote_add(&remote, _repo, "test", url)); + cl_git_pass(git_remote_create(&remote, _repo, "test", url)); git_remote_set_callbacks(remote, &callbacks); git_remote_set_autotag(remote, flag); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); @@ -85,13 +85,12 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date { git_repository *_repository; bool invoked = false; - git_remote *remote, *origin; + git_remote *remote; git_clone_options opts = GIT_CLONE_OPTIONS_INIT; - opts.bare = true; - cl_git_pass(git_remote_new(&origin, NULL, "origin", "https://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DEFAULT_FETCH)); - cl_git_pass(git_clone(&_repository, origin, "./fetch/lg2", &opts)); + cl_git_pass(git_clone(&_repository, "https://github.com/libgit2/TestGitRepository.git", + "./fetch/lg2", &opts)); git_repository_free(_repository); cl_git_pass(git_repository_open(&_repository, "./fetch/lg2")); @@ -109,6 +108,5 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date git_remote_disconnect(remote); git_remote_free(remote); - git_remote_free(origin); git_repository_free(_repository); } diff --git a/tests-clar/online/fetchhead.c b/tests-clar/online/fetchhead.c index fb6cf57e5..f89270741 100644 --- a/tests-clar/online/fetchhead.c +++ b/tests-clar/online/fetchhead.c @@ -8,7 +8,6 @@ #define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository" static git_repository *g_repo; -static git_remote *g_origin; static git_clone_options g_options; void test_online_fetchhead__initialize(void) @@ -17,30 +16,21 @@ void test_online_fetchhead__initialize(void) memset(&g_options, 0, sizeof(git_clone_options)); g_options.version = GIT_CLONE_OPTIONS_VERSION; - cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_REPO_URL, GIT_REMOTE_DEFAULT_FETCH)); } void test_online_fetchhead__cleanup(void) { - git_remote_free(g_origin); -} - -static void cleanup_repository(void *path) -{ if (g_repo) { git_repository_free(g_repo); g_repo = NULL; } - cl_fixture_cleanup((const char *)path); + cl_fixture_cleanup("./foo"); } - static void fetchhead_test_clone(void) { - cl_set_cleanup(&cleanup_repository, "./foo"); - - cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options)); + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); } static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fetchhead) diff --git a/tests-clar/online/push.c b/tests-clar/online/push.c index 477a39ee6..d8ee4c2ee 100644 --- a/tests-clar/online/push.c +++ b/tests-clar/online/push.c @@ -164,7 +164,7 @@ void test_online_push__initialize(void) _remote = NULL; if (_remote_url) { - cl_git_pass(git_remote_add(&_remote, _repo, "test", _remote_url)); + cl_git_pass(git_remote_create(&_remote, _repo, "test", _remote_url)); git_remote_set_cred_acquire_cb(_remote, cred_acquire_cb, &cred_acquire_called); record_callbacks_data_clear(&_record_cbs_data); @@ -494,7 +494,7 @@ void test_online_push__bad_refspecs(void) git_push *push; if (_remote) { - cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH)); +// cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH)); cl_git_pass(git_push_new(&push, _remote)); /* Unexpanded branch names not supported */ |
