Blame tests/network/remote/remotes.c

Packit Service 20376f
#include "clar_libgit2.h"
Packit Service 20376f
#include "config/config_helpers.h"
Packit Service 20376f
#include "buffer.h"
Packit Service 20376f
#include "refspec.h"
Packit Service 20376f
#include "remote.h"
Packit Service 20376f
Packit Service 20376f
static git_remote *_remote;
Packit Service 20376f
static git_repository *_repo;
Packit Service 20376f
static const git_refspec *_refspec;
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__initialize(void)
Packit Service 20376f
{
Packit Service 20376f
	_repo = cl_git_sandbox_init("testrepo.git");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));
Packit Service 20376f
Packit Service 20376f
	_refspec = git_remote_get_refspec(_remote, 0);
Packit Service 20376f
	cl_assert(_refspec != NULL);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__cleanup(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote_free(_remote);
Packit Service 20376f
	_remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_git_sandbox_cleanup();
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__parsing(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *_remote2 = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_s(git_remote_name(_remote), "test");
Packit Service 20376f
	cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
Packit Service 20376f
	cl_assert(git_remote_pushurl(_remote) == NULL);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIRECTION_FETCH),
Packit Service 20376f
					  "git://github.com/libgit2/libgit2");
Packit Service 20376f
	cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIRECTION_PUSH),
Packit Service 20376f
					  "git://github.com/libgit2/libgit2");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&_remote2, _repo, "test_with_pushurl"));
Packit Service 20376f
	cl_assert_equal_s(git_remote_name(_remote2), "test_with_pushurl");
Packit Service 20376f
	cl_assert_equal_s(git_remote_url(_remote2), "git://github.com/libgit2/fetchlibgit2");
Packit Service 20376f
	cl_assert_equal_s(git_remote_pushurl(_remote2), "git://github.com/libgit2/pushlibgit2");
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIRECTION_FETCH),
Packit Service 20376f
					  "git://github.com/libgit2/fetchlibgit2");
Packit Service 20376f
	cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIRECTION_PUSH),
Packit Service 20376f
					  "git://github.com/libgit2/pushlibgit2");
Packit Service 20376f
Packit Service 20376f
	git_remote_free(_remote2);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__pushurl(void)
Packit Service 20376f
{
Packit Service 20376f
	const char *name = git_remote_name(_remote);
Packit Service 20376f
	git_remote *mod;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_set_pushurl(_repo, name, "git://github.com/libgit2/notlibgit2"));
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&mod, _repo, name));
Packit Service 20376f
	cl_assert_equal_s(git_remote_pushurl(mod), "git://github.com/libgit2/notlibgit2");
Packit Service 20376f
	git_remote_free(mod);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_set_pushurl(_repo, name, NULL));
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&mod, _repo, name));
Packit Service 20376f
	cl_assert(git_remote_pushurl(mod) == NULL);
Packit Service 20376f
	git_remote_free(mod);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__error_when_not_found(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *r;
Packit Service 20376f
	cl_git_fail_with(git_remote_lookup(&r, _repo, "does-not-exist"), GIT_ENOTFOUND);
Packit Service 20376f
Packit Service 20376f
	cl_assert(giterr_last() != NULL);
Packit Service 20376f
	cl_assert(giterr_last()->klass == GITERR_CONFIG);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__error_when_no_push_available(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *r;
Packit Service 20376f
	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
Packit Service 20376f
	char *specs = {
Packit Service 20376f
		"refs/heads/master",
Packit Service 20376f
	};
Packit Service 20376f
	git_strarray arr = {
Packit Service 20376f
		&specs,
Packit Service 20376f
		1,
Packit Service 20376f
	};
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_create_anonymous(&r, _repo, cl_fixture("testrepo.git")));
Packit Service 20376f
Packit Service 20376f
	callbacks.transport = git_transport_local;
Packit Service 20376f
	cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH, &callbacks, NULL, NULL));
Packit Service 20376f
Packit Service 20376f
	/* Make sure that push is really not available */
Packit Service 20376f
	r->transport->push = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(-1, git_remote_upload(r, &arr, NULL));
