Ejemplo n.º 1
0
void test_network_remote_remotes__query_refspecs(void)
{
	git_remote *remote;
	git_strarray array;
	int i;

	cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "query", "git://github.com/libgit2/libgit2", NULL));
	git_remote_free(remote);

	for (i = 0; i < 3; i++) {
		cl_git_pass(git_remote_add_fetch(_repo, "query", fetch_refspecs[i]));
		cl_git_pass(git_remote_add_push(_repo, "query", push_refspecs[i]));
	}

	cl_git_pass(git_remote_lookup(&remote, _repo, "query"));

	cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
	for (i = 0; i < 3; i++) {
		cl_assert_equal_s(fetch_refspecs[i], array.strings[i]);
	}
	git_strarray_free(&array);

	cl_git_pass(git_remote_get_push_refspecs(&array, remote));
	for (i = 0; i < 3; i++) {
		cl_assert_equal_s(push_refspecs[i], array.strings[i]);
	}
	git_strarray_free(&array);

	git_remote_free(remote);
	git_remote_delete(_repo, "test");
}
Ejemplo n.º 2
0
int git_remote_dup(git_remote **dest, git_remote *source)
{
	int error = 0;
	git_strarray refspecs = { 0 };
	git_remote *remote = git__calloc(1, sizeof(git_remote));
	GITERR_CHECK_ALLOC(remote);

	if (source->name != NULL) {
		remote->name = git__strdup(source->name);
		GITERR_CHECK_ALLOC(remote->name);
	}

	if (source->url != NULL) {
		remote->url = git__strdup(source->url);
		GITERR_CHECK_ALLOC(remote->url);		
	}

	if (source->pushurl != NULL) {
		remote->pushurl = git__strdup(source->pushurl);
		GITERR_CHECK_ALLOC(remote->pushurl);
	}

	remote->transport_cb = source->transport_cb;
	remote->transport_cb_payload = source->transport_cb_payload;
	remote->repo = source->repo;
	remote->download_tags = source->download_tags;
	remote->check_cert = source->check_cert;
	remote->update_fetchhead = source->update_fetchhead;

	if (git_vector_init(&remote->refs, 32, NULL) < 0 ||
	    git_vector_init(&remote->refspecs, 2, NULL) < 0 ||
	    git_vector_init(&remote->active_refspecs, 2, NULL) < 0) {
		error = -1;
		goto cleanup;
	}

	if ((error = git_remote_get_fetch_refspecs(&refspecs, source)) < 0 ||
	    (error = git_remote_set_fetch_refspecs(remote, &refspecs)) < 0)
		goto cleanup;

	git_strarray_free(&refspecs);

	if ((error = git_remote_get_push_refspecs(&refspecs, source)) < 0 ||
	    (error = git_remote_set_push_refspecs(remote, &refspecs)) < 0)
		goto cleanup;

	*dest = remote;

cleanup:

	git_strarray_free(&refspecs);

	if (error < 0)
		git__free(remote);

	return error;
}
Ejemplo n.º 3
0
PyObject *
Remote_push_refspecs__get__(Remote *self)
{
    int err;
    git_strarray refspecs;
    PyObject *new_list;

    err = git_remote_get_push_refspecs(&refspecs, self->remote);
    if (err != GIT_OK)
        return Error_set(err);

    new_list = get_pylist_from_git_strarray(&refspecs);

    git_strarray_free(&refspecs);
    return new_list;
}
Ejemplo n.º 4
0
emacs_value egit_remote_get_refspecs(emacs_env *env, emacs_value _remote, emacs_value dir)
{
    EGIT_ASSERT_REMOTE(_remote);
    git_remote *remote = EGIT_EXTRACT(_remote);

    git_strarray out = {NULL, 0};
    int retval;
    if (EM_EQ(dir, em_fetch))
        retval = git_remote_get_fetch_refspecs(&out, remote);
    else if (EM_EQ(dir, em_push))
        retval = git_remote_get_push_refspecs(&out, remote);
    else {
        em_signal_wrong_value(env, dir);
        return em_nil;
    }
    EGIT_CHECK_ERROR(retval);

    EGIT_RET_STRARRAY(out);
}
Ejemplo n.º 5
0
static VALUE rb_git_remote_refspecs(VALUE self, git_direction direction)
{
	git_remote *remote;
	int error = 0;
	git_strarray refspecs;
	VALUE rb_refspec_array;

	Data_Get_Struct(self, git_remote, remote);

	if (direction == GIT_DIRECTION_FETCH)
		error = git_remote_get_fetch_refspecs(&refspecs, remote);
	else
		error = git_remote_get_push_refspecs(&refspecs, remote);

	rugged_exception_check(error);

	rb_refspec_array = rugged_strarray_to_rb_ary(&refspecs);
	git_strarray_free(&refspecs);
	return rb_refspec_array;
}
Ejemplo n.º 6
0
void test_network_remote_remotes__dup(void)
{
	git_strarray array;
	git_remote *dup;

	cl_git_pass(git_remote_dup(&dup, _remote));

	cl_assert_equal_s(git_remote_name(dup), git_remote_name(_remote));
	cl_assert_equal_s(git_remote_url(dup), git_remote_url(_remote));
	cl_assert_equal_s(git_remote_pushurl(dup), git_remote_pushurl(_remote));

	cl_git_pass(git_remote_get_fetch_refspecs(&array, _remote));
	cl_assert_equal_i(1, (int)array.count);
	cl_assert_equal_s("+refs/heads/*:refs/remotes/test/*", array.strings[0]);
	git_strarray_free(&array);

	cl_git_pass(git_remote_get_push_refspecs(&array, _remote));
	cl_assert_equal_i(0, (int)array.count);
	git_strarray_free(&array);

	git_remote_free(dup);
}
Ejemplo n.º 7
0
/*
 *  call-seq:
 *    remote.push(refspecs = nil, options = {}) -> hash
 *
 *  Pushes the given +refspecs+ to the given +remote+. Returns a hash that contains
 *  key-value pairs that reflect pushed refs and error messages, if applicable.
 *
 *  The following options can be passed in the +options+ Hash:
 *
 *  :credentials ::
 *    The credentials to use for the push operation. Can be either an instance of one
 *    of the Rugged::Credentials types, or a proc returning one of the former.
 *    The proc will be called with the +url+, the +username+ from the url (if applicable) and
 *    a list of applicable credential types.
 *
 *  :message ::
 *    A single line log message to be appended to the reflog of each local remote-tracking
 *    branch that gets updated. Defaults to: "fetch".
 *
 *  :signature ::
 *    The signature to be used for populating the reflog entries.
 *
 *  Example:
 *
 *    remote = Rugged::Remote.lookup(@repo, 'origin')
 *    remote.push(["refs/heads/master", ":refs/heads/to_be_deleted"])
 */
