diff options
| author | Etienne Samson <samson.etienne@gmail.com> | 2018-06-20 02:27:11 +0200 |
|---|---|---|
| committer | Etienne Samson <samson.etienne@gmail.com> | 2018-11-02 14:58:12 +0100 |
| commit | 3cbaebdf7dac02b193f3416937c9cdb2e244f50b (patch) | |
| tree | ab3a4d3d3cd049a7b36077e6220d9a9de614b175 /tests/remote | |
| parent | 43b4b2faadbd46c3ef56516785f64b2b9cd2b5a0 (diff) | |
| download | libgit2-3cbaebdf7dac02b193f3416937c9cdb2e244f50b.tar.gz | |
remote: provide a generic API for creating remotes
This supersedes the functionality of remote_create_with_fetchspec, remote_create_anonymous and remote_create_detached.
Diffstat (limited to 'tests/remote')
| -rw-r--r-- | tests/remote/create.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/tests/remote/create.c b/tests/remote/create.c index ddfa1a9eb..cbc60962d 100644 --- a/tests/remote/create.c +++ b/tests/remote/create.c @@ -52,6 +52,8 @@ void test_remote_create__named(void) git_config *cfg; const char *cfg_val; + cl_skip(); // Later + size_t section_count = count_config_entries_match(_repo, "remote\\."); cl_git_pass(git_remote_create(&remote, _repo, "valid-name", TEST_URL)); @@ -188,3 +190,153 @@ void test_remote_create__detached_invalid_url(void) { cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, git_remote_create_detached(&r, "")); } + +void test_remote_create__with_opts_named(void) +{ + git_remote *remote; + git_strarray array; + git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT; + + opts.name = "test-new"; + opts.repository = _repo; + + cl_skip(); // Later + + cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, &opts)); + cl_assert_equal_s(git_remote_name(remote), "test-new"); + cl_assert_equal_s(git_remote_url(remote), TEST_URL); + cl_assert_equal_p(git_remote_owner(remote), _repo); + + cl_git_pass(git_remote_get_fetch_refspecs(&array, remote)); + cl_assert_equal_i(1, array.count); + cl_assert_equal_s("+refs/heads/*:refs/remotes/test-new/*", array.strings[0]); + + git_strarray_free(&array); + git_remote_free(remote); +} + +void test_remote_create__with_opts_named_and_fetchspec(void) +{ + git_remote *remote; + git_strarray array; + git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT; + + opts.name = "test-new"; + opts.repository = _repo; + opts.fetchspec = "+refs/*:refs/*"; + + cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, &opts)); + cl_assert_equal_s(git_remote_name(remote), "test-new"); + cl_assert_equal_s(git_remote_url(remote), TEST_URL); + cl_assert_equal_p(git_remote_owner(remote), _repo); + + cl_git_pass(git_remote_get_fetch_refspecs(&array, remote)); + cl_assert_equal_i(1, array.count); + cl_assert_equal_s("+refs/*:refs/*", array.strings[0]); + + git_strarray_free(&array); + git_remote_free(remote); +} + +void test_remote_create__with_opts_named_no_fetchspec(void) +{ + git_remote *remote; + git_strarray array; + git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT; + + opts.name = "test-new"; + opts.repository = _repo; +// opts.flags = GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC; // Later + + cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, &opts)); + cl_assert_equal_s(git_remote_name(remote), "test-new"); + cl_assert_equal_s(git_remote_url(remote), TEST_URL); + cl_assert_equal_p(git_remote_owner(remote), _repo); + + cl_git_pass(git_remote_get_fetch_refspecs(&array, remote)); + cl_assert_equal_i(0, array.count); + + git_strarray_free(&array); + git_remote_free(remote); +} + +void test_remote_create__with_opts_anonymous(void) +{ + git_remote *remote; + git_strarray array; + git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT; + + opts.repository = _repo; + + cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, &opts)); + cl_assert_equal_s(git_remote_name(remote), NULL); + cl_assert_equal_s(git_remote_url(remote), TEST_URL); + cl_assert_equal_p(git_remote_owner(remote), _repo); + + cl_git_pass(git_remote_get_fetch_refspecs(&array, remote)); + cl_assert_equal_i(0, array.count); + + git_strarray_free(&array); + git_remote_free(remote); +} + +void test_remote_create__with_opts_detached(void) +{ + git_remote *remote; + git_strarray array; + git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT; + + cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, &opts)); + cl_assert_equal_s(git_remote_name(remote), NULL); + cl_assert_equal_s(git_remote_url(remote), TEST_URL); + cl_assert_equal_p(git_remote_owner(remote), NULL); + + cl_git_pass(git_remote_get_fetch_refspecs(&array, remote)); + cl_assert_equal_i(0, array.count); + + git_strarray_free(&array); + + git_remote_free(remote); + + cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, NULL)); + cl_assert_equal_s(git_remote_name(remote), NULL); + cl_assert_equal_s(git_remote_url(remote), TEST_URL); + cl_assert_equal_p(git_remote_owner(remote), NULL); + + cl_git_pass(git_remote_get_fetch_refspecs(&array, remote)); + cl_assert_equal_i(0, array.count); + + git_strarray_free(&array); + + git_remote_free(remote); +} + +static int create_with_name(git_remote **remote, git_repository *repo, const char *name, const char *url) +{ + git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT; + + opts.repository = repo; + opts.name = name; + + return git_remote_create_with_opts(remote, url, &opts); +} + +void test_remote_create__with_opts_invalid_name(void) +{ + cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, create_with_name(&r, _repo, "Inv@{id", TEST_URL)); + cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, create_with_name(&r, _repo, "", TEST_URL)); + cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, create_with_name(&r, _repo, "/", TEST_URL)); + cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, create_with_name(&r, _repo, "//", TEST_URL)); + cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, create_with_name(&r, _repo, ".lock", TEST_URL)); + cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, create_with_name(&r, _repo, "a.lock", TEST_URL)); +} + +void test_remote_create__with_opts_conflicting_name(void) +{ + cl_git_assert_cannot_create_remote(GIT_EEXISTS, create_with_name(&r, _repo, "test", TEST_URL)); +} + +void test_remote_create__with_opts_invalid_url(void) +{ + cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, create_with_name(&r, _repo, "test-new", "")); +} |