Packit Service 20376f
Packit Service 20376f
	git_remote_free(r);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__refspec_parsing(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
Packit Service 20376f
	cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/test/*");
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__add_fetchspec(void)
Packit Service 20376f
{
Packit Service 20376f
	size_t size;
Packit Service 20376f
Packit Service 20376f
	size = git_remote_refspec_count(_remote);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_add_fetch(_repo, "test", "refs/*:refs/*"));
Packit Service 20376f
	size++;
Packit Service 20376f
Packit Service 20376f
	git_remote_free(_remote);
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i((int)size, (int)git_remote_refspec_count(_remote));
Packit Service 20376f
Packit Service 20376f
	_refspec = git_remote_get_refspec(_remote, size - 1);
Packit Service 20376f
	cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
Packit Service 20376f
	cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
Packit Service 20376f
	cl_assert_equal_s(git_refspec_string(_refspec), "refs/*:refs/*");
Packit Service 20376f
	cl_assert_equal_b(_refspec->push, false);
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(GIT_EINVALIDSPEC, git_remote_add_fetch(_repo, "test", "refs/*/foo/*:refs/*"));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__dup(void)
Packit Service 20376f
{
Packit Service 20376f
	git_strarray array;
Packit Service 20376f
	git_remote *dup;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_dup(&dup, _remote));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_s(git_remote_name(dup), git_remote_name(_remote));
Packit Service 20376f
	cl_assert_equal_s(git_remote_url(dup), git_remote_url(_remote));
Packit Service 20376f
	cl_assert_equal_s(git_remote_pushurl(dup), git_remote_pushurl(_remote));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_get_fetch_refspecs(&array, _remote));
Packit Service 20376f
	cl_assert_equal_i(1, (int)array.count);
Packit Service 20376f
	cl_assert_equal_s("+refs/heads/*:refs/remotes/test/*", array.strings[0]);
Packit Service 20376f
	git_strarray_free(&array);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_get_push_refspecs(&array, _remote));
Packit Service 20376f
	cl_assert_equal_i(0, (int)array.count);
Packit Service 20376f
	git_strarray_free(&array);
Packit Service 20376f
Packit Service 20376f
	git_remote_free(dup);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__add_pushspec(void)
Packit Service 20376f
{
Packit Service 20376f
	size_t size;
Packit Service 20376f
Packit Service 20376f
	size = git_remote_refspec_count(_remote);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_add_push(_repo, "test", "refs/*:refs/*"));
Packit Service 20376f
	size++;
Packit Service 20376f
Packit Service 20376f
	git_remote_free(_remote);
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i((int)size, (int)git_remote_refspec_count(_remote));
Packit Service 20376f
Packit Service 20376f
	_refspec = git_remote_get_refspec(_remote, size - 1);
Packit Service 20376f
	cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
Packit Service 20376f
	cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
Packit Service 20376f
	cl_assert_equal_s(git_refspec_string(_refspec), "refs/*:refs/*");
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_b(_refspec->push, true);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__fnmatch(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_assert(git_refspec_src_matches(_refspec, "refs/heads/master"));
Packit Service 20376f
	cl_assert(git_refspec_src_matches(_refspec, "refs/heads/multi/level/branch"));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__transform(void)
Packit Service 20376f
{
Packit Service 20376f
	git_buf ref = GIT_BUF_INIT;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_refspec_transform(&ref, _refspec, "refs/heads/master"));
Packit Service 20376f
	cl_assert_equal_s(ref.ptr, "refs/remotes/test/master");
Packit Service 20376f
	git_buf_free(&ref;;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__transform_destination_to_source(void)
Packit Service 20376f
{
Packit Service 20376f
	git_buf ref = GIT_BUF_INIT;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_refspec_rtransform(&ref, _refspec, "refs/remotes/test/master"));
Packit Service 20376f
	cl_assert_equal_s(ref.ptr, "refs/heads/master");
Packit Service 20376f
	git_buf_free(&ref;;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__missing_refspecs(void)
Packit Service 20376f
{
Packit Service 20376f
	git_config *cfg;
Packit Service 20376f
Packit Service 20376f
	git_remote_free(_remote);
Packit Service 20376f
	_remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_config(&cfg, _repo));
Packit Service 20376f
	cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&_remote, _repo, "specless"));
Packit Service 20376f
Packit Service 20376f
	git_config_free(cfg);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__nonmatch_upstream_refspec(void)
Packit Service 20376f
{
Packit Service 20376f
	git_config *config;
Packit Service 20376f
	git_remote *remote;
Packit Service 20376f
	char *specstr[] = {
Packit Service 20376f
		"refs/tags/*:refs/tags/*",
Packit Service 20376f
	};
Packit Service 20376f
	git_strarray specs = {
Packit Service 20376f
		specstr,
Packit Service 20376f
		1,
Packit Service 20376f
	};
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_create(&remote, _repo, "taggy", git_repository_path(_repo)));
Packit Service 20376f
Packit Service 20376f
	/*
Packit Service 20376f
	 * Set the current branch's upstream remote to a dummy ref so we call into the code
Packit Service 20376f
	 * which tries to check for the current branch's upstream in the refspecs
Packit Service 20376f
	 */
Packit Service 20376f
	cl_git_pass(git_repository_config(&config, _repo));
Packit Service 20376f
	cl_git_pass(git_config_set_string(config, "branch.master.remote", "taggy"));
Packit Service 20376f
	cl_git_pass(git_config_set_string(config, "branch.master.merge", "refs/heads/foo"));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_fetch(remote, &specs, NULL, NULL));
