diff options
author | Vicent Marti <tanoku@gmail.com> | 2013-01-03 07:24:12 +0400 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2013-01-03 07:24:12 +0400 |
commit | 7761ce21625564b6526b89326c14a9843a1403d4 (patch) | |
tree | 7982836b366da36a70017d8ce15856e08d7d27a2 /tests-clar/clone | |
parent | 4236164a77b57c42641530a523590a913ba299f9 (diff) | |
parent | 922dd9788cfec2ec4727e1b264a2ad6a7f4849ba (diff) |
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/clone')
-rw-r--r-- | tests-clar/clone/empty.c | 22 | ||||
-rw-r--r-- | tests-clar/clone/nonetwork.c | 125 |
2 files changed, 111 insertions, 36 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); +} + |