static VALUE rb_git_remote_push(int argc, VALUE *argv, VALUE self)
{
	VALUE rb_refspecs, rb_options, rb_val;
	VALUE rb_repo = rugged_owner(self);
	VALUE rb_exception = Qnil, rb_result = rb_hash_new();

	git_repository *repo;
	git_remote *remote, *tmp_remote = NULL;
	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
	git_push *push = NULL;
	git_signature *signature = NULL;

	int error = 0, i = 0;
	char *log_message = NULL;

	struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, 0 };

	rb_scan_args(argc, argv, "01:", &rb_refspecs, &rb_options);

	if (!NIL_P(rb_refspecs)) {
		Check_Type(rb_refspecs, T_ARRAY);
		for (i = 0; i < RARRAY_LEN(rb_refspecs); ++i) {
			VALUE rb_refspec = rb_ary_entry(rb_refspecs, i);
			Check_Type(rb_refspec, T_STRING);
		}
	}

	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);
	Data_Get_Struct(self, git_remote, remote);

	if (!NIL_P(rb_options)) {
		rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);

		rb_val = rb_hash_aref(rb_options, CSTR2SYM("message"));
		if (!NIL_P(rb_val))
			log_message = StringValueCStr(rb_val);

		rb_val = rb_hash_aref(rb_options, CSTR2SYM("signature"));
		if (!NIL_P(rb_val))
			signature = rugged_signature_get(rb_val, repo);
	}

	// Create a temporary remote that we use for pushing
	if ((error = git_remote_dup(&tmp_remote, remote)) ||
	    (error = git_remote_set_callbacks(tmp_remote, &callbacks)))
	    goto cleanup;

	if (!NIL_P(rb_refspecs)) {
		git_remote_clear_refspecs(tmp_remote);

		for (i = 0; !error && i < RARRAY_LEN(rb_refspecs); ++i) {
			VALUE rb_refspec = rb_ary_entry(rb_refspecs, i);

			if ((error = git_remote_add_push(tmp_remote, StringValueCStr(rb_refspec))))
				goto cleanup;
		}
	}

	if ((error = git_push_new(&push, tmp_remote)))
		goto cleanup;

	// TODO: Get rid of this once git_remote_push lands in libgit2.
	{
		git_strarray push_refspecs;
		size_t i;

		if ((error = git_remote_get_push_refspecs(&push_refspecs, tmp_remote)))
			goto cleanup;

		if (push_refspecs.count == 0) {
			rb_exception = rb_exc_new2(rb_eRuggedError, "no pushspecs are configured for the given remote");
			goto cleanup;
		}

		for (i = 0; !error && i < push_refspecs.count; ++i) {
			error = git_push_add_refspec(push, push_refspecs.strings[i]);
		}

		git_strarray_free(&push_refspecs);
		if (error) goto cleanup;
	}

	if ((error = git_push_finish(push)))
		goto cleanup;

	if (!git_push_unpack_ok(push)) {
		rb_exception = rb_exc_new2(rb_eRuggedError, "the remote side did not unpack successfully");
		goto cleanup;
	}

	if ((error = git_push_status_foreach(push, &push_status_cb, (void *)rb_result)) ||
	    (error = git_push_update_tips(push, signature, log_message)))
	    goto cleanup;