Packit Service 20376f
Packit Service 20376f
	git_remote_free(remote);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__list(void)
Packit Service 20376f
{
Packit Service 20376f
	git_strarray list;
Packit Service 20376f
	git_config *cfg;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_list(&list, _repo));
Packit Service 20376f
	cl_assert(list.count == 5);
Packit Service 20376f
	git_strarray_free(&list);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_config(&cfg, _repo));
Packit Service 20376f
Packit Service 20376f
	/* Create a new remote */
Packit Service 20376f
	cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
Packit Service 20376f
Packit Service 20376f
	/* Update a remote (previously without any url/pushurl entry) */
Packit Service 20376f
	cl_git_pass(git_config_set_string(cfg, "remote.no-remote-url.pushurl", "http://example.com"));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_list(&list, _repo));
Packit Service 20376f
	cl_assert(list.count == 7);
Packit Service 20376f
	git_strarray_free(&list);
Packit Service 20376f
Packit Service 20376f
	git_config_free(cfg);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__loading_a_missing_remote_returns_ENOTFOUND(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote_free(_remote);
Packit Service 20376f
	_remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(GIT_ENOTFOUND, git_remote_lookup(&_remote, _repo, "just-left-few-minutes-ago"));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__loading_with_an_invalid_name_returns_EINVALIDSPEC(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote_free(_remote);
Packit Service 20376f
	_remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(GIT_EINVALIDSPEC, git_remote_lookup(&_remote, _repo, "Inv@{id"));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * $ git remote add addtest http://github.com/libgit2/libgit2
Packit Service 20376f
 *
Packit Service 20376f
 * $ cat .git/config
Packit Service 20376f
 * [...]
Packit Service 20376f
 * [remote "addtest"]
Packit Service 20376f
 *         url = http://github.com/libgit2/libgit2
Packit Service 20376f
 *         fetch = +refs/heads/\*:refs/remotes/addtest/\*
Packit Service 20376f
 */
Packit Service 20376f
void test_network_remote_remotes__add(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote_free(_remote);
Packit Service 20376f
	_remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_create(&_remote, _repo, "addtest", "http://github.com/libgit2/libgit2"));
Packit Service 20376f
	cl_assert_equal_i(GIT_REMOTE_DOWNLOAD_TAGS_AUTO, git_remote_autotag(_remote));
Packit Service 20376f
Packit Service 20376f
	git_remote_free(_remote);
Packit Service 20376f
	_remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&_remote, _repo, "addtest"));
Packit Service 20376f
	cl_assert_equal_i(GIT_REMOTE_DOWNLOAD_TAGS_AUTO, git_remote_autotag(_remote));
Packit Service 20376f
Packit Service 20376f
	_refspec = git_vector_get(&_remote->refspecs, 0);
Packit Service 20376f
	cl_assert_equal_s("refs/heads/*", git_refspec_src(_refspec));
Packit Service 20376f
	cl_assert(git_refspec_force(_refspec) == 1);
Packit Service 20376f
	cl_assert_equal_s("refs/remotes/addtest/*", git_refspec_dst(_refspec));
