summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2013-01-03 04:24:12 +0100
committerVicent Marti <tanoku@gmail.com>2013-01-03 04:24:12 +0100
commit7761ce21625564b6526b89326c14a9843a1403d4 (patch)
tree7982836b366da36a70017d8ce15856e08d7d27a2 /tests-clar
parent4236164a77b57c42641530a523590a913ba299f9 (diff)
parent922dd9788cfec2ec4727e1b264a2ad6a7f4849ba (diff)
downloadlibgit2-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')
-rw-r--r--tests-clar/clone/empty.c22
-rw-r--r--tests-clar/clone/nonetwork.c125
-rw-r--r--tests-clar/network/fetchlocal.c4
-rw-r--r--tests-clar/network/remotelocal.c2
-rw-r--r--tests-clar/network/remoterename.c50
-rw-r--r--tests-clar/network/remotes.c55
-rw-r--r--tests-clar/online/clone.c121
-rw-r--r--tests-clar/online/fetch.c10
-rw-r--r--tests-clar/online/fetchhead.c14
-rw-r--r--tests-clar/online/push.c4
10 files changed, 221 insertions, 186 deletions
diff --git a/tests-clar/clone/empty.c b/tests-clar/clone/empty.c
index 8f2e6ff12..652363747 100644
--- a/tests-clar/clone/empty.c
+++ b/tests-clar/clone/empty.c
@@ -4,7 +4,6 @@
#include "repository.h"
static git_clone_options g_options;
-static git_remote *g_origin;
static git_repository *g_repo;
static git_repository *g_repo_cloned;
@@ -17,13 +16,10 @@ void test_clone_empty__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", cl_git_fixture_url("testrepo.git"), GIT_REMOTE_DEFAULT_FETCH));
}
void test_clone_empty__cleanup(void)
{
- git_remote_free(g_origin);
- g_origin = NULL;
cl_git_sandbox_cleanup();
}
@@ -39,23 +35,15 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void)
{
cl_set_cleanup(&cleanup_repository, "./empty");
- git_remote_free(g_origin);
- g_origin = NULL;
- cl_git_pass(git_remote_new(&g_origin, NULL, "origin", "./empty_bare.git", GIT_REMOTE_DEFAULT_FETCH));
-
g_options.bare = true;
- cl_git_pass(git_clone(&g_repo_cloned, g_origin, "./empty", &g_options));
+ cl_git_pass(git_clone(&g_repo_cloned, "./empty_bare.git", "./empty", &g_options));
}
void test_clone_empty__can_clone_an_empty_local_repo(void)
{
cl_set_cleanup(&cleanup_repository, "./empty");
- git_remote_free(g_origin);
- g_origin = NULL;
- cl_git_pass(git_remote_new(&g_origin, NULL, "origin", "./empty_bare.git", GIT_REMOTE_DEFAULT_FETCH));
-
- cl_git_pass(git_clone(&g_repo_cloned, g_origin, "./empty", &g_options));
+ cl_git_pass(git_clone(&g_repo_cloned, "./empty_bare.git", "./empty", &g_options));
}
void test_clone_empty__can_clone_an_empty_standard_repo(void)
@@ -64,11 +52,7 @@ void test_clone_empty__can_clone_an_empty_standard_repo(void)
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_remove_placeholders(git_repository_path(g_repo), "dummy-marker.txt");
- git_remote_free(g_origin);
- g_origin = NULL;
- cl_git_pass(git_remote_new(&g_origin, NULL, "origin", "./empty_standard_repo", GIT_REMOTE_DEFAULT_FETCH));
-
cl_set_cleanup(&cleanup_repository, "./empty");
- cl_git_pass(git_clone(&g_repo_cloned, g_origin, "./empty", &g_options));
+ cl_git_pass(git_clone(&g_repo_cloned, "./empty_standard_repo", "./empty", &g_options));
}
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c
index 91c020e9f..b99c29dcf 100644
--- a/tests-clar/clone/nonetwork.c
+++ b/tests-clar/clone/nonetwork.c
@@ -6,16 +6,18 @@
#define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
static git_clone_options g_options;
-static git_remote *g_origin;
static git_repository *g_repo;
void test_clone_nonetwork__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", cl_git_fixture_url("testrepo.git"), GIT_REMOTE_DEFAULT_FETCH));
+ g_options.checkout_opts = dummy_opts;
+ g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
}
void test_clone_nonetwork__cleanup(void)
@@ -26,51 +28,140 @@ void test_clone_nonetwork__cleanup(void)
}
cl_fixture_cleanup("./foo");
- git_remote_free(g_origin);
}
void test_clone_nonetwork__bad_url(void)
{
/* Clone should clean up the mess if the URL isn't a git repository */
- git_remote_free(g_origin);
- cl_git_pass(git_remote_new(&g_origin, NULL, "origin", "not_a_repo", GIT_REMOTE_DEFAULT_FETCH));
-
- cl_git_fail(git_clone(&g_repo, g_origin, "./foo", &g_options));
+ cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
cl_assert(!git_path_exists("./foo"));
g_options.bare = true;
- cl_git_fail(git_clone(&g_repo, g_origin, "./foo", &g_options));
+ cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
cl_assert(!git_path_exists("./foo"));
}
void test_clone_nonetwork__local(void)
{
- cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options));
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
}
void test_clone_nonetwork__local_absolute_path(void)
{
- const char *local_src = cl_fixture("testrepo.git");
- git_remote_free(g_origin);
-
- cl_git_pass(git_remote_new(&g_origin, NULL, "origin", local_src, GIT_REMOTE_DEFAULT_FETCH));
- cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options));
+ const char *local_src;
+ local_src = cl_fixture("testrepo.git");
+ cl_git_pass(git_clone(&g_repo, local_src, "./foo", &g_options));
}
void test_clone_nonetwork__local_bare(void)
{
g_options.bare = true;
- cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options));
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
}
void test_clone_nonetwork__fail_when_the_target_is_a_file(void)
{
cl_git_mkfile("./foo", "Bar!");
- cl_git_fail(git_clone(&g_repo, g_origin, "./foo", &g_options));
+ cl_git_fail(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
}
void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(void)
{
p_mkdir("./foo", GIT_DIR_MODE);
cl_git_mkfile("./foo/bar", "Baz!");
- cl_git_fail(git_clone(&g_repo, g_origin, "./foo", &g_options));
+ cl_git_fail(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+}
+
+void test_clone_nonetwork__custom_origin_name(void)
+{
+ git_remote *remote;
+
+ g_options.remote_name = "my_origin";
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_remote_load(&remote, g_repo, "my_origin"));
+
+ git_remote_free(remote);
+}
+
+void test_clone_nonetwork__custom_push_url(void)
+{
+ git_remote *remote;
+ const char *url = "http://example.com";
+
+ g_options.pushurl = url;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_remote_load(&remote, g_repo, "origin"));
+ cl_assert_equal_s(url, git_remote_pushurl(remote));
+
+ git_remote_free(remote);
+}
+
+void test_clone_nonetwork__custom_fetch_spec(void)
+{
+ git_remote *remote;
+ git_reference *master;
+ const git_refspec *actual_fs;
+ const char *spec = "+refs/heads/master:refs/heads/foo";
+
+ g_options.fetch_spec = spec;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_remote_load(&remote, g_repo, "origin"));
+ actual_fs = git_remote_fetchspec(remote);
+ cl_assert_equal_s("refs/heads/master", git_refspec_src(actual_fs));
+ cl_assert_equal_s("refs/heads/foo", git_refspec_dst(actual_fs));
+
+ cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/foo"));
+ git_reference_free(master);
+
+ git_remote_free(remote);
}
+
+void test_clone_nonetwork__custom_push_spec(void)
+{
+ git_remote *remote;
+ const git_refspec *actual_fs;
+ const char *spec = "+refs/heads/master:refs/heads/foo";
+
+ g_options.push_spec = spec;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_remote_load(&remote, g_repo, "origin"));
+ actual_fs = git_remote_pushspec(remote);
+ cl_assert_equal_s("refs/heads/master", git_refspec_src(actual_fs));
+ cl_assert_equal_s("refs/heads/foo", git_refspec_dst(actual_fs));
+
+ git_remote_free(remote);
+}
+
+void test_clone_nonetwork__custom_autotag(void)
+{
+ git_strarray tags = {0};
+
+ g_options.remote_autotag = GIT_REMOTE_DOWNLOAD_TAGS_NONE;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_tag_list(&tags, g_repo));
+ cl_assert_equal_i(0, tags.count);
+}
+
+void test_clone_nonetwork__cope_with_already_existing_directory(void)
+{
+ p_mkdir("./foo", GIT_DIR_MODE);
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+}
+
+void test_clone_nonetwork__can_prevent_the_checkout_of_a_standard_repo(void)
+{
+ git_buf path = GIT_BUF_INIT;
+
+ g_options.checkout_opts.checkout_strategy = 0;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./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);
+}
+
diff --git a/tests-clar/network/fetchlocal.c b/tests-clar/network/fetchlocal.c
index 018531c5c..24949243e 100644
--- a/tests-clar/network/fetchlocal.c
+++ b/tests-clar/network/fetchlocal.c
@@ -21,7 +21,7 @@ void test_network_fetchlocal__complete(void)
const char *url = cl_git_fixture_url("testrepo.git");
cl_git_pass(git_repository_init(&repo, "foo", true));
- cl_git_pass(git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, url));
+ cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin, transfer_cb, &callcount));
cl_git_pass(git_remote_update_tips(origin));
@@ -47,7 +47,7 @@ void test_network_fetchlocal__partial(void)
cl_assert_equal_i(1, (int)refnames.count);
url = cl_git_fixture_url("testrepo.git");
- cl_git_pass(git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, url));
+ cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin, transfer_cb, &callcount));
cl_git_pass(git_remote_update_tips(origin));
diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remotelocal.c
index 8376b8bf1..5d6a16a2a 100644
--- a/tests-clar/network/remotelocal.c
+++ b/tests-clar/network/remotelocal.c
@@ -50,7 +50,7 @@ static void connect_to_local_repository(const char *local_repository)
{
git_buf_sets(&file_path_buf, cl_git_path_url(local_repository));
- cl_git_pass(git_remote_new(&remote, repo, NULL, git_buf_cstr(&file_path_buf), NULL));
+ cl_git_pass(git_remote_create_inmemory(&remote, repo, NULL, git_buf_cstr(&file_path_buf)));
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
}
diff --git a/tests-clar/network/remoterename.c b/tests-clar/network/remoterename.c
index bd582314d..24cfadcc3 100644
--- a/tests-clar/network/remoterename.c
+++ b/tests-clar/network/remoterename.c
@@ -148,46 +148,6 @@ void test_network_remoterename__cannot_overwrite_an_existing_remote(void)
cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(_remote, "test_with_pushurl", dont_call_me_cb, NULL));
}
-void test_network_remoterename__renaming_an_inmemory_remote_persists_it(void)
-{
- git_remote *remote;
-
- assert_config_entry_existence(_repo, "remote.durable.url", false);
-
- cl_git_pass(git_remote_new(&remote, _repo, NULL, "git://github.com/libgit2/durable.git", NULL));
-
- assert_config_entry_existence(_repo, "remote.durable.url", false);
-
- cl_git_pass(git_remote_rename(remote, "durable", dont_call_me_cb, NULL));
-
- assert_config_entry_value(_repo, "remote.durable.url", "git://github.com/libgit2/durable.git");
-
- git_remote_free(remote);
-}
-
-void test_network_remoterename__renaming_an_inmemory_nameless_remote_notifies_the_inability_to_update_the_fetch_refspec(void)
-{
- git_remote *remote;
-
- char *expected_refspecs[] = {
- "+refs/heads/*:refs/remotes/volatile/*",
- NULL
- };
-
- assert_config_entry_existence(_repo, "remote.volatile.url", false);
-
- cl_git_pass(git_remote_new(
- &remote,
- _repo,
- NULL,
- "git://github.com/libgit2/volatile.git",
- "+refs/heads/*:refs/remotes/volatile/*"));
-
- cl_git_pass(git_remote_rename(remote, "durable", ensure_refspecs, &expected_refspecs));
-
- git_remote_free(remote);
-}
-
void test_network_remoterename__renaming_a_remote_moves_the_underlying_reference(void)
{
git_reference *underlying;
@@ -202,3 +162,13 @@ void test_network_remoterename__renaming_a_remote_moves_the_underlying_reference
cl_git_pass(git_reference_lookup(&underlying, _repo, "refs/remotes/just/renamed/master"));
git_reference_free(underlying);
}
+
+void test_network_remoterename__cannot_rename_an_inmemory_remote(void)
+{
+ git_remote *remote;
+
+ cl_git_pass(git_remote_create_inmemory(&remote, _repo, NULL, "file:///blah"));
+ cl_git_fail(git_remote_rename(remote, "newname", NULL, NULL));
+
+ git_remote_free(remote);
+}
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index 651cbefec..e947ffe93 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -108,7 +108,7 @@ void test_network_remotes__save(void)
_remote = NULL;
/* Set up the remote and save it to config */
- cl_git_pass(git_remote_new(&_remote, _repo, "upstream", "git://github.com/libgit2/libgit2", NULL));
+ cl_git_pass(git_remote_create(&_remote, _repo, "upstream", "git://github.com/libgit2/libgit2"));
cl_git_pass(git_remote_set_fetchspec(_remote, "refs/heads/*:refs/remotes/upstream/*"));
cl_git_pass(git_remote_set_pushspec(_remote, "refs/heads/*:refs/heads/*"));
cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/libgit2_push"));
@@ -123,7 +123,7 @@ void test_network_remotes__save(void)
cl_assert(_refspec != NULL);
cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/upstream/*");
- cl_assert(git_refspec_force(_refspec) == 0);
+ cl_assert_equal_i(0, git_refspec_force(_refspec));
_refspec = git_remote_pushspec(_remote);
cl_assert(_refspec != NULL);
@@ -229,7 +229,7 @@ void test_network_remotes__add(void)
git_remote_free(_remote);
_remote = NULL;
- cl_git_pass(git_remote_add(&_remote, _repo, "addtest", "http://github.com/libgit2/libgit2"));
+ cl_git_pass(git_remote_create(&_remote, _repo, "addtest", "http://github.com/libgit2/libgit2"));
git_remote_free(_remote);
_remote = NULL;
@@ -248,16 +248,18 @@ void test_network_remotes__cannot_add_a_nameless_remote(void)
cl_assert_equal_i(
GIT_EINVALIDSPEC,
- git_remote_add(&remote, _repo, NULL, "git://github.com/libgit2/libgit2"));
+ git_remote_create(&remote, _repo, NULL, "git://github.com/libgit2/libgit2"));
}
-void test_network_remotes__cannot_save_a_nameless_remote(void)
+void test_network_remotes__cannot_save_an_inmemory_remote(void)
{
git_remote *remote;
- cl_git_pass(git_remote_new(&remote, _repo, NULL, "git://github.com/libgit2/libgit2", NULL));
+ cl_git_pass(git_remote_create_inmemory(&remote, _repo, NULL, "git://github.com/libgit2/libgit2"));
- cl_assert_equal_i(GIT_EINVALIDSPEC, git_remote_save(remote));
+ cl_assert_equal_p(NULL, git_remote_name(remote));
+
+ cl_git_fail(git_remote_save(remote));
git_remote_free(remote);
}
@@ -267,27 +269,12 @@ void test_network_remotes__cannot_add_a_remote_with_an_invalid_name(void)
cl_assert_equal_i(
GIT_EINVALIDSPEC,
- git_remote_add(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2"));
+ git_remote_create(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2"));
cl_assert_equal_p(remote, NULL);
cl_assert_equal_i(
GIT_EINVALIDSPEC,
- git_remote_add(&remote, _repo, "", "git://github.com/libgit2/libgit2"));
- cl_assert_equal_p(remote, NULL);
-}
-
-void test_network_remotes__cannot_initialize_a_remote_with_an_invalid_name(void)
-{
- git_remote *remote = NULL;
-
- cl_assert_equal_i(
- GIT_EINVALIDSPEC,
- git_remote_new(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2", NULL));
- cl_assert_equal_p(remote, NULL);
-
- cl_assert_equal_i(
- GIT_EINVALIDSPEC,
- git_remote_new(&remote, _repo, "", "git://github.com/libgit2/libgit2", NULL));
+ git_remote_create(&remote, _repo, "", "git://github.com/libgit2/libgit2"));
cl_assert_equal_p(remote, NULL);
}
@@ -331,7 +318,7 @@ void test_network_remotes__check_structure_version(void)
git_remote_free(_remote);
_remote = NULL;
- cl_git_pass(git_remote_new(&_remote, _repo, NULL, "test-protocol://localhost", NULL));
+ cl_git_pass(git_remote_create_inmemory(&_remote, _repo, NULL, "test-protocol://localhost"));
transport.version = 0;
cl_git_fail(git_remote_set_transport(_remote, &transport));
@@ -345,19 +332,13 @@ void test_network_remotes__check_structure_version(void)
cl_assert_equal_i(GITERR_INVALID, err->klass);
}
-void test_network_remotes__dangling(void)
+void test_network_remotes__cannot_create_a_remote_which_name_conflicts_with_an_existing_remote(void)
{
- git_remote_free(_remote);
- _remote = NULL;
-
- cl_git_pass(git_remote_new(&_remote, NULL, "upstream", "git://github.com/libgit2/libgit2", NULL));
-
- cl_git_pass(git_remote_rename(_remote, "newname", NULL, NULL));
- cl_assert_equal_s(git_remote_name(_remote), "newname");
+ git_remote *remote = NULL;
- cl_git_fail(git_remote_save(_remote));
- cl_git_fail(git_remote_update_tips(_remote));
+ cl_assert_equal_i(
+ GIT_EEXISTS,
+ git_remote_create(&remote, _repo, "test", "git://github.com/libgit2/libgit2"));
- cl_git_pass(git_remote_set_repository(_remote, _repo));
- cl_git_pass(git_remote_save(_remote));
+ cl_assert_equal_p(remote, NULL);
}
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 */