Example #1
0
void test_network_remotes__save(void)
{
	git_remote_free(_remote);

	/* 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_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_save(_remote));
	git_remote_free(_remote);
	_remote = NULL;

	/* Load it from config and make sure everything matches */
	cl_git_pass(git_remote_load(&_remote, _repo, "upstream"));

	_refspec = git_remote_fetchspec(_remote);
	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/*");

	_refspec = git_remote_pushspec(_remote);
	cl_assert(_refspec != NULL);
	cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
	cl_assert_equal_s(git_refspec_dst(_refspec), "refs/heads/*");
}
Example #2
0
void test_network_remotes__set_fetchspec(void)
{
	cl_git_pass(git_remote_set_fetchspec(_remote, "refs/*:refs/*"));
	_refspec = git_remote_fetchspec(_remote);
	cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
	cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
}
Example #3
0
int
Remote_fetchspec__set__(Remote *self, PyObject* py_tuple)
{
    int err;
    size_t length = 0;
    char* src = NULL, *dst = NULL, *buf = NULL;

    if (!PyArg_ParseTuple(py_tuple, "ss", &src, &dst))
        return -1;

    /* length is strlen('+' + src + ':' + dst) and Null-Byte */
    length = strlen(src) + strlen(dst) + 3;
    buf = (char*) calloc(length, sizeof(char));
    if (buf != NULL) {
        sprintf(buf, "+%s:%s", src, dst);
        err = git_remote_set_fetchspec(self->remote, buf);
        free(buf);

        if (err == GIT_OK)
            return 0;

        Error_set_exc(PyExc_ValueError);
    }

    return -1;
}
Example #4
0
static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fetchhead)
{
	git_remote *remote;
	git_buf fetchhead_buf = GIT_BUF_INIT;
	int equals = 0;

	cl_git_pass(git_remote_load(&remote, g_repo, "origin"));
	git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);

	if(fetchspec != NULL)
		git_remote_set_fetchspec(remote, fetchspec);

	cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
	cl_git_pass(git_remote_download(remote, NULL, NULL));
	cl_git_pass(git_remote_update_tips(remote));
	git_remote_disconnect(remote);
	git_remote_free(remote);

	cl_git_pass(git_futils_readbuffer(&fetchhead_buf, "./foo/.git/FETCH_HEAD"));

	equals = (strcmp(fetchhead_buf.ptr, expected_fetchhead) == 0);

	git_buf_free(&fetchhead_buf);

	cl_assert(equals);
}
Example #5
0
void test_refs_branches_remote__ambiguous_remote_returns_error(void)
{
	git_remote *remote;

	/* Create the remote */
	cl_git_pass(git_remote_create(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2"));

	/* Update the remote fetch spec */
	cl_git_pass(git_remote_set_fetchspec(remote, "refs/heads/*:refs/remotes/test/*"));
	cl_git_pass(git_remote_save(remote));

	git_remote_free(remote);

	cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo,
		remote_tracking_branch_name), GIT_EAMBIGUOUS);
}
Example #6
0
static int create_and_configure_origin(
		git_remote **out,
		git_repository *repo,
		const char *url,
		const git_clone_options *options)
{
	int error;
	git_remote *origin = NULL;

	if ((error = git_remote_create(&origin, repo, options->remote_name, url)) < 0)
		goto on_error;

	git_remote_set_cred_acquire_cb(origin, options->cred_acquire_cb,
			options->cred_acquire_payload);
	git_remote_set_autotag(origin, options->remote_autotag);
	/*
	 * Don't write FETCH_HEAD, we'll check out the remote tracking
	 * branch ourselves based on the server's default.
	 */
	git_remote_set_update_fetchhead(origin, 0);

	if (options->remote_callbacks &&
	    (error = git_remote_set_callbacks(origin, options->remote_callbacks)) < 0)
		goto on_error;

	if (options->fetch_spec &&
	    (error = git_remote_set_fetchspec(origin, options->fetch_spec)) < 0)
		goto on_error;

	if (options->push_spec &&
	    (error = git_remote_set_pushspec(origin, options->push_spec)) < 0)
		goto on_error;

	if (options->pushurl &&
	    (error = git_remote_set_pushurl(origin, options->pushurl)) < 0)
		goto on_error;

	if ((error = git_remote_save(origin)) < 0)
		goto on_error;

	*out = origin;
	return 0;

on_error:
	git_remote_free(origin);
	return error;
}