Packit Service 20376f
	cl_assert_equal_s(git_remote_url(_remote), "http://github.com/libgit2/libgit2");
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__cannot_add_a_nameless_remote(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *remote;
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(
Packit Service 20376f
		GIT_EINVALIDSPEC,
Packit Service 20376f
		git_remote_create(&remote, _repo, NULL, "git://github.com/libgit2/libgit2"));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__cannot_add_a_remote_with_an_invalid_name(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(
Packit Service 20376f
		GIT_EINVALIDSPEC,
Packit Service 20376f
		git_remote_create(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2"));
Packit Service 20376f
	cl_assert_equal_p(remote, NULL);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(
Packit Service 20376f
		GIT_EINVALIDSPEC,
Packit Service 20376f
		git_remote_create(&remote, _repo, "", "git://github.com/libgit2/libgit2"));
Packit Service 20376f
	cl_assert_equal_p(remote, NULL);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__tagopt(void)
Packit Service 20376f
{
Packit Service 20376f
	const char *name = git_remote_name(_remote);
Packit Service 20376f
Packit Service 20376f
	git_remote_set_autotag(_repo, name, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
Packit Service 20376f
	assert_config_entry_value(_repo, "remote.test.tagopt", "--tags");
Packit Service 20376f
Packit Service 20376f
	git_remote_set_autotag(_repo, name, GIT_REMOTE_DOWNLOAD_TAGS_NONE);
Packit Service 20376f
	assert_config_entry_value(_repo, "remote.test.tagopt", "--no-tags");
Packit Service 20376f
Packit Service 20376f
	git_remote_set_autotag(_repo, name, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
Packit Service 20376f
	assert_config_entry_existence(_repo, "remote.test.tagopt", false);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__can_load_with_an_empty_url(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&remote, _repo, "empty-remote-url"));
Packit Service 20376f
Packit Service 20376f
	cl_assert(remote->url == NULL);
Packit Service 20376f
	cl_assert(remote->pushurl == NULL);
Packit Service 20376f
Packit Service 20376f
	cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
Packit Service 20376f
Packit Service 20376f
	cl_assert(giterr_last() != NULL);
Packit Service 20376f
	cl_assert(giterr_last()->klass == GITERR_INVALID);
Packit Service 20376f
Packit Service 20376f
	git_remote_free(remote);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__can_load_with_only_an_empty_pushurl(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&remote, _repo, "empty-remote-pushurl"));
Packit Service 20376f
Packit Service 20376f
	cl_assert(remote->url == NULL);
Packit Service 20376f
	cl_assert(remote->pushurl == NULL);
Packit Service 20376f
Packit Service 20376f
	cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
Packit Service 20376f
Packit Service 20376f
	git_remote_free(remote);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__returns_ENOTFOUND_when_neither_url_nor_pushurl(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(
Packit Service 20376f
		git_remote_lookup(&remote, _repo, "no-remote-url"), GIT_ENOTFOUND);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void assert_cannot_create_remote(const char *name, int expected_error)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *remote = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(
Packit Service 20376f
		git_remote_create(&remote, _repo, name, "git://github.com/libgit2/libgit2"),
Packit Service 20376f
		expected_error);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_p(remote, NULL);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__cannot_create_a_remote_which_name_conflicts_with_an_existing_remote(void)
Packit Service 20376f
{
Packit Service 20376f
	assert_cannot_create_remote("test", GIT_EEXISTS);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__cannot_create_a_remote_which_name_is_invalid(void)
Packit Service 20376f
{
Packit Service 20376f
	assert_cannot_create_remote("/", GIT_EINVALIDSPEC);
Packit Service 20376f
	assert_cannot_create_remote("//", GIT_EINVALIDSPEC);
Packit Service 20376f
	assert_cannot_create_remote(".lock", GIT_EINVALIDSPEC);
Packit Service 20376f
	assert_cannot_create_remote("a.lock", GIT_EINVALIDSPEC);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remote__git_remote_create_with_fetchspec(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *remote;
Packit Service 20376f
	git_strarray array;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "test-new", "git://github.com/libgit2/libgit2", "+refs/*:refs/*"));
Packit Service 20376f
	git_remote_get_fetch_refspecs(&array, remote);
Packit Service 20376f
	cl_assert_equal_s("+refs/*:refs/*", array.strings[0]);
Packit Service 20376f
	git_remote_free(remote);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static const char *fetch_refspecs[] = {
Packit Service 20376f
	"+refs/heads/*:refs/remotes/origin/*",
Packit Service 20376f
	"refs/tags/*:refs/tags/*",
Packit Service 20376f
	"+refs/pull/*:refs/pull/*",
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
static const char *push_refspecs[] = {
Packit Service 20376f
	"refs/heads/*:refs/heads/*",
Packit Service 20376f
	"refs/tags/*:refs/tags/*",
Packit Service 20376f
	"refs/notes/*:refs/notes/*",
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
void test_network_remote_remotes__query_refspecs(void)
Packit Service 20376f
{
Packit Service 20376f
	git_remote *remote;
Packit Service 20376f
	git_strarray array;
Packit Service 20376f
	int i;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "query", "git://github.com/libgit2/libgit2", NULL));
Packit Service 20376f
	git_remote_free(remote);
Packit Service 20376f
Packit Service 20376f
	for (i = 0; i < 3; i++) {
Packit Service 20376f
		cl_git_pass(git_remote_add_fetch(_repo, "query", fetch_refspecs[i]));
Packit Service 20376f
		cl_git_pass(git_remote_add_push(_repo, "query", push_refspecs[i]));
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_lookup(&remote, _repo, "query"));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
Packit Service 20376f
	for (i = 0; i < 3; i++) {
Packit Service 20376f
		cl_assert_equal_s(fetch_refspecs[i], array.strings[i]);
Packit Service 20376f
	}
Packit Service 20376f
	git_strarray_free(&array);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_remote_get_push_refspecs(&array, remote));
Packit Service 20376f
	for (i = 0; i < 3; i++) {
Packit Service 20376f
		cl_assert_equal_s(push_refspecs[i], array.strings[i]);
Packit Service 20376f
	}
Packit Service 20376f
	git_strarray_free(&array);
Packit Service 20376f
Packit Service 20376f
	git_remote_free(remote);
Packit Service 20376f
	git_remote_delete(_repo, "test");
Packit Service 20376f
}