cleanup:
	git_push_free(push);
	git_remote_free(tmp_remote);
	git_signature_free(signature);

	if (!NIL_P(rb_exception))
		rb_exc_raise(rb_exception);

	rugged_exception_check(error);

	return rb_result;
}
Ejemplo n.º 8
0
int cmd_push(git_repository *repo, int argc, char **argv)
{
	int err = GIT_OK;
	int i;
	int rc = EXIT_FAILURE;
	git_strarray refs = {NULL, 0};
	git_push_options push_options = GIT_PUSH_OPTIONS_INIT;
	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
	char *ref_fullname = NULL;

	git_remote *r = NULL;

	for (i=1;i<argc;i++)
	{
		if (argv[i][0] == '-')
		{
			fprintf(stderr,"Unknown option \"%s\"\n",argv[i]);
			goto out;
		}

		if (r)
		{
			git_reference *ref;

			if (refs.count) {
				fprintf(stderr, "USAGE: %s <remote> <refspec>\n", argv[0]);
				goto out;
			}

			if (!git_reference_dwim(&ref, repo, argv[i]))
			{
				ref_fullname = strdup(git_reference_name(ref));
				refs.strings = &ref_fullname;
				git_reference_free(ref);
			} else
			{
				refs.strings = &argv[i];
			}
			refs.count = 1;
		} else
		{
			if ((err = git_remote_lookup(&r,repo,argv[i])) != GIT_OK)
				goto out;
		}
	}

	if (!r)
	{
		fprintf(stderr,"No remote given!\n");
		goto out;
	}

	if (refs.count == 0)
	{
		git_strarray cfg_refs;

		if ((err = git_remote_get_push_refspecs(&cfg_refs, r)))
			goto out;

		if (!cfg_refs.count)
		{
			fprintf(stderr, "No refspec given and no refspec configured. "
					"Pushing is probably a noop.\n");
		}
		git_strarray_free(&cfg_refs);
	}
	callbacks.credentials = cred_acquire_cb;
	callbacks.push_update_reference = push_update_reference_callback;
	callbacks.certificate_check = certificate_check;
	push_options.callbacks = callbacks;

	if ((err = git_remote_push(r, &refs, &push_options)))
		goto out;

out:
	if (err != GIT_OK)
		libgit_error();
	free(ref_fullname);
	if (r) git_remote_free(r);
	return rc;
}