Пример #1
0
void test_online_fetch__fetch_twice(void)
{
	git_remote *remote;
	cl_git_pass(git_remote_create(&remote, _repo, "test", "git://github.com/libgit2/TestGitRepository.git"));
    	cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
    	cl_git_pass(git_remote_download(remote));
    	git_remote_disconnect(remote);
    	
    	git_remote_connect(remote, GIT_DIRECTION_FETCH);
	cl_git_pass(git_remote_download(remote));
	git_remote_disconnect(remote);
	
	git_remote_free(remote);
}
Пример #2
0
static int setup_remotes_and_fetch(
		git_repository *repo,
		const char *origin_url,
		git_transfer_progress_callback progress_cb,
		void *progress_payload)
{
	int retcode = GIT_ERROR;
	git_remote *origin = NULL;

	/* Create the "origin" remote */
	if (!git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, origin_url)) {
		/* Connect and download everything */
		if (!git_remote_connect(origin, GIT_DIR_FETCH)) {
			if (!git_remote_download(origin, progress_cb, progress_payload)) {
				/* Create "origin/foo" branches for all remote branches */
				if (!git_remote_update_tips(origin)) {
					/* Point HEAD to the same ref as the remote's head */
					if (!update_head_to_remote(repo, origin)) {
						retcode = 0;
					}
				}
			}
			git_remote_disconnect(origin);
		}
		git_remote_free(origin);
	}

	return retcode;
}
Пример #3
0
void test_network_remote_local__push_to_bare_remote(void)
{
    char *refspec_strings[] = {
        "master:master",
    };
    git_strarray array = {
        refspec_strings,
        1,
    };

    /* Should be able to push to a bare remote */
    git_remote *localremote;

    /* Get some commits */
    connect_to_local_repository(cl_fixture("testrepo.git"));
    cl_git_pass(git_remote_fetch(remote, &array, NULL, NULL));

    /* Set up an empty bare repo to push into */
    {
        git_repository *localbarerepo;
        cl_git_pass(git_repository_init(&localbarerepo, "./localbare.git", 1));
        git_repository_free(localbarerepo);
    }

    /* Connect to the bare repo */
    cl_git_pass(git_remote_create_anonymous(&localremote, repo, "./localbare.git"));
    cl_git_pass(git_remote_connect(localremote, GIT_DIRECTION_PUSH, NULL, NULL, NULL));

    /* Try to push */
    cl_git_pass(git_remote_upload(localremote, &push_array, NULL));

    /* Clean up */
    git_remote_free(localremote);
    cl_fixture_cleanup("localbare.git");
}
Пример #4
0
/*
 *  call-seq:
 *    remote.check_connection(direction, options = {}) -> boolean
 *
 *  Try to connect to the +remote+. Useful to simulate
 *  <tt>git fetch --dry-run</tt> and <tt>git push --dry-run</tt>.
 *
 *  Returns +true+ if connection is successful, +false+ otherwise.
 *
 *  +direction+ must be either +:fetch+ or +:push+.
 *
 *  The following options can be passed in the +options+ Hash:
 *
 *  +credentials+ ::
 *    The credentials to use for the connection. 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.
 *
 *  Example:
 *
 *    remote = repo.remotes["origin"]
 *    success = remote.check_connection(:fetch)
 *    raise Error("Unable to pull without credentials") unless success
 */
static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
{
	git_remote *remote;
	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
	struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
	VALUE rb_direction, rb_options;
	ID id_direction;
	int error, direction;

	Data_Get_Struct(self, git_remote, remote);
	rb_scan_args(argc, argv, "01:", &rb_direction, &rb_options);

	Check_Type(rb_direction, T_SYMBOL);
	id_direction = SYM2ID(rb_direction);
	if (id_direction == rb_intern("fetch"))
		direction = GIT_DIRECTION_FETCH;
	else if (id_direction == rb_intern("push"))
		direction = GIT_DIRECTION_PUSH;
	else
		rb_raise(rb_eTypeError, "Invalid direction. Expected :fetch or :push");

	rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);

	error = git_remote_connect(remote, direction, &callbacks);
	git_remote_disconnect(remote);

	if (payload.exception)
		rb_jump_tag(payload.exception);

	return error ? Qfalse : Qtrue;
}
Пример #5
0
void test_network_fetchlocal__partial(void)
{
	git_repository *repo = cl_git_sandbox_init("partial-testrepo");
	git_remote *origin;
	int callcount = 0;
	git_strarray refnames = {0};
	const char *url;
	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;

	callbacks.transfer_progress = transfer_cb;
	callbacks.payload = &callcount;

	cl_set_cleanup(&cleanup_sandbox, NULL);
	cl_git_pass(git_reference_list(&refnames, repo));
	cl_assert_equal_i(1, (int)refnames.count);

	url = cl_git_fixture_url("testrepo.git");
	cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
	git_remote_set_callbacks(origin, &callbacks);
	cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
	cl_git_pass(git_remote_download(origin));
	cl_git_pass(git_remote_update_tips(origin, NULL, NULL));

	git_strarray_free(&refnames);

	cl_git_pass(git_reference_list(&refnames, repo));
	cl_assert_equal_i(20, (int)refnames.count); /* 18 remote + 1 local */
	cl_assert(callcount > 0);

	git_strarray_free(&refnames);
	git_remote_free(origin);
}
Пример #6
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;
	git_strarray array, *active_refs = NULL;

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

	if(fetchspec != NULL) {
		array.count = 1;
		array.strings = (char **) &fetchspec;
		active_refs = &array;
	}

	cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
	cl_git_pass(git_remote_download(remote, active_refs));
	cl_git_pass(git_remote_update_tips(remote, NULL));
	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);
}
Пример #7
0
PyObject *
Remote_fetch(Remote *self, PyObject *args)
{
    PyObject* py_stats = NULL;
    const git_transfer_progress *stats;
    int err;

    err = git_remote_connect(self->remote, GIT_DIRECTION_FETCH);
    if (err == GIT_OK) {
        err = git_remote_download(self->remote);
        if (err == GIT_OK) {
            stats = git_remote_stats(self->remote);
            py_stats = Py_BuildValue("{s:I,s:I,s:n}",
                "indexed_objects", stats->indexed_objects,
                "received_objects", stats->received_objects,
                "received_bytes", stats->received_bytes);

            err = git_remote_update_tips(self->remote);
        }
        git_remote_disconnect(self->remote);
    }

    if (err < 0)
        return Error_set(err);

    return (PyObject*) py_stats;
}
Пример #8
0
Файл: fetch.c Проект: bxio/.atom
static void *download(void *ptr)
{
	struct dl_data *data = (struct dl_data *)ptr;

	// Connect to the remote end specifying that we want to fetch
	// information from it.
	if (git_remote_connect(data->remote, GIT_DIRECTION_FETCH) < 0) {
		data->ret = -1;
		goto exit;
	}

	// Download the packfile and index it. This function updates the
	// amount of received data and the indexer stats which lets you
	// inform the user about progress.
	if (git_remote_download(data->remote, NULL, NULL) < 0) {
		data->ret = -1;
		goto exit;
	}

	data->ret = 0;

exit:
	data->finished = 1;
	return &data->ret;
}
Пример #9
0
static void connect_to_local_repository(const char *local_repository)
{
    git_buf_sets(&file_path_buf, cl_git_path_url(local_repository));

    cl_git_pass(git_remote_create_anonymous(&remote, repo, git_buf_cstr(&file_path_buf)));
    cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
}
Пример #10
0
void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date(void)
{
	git_repository *_repository;
	bool invoked = false;
	git_remote *remote;
	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
	git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
	opts.bare = true;

	cl_git_pass(git_clone(&_repository, "https://github.com/libgit2/TestGitRepository.git",
				"./fetch/lg2", &opts));
	git_repository_free(_repository);

	cl_git_pass(git_repository_open(&_repository, "./fetch/lg2"));

	cl_git_pass(git_remote_load(&remote, _repository, "origin"));
	cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));

	cl_assert_equal_i(false, invoked);

	callbacks.transfer_progress = &transferProgressCallback;
	callbacks.payload = &invoked;
	git_remote_set_callbacks(remote, &callbacks);
	cl_git_pass(git_remote_download(remote));

	cl_assert_equal_i(false, invoked);

	cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
	git_remote_disconnect(remote);

	git_remote_free(remote);
	git_repository_free(_repository);
}
Пример #11
0
void test_network_remote_remotes__error_when_no_push_available(void)
{
	git_remote *r;
	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
	char *specs = {
		"refs/heads/master",
	};
	git_strarray arr = {
		&specs,
		1,
	};


	cl_git_pass(git_remote_create_anonymous(&r, _repo, cl_fixture("testrepo.git")));

	callbacks.transport = git_transport_local;
	cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH, &callbacks, NULL));

	/* Make sure that push is really not available */
	r->transport->push = NULL;

	cl_git_fail_with(-1, git_remote_upload(r, &arr, NULL));

	git_remote_free(r);
}
Пример #12
0
void test_network_remote_local__push_to_non_bare_remote(void)
{
    char *refspec_strings[] = {
        "master:master",
    };
    git_strarray array = {
        refspec_strings,
        1,
    };
    /* Shouldn't be able to push to a non-bare remote */
    git_remote *localremote;
    git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT;

    /* Get some commits */
    connect_to_local_repository(cl_fixture("testrepo.git"));
    cl_git_pass(git_remote_fetch(remote, &array, &fetch_opts, NULL));

    /* Set up an empty non-bare repo to push into */
    {
        git_repository *remoterepo = NULL;
        cl_git_pass(git_repository_init(&remoterepo, "localnonbare", 0));
        git_repository_free(remoterepo);
    }

    /* Connect to the bare repo */
    cl_git_pass(git_remote_create_anonymous(&localremote, repo, "./localnonbare"));
    cl_git_pass(git_remote_connect(localremote, GIT_DIRECTION_PUSH, NULL, NULL, NULL));

    /* Try to push */
    cl_git_fail_with(GIT_EBAREREPO, git_remote_upload(localremote, &push_array, NULL));

    /* Clean up */
    git_remote_free(localremote);
    cl_fixture_cleanup("localbare.git");
}
Пример #13
0
static int use_remote(git_repository *repo, char *name)
{
	git_remote *remote = NULL;
	int error;
	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;

	// Find the remote by name
	error = git_remote_load(&remote, repo, name);
	if (error < 0) {
		error = git_remote_create_inmemory(&remote, repo, NULL, name);
		if (error < 0)
			goto cleanup;
	}

	callbacks.credentials = cred_acquire_cb;
	git_remote_set_callbacks(remote, &callbacks);

	error = git_remote_connect(remote, GIT_DIRECTION_FETCH);
	if (error < 0)
		goto cleanup;

	error = git_remote_ls(remote, &show_ref__cb, NULL);

cleanup:
	git_remote_free(remote);
	return error;
}
Пример #14
0
/**
 * ggit_remote_connect:
 * @remote: a #GgitRemote.
 * @direction: whether you want to receive or send data.
 * @callbacks: the callbacks to use for this connection.
 * @proxy_options: (allow-none): the proxy options.
 * @custom_headers: (allow-none): extra HTTP headers to use in this connection.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Opens a connection to a remote.
 * The transport is selected based on the URL. The direction argument
 * is due to a limitation of the git protocol (over TCP or SSH) which
 * starts up a specific binary which can only do the one or the other.
 */
void
ggit_remote_connect (GgitRemote           *remote,
                     GgitDirection         direction,
                     GgitRemoteCallbacks  *callbacks,
                     GgitProxyOptions     *proxy_options,
                     const gchar * const  *custom_headers,
                     GError              **error)
{
	gint ret;
	git_strarray headers;

	g_return_if_fail (GGIT_IS_REMOTE (remote));
	g_return_if_fail (error == NULL || *error == NULL);

	ggit_utils_get_git_strarray_from_str_array (custom_headers, &headers);

	ret = git_remote_connect (_ggit_native_get (remote),
	                          (git_direction)direction,
	                          _ggit_remote_callbacks_get_native (callbacks),
	                          proxy_options != NULL ? _ggit_proxy_options_get_proxy_options (proxy_options) : NULL,
	                          &headers);

	if (ret != GIT_OK)
	{
		_ggit_error_set (error, ret);
	}
}
Пример #15
0
void test_network_remote_defaultbranch__detached_sharing_nonbranch_id(void)
{
    git_oid id, id_cloned;
    git_reference *ref;
    git_buf buf = GIT_BUF_INIT;
    git_repository *cloned_repo;

    cl_git_pass(git_reference_name_to_id(&id, g_repo_a, "HEAD"));
    cl_git_pass(git_repository_detach_head(g_repo_a, NULL, NULL));
    cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/master"));
    cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/not-good"));
    cl_git_pass(git_reference_create(&ref, g_repo_a, "refs/foo/bar", &id, 1, NULL, NULL));
    git_reference_free(ref);

    cl_git_pass(git_remote_connect(g_remote, GIT_DIRECTION_FETCH));
    cl_git_fail_with(GIT_ENOTFOUND, git_remote_default_branch(&buf, g_remote));

    cl_git_pass(git_clone(&cloned_repo, git_repository_path(g_repo_a), "./local-detached", NULL));

    cl_assert(git_repository_head_detached(cloned_repo));
    cl_git_pass(git_reference_name_to_id(&id_cloned, g_repo_a, "HEAD"));
    cl_assert(git_oid_equal(&id, &id_cloned));

    git_repository_free(cloned_repo);
}
Пример #16
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_clear_refspecs(remote);
		git_remote_add_fetch(remote, fetchspec);
	}

	cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
	cl_git_pass(git_remote_download(remote));
	cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
	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);
}
Пример #17
0
static void connect_to_local_repository(const char *local_repository)
{
	build_local_file_url(&file_path_buf, local_repository);

	cl_git_pass(git_remote_new(&remote, repo, NULL, git_buf_cstr(&file_path_buf), NULL));
	cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));

}
Пример #18
0
static void assert_default_branch(const char *should)
{
    git_buf name = GIT_BUF_INIT;

    cl_git_pass(git_remote_connect(g_remote, GIT_DIRECTION_FETCH));
    cl_git_pass(git_remote_default_branch(&name, g_remote));
    cl_assert_equal_s(should, name.ptr);
    git_buf_free(&name);
}
Пример #19
0
void GitRepository::fetch()
{
    git_repository* repo = repository();

    const char* remote_name = "origin";
    git_auto<git_remote> remote;
    git_eval(git_remote_lookup(&remote, repo, remote_name));
    git_eval(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL));
    git_eval(git_remote_fetch(remote, NULL, NULL, NULL));
}
Пример #20
0
void test_network_remotelocal__initialize(void)
{
	cl_fixture("remotelocal");
	cl_git_pass(git_repository_init(&repo, "remotelocal/", 0));
	cl_assert(repo != NULL);

	build_local_file_url(&file_path_buf, "testrepo.git");

	cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL));
	cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
}
Пример #21
0
void test_network_remote_remotes__can_load_with_only_an_empty_pushurl(void)
{
	git_remote *remote = NULL;

	cl_git_pass(git_remote_lookup(&remote, _repo, "empty-remote-pushurl"));

	cl_assert(remote->url == NULL);
	cl_assert(remote->pushurl == NULL);

	cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL));

	git_remote_free(remote);
}
Пример #22
0
void GitRepository::push()
{
    git_repository* repo = repository();

    const char* remote_name = "origin";
    git_auto<git_remote> remote;
    git_eval(git_remote_lookup(&remote, repo, remote_name));
    git_eval(git_remote_connect(remote, GIT_DIRECTION_PUSH, NULL, NULL));

    git_auto<git_reference> head;
    git_eval(git_repository_head(&head, repo));
    QString refname = QString("+%1:%1").arg(git_reference_name(head));
    git_eval(git_remote_add_push(repo, remote_name, refname.toLatin1()));
    git_eval(git_remote_upload(remote, NULL, NULL));
}
Пример #23
0
void test_network_remote_defaultbranch__no_default_branch(void)
{
    git_remote *remote_b;
    const git_remote_head **heads;
    size_t len;
    git_buf buf = GIT_BUF_INIT;

    cl_git_pass(git_remote_create(&remote_b, g_repo_b, "self", git_repository_path(g_repo_b)));
    cl_git_pass(git_remote_connect(remote_b, GIT_DIRECTION_FETCH));
    cl_git_pass(git_remote_ls(&heads, &len, remote_b));
    cl_assert_equal_i(0, len);

    cl_git_fail_with(GIT_ENOTFOUND, git_remote_default_branch(&buf, remote_b));

    git_remote_free(remote_b);
}
Пример #24
0
void test_online_fetch__ls_disconnected(void)
{
	git_remote *remote;
	int nr_before = 0, nr_after = 0;

	cl_git_pass(git_remote_create(&remote, _repo, "test",
				"http://github.com/libgit2/TestGitRepository.git"));
	cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
	cl_git_pass(git_remote_ls(remote, ls_cb, &nr_before));
	git_remote_disconnect(remote);
	cl_git_pass(git_remote_ls(remote, ls_cb, &nr_after));

	cl_assert_equal_i(nr_before, nr_after);

	git_remote_free(remote);
}
Пример #25
0
void test_network_remote_remotes__can_load_with_an_empty_url(void)
{
	git_remote *remote = NULL;

	cl_git_pass(git_remote_lookup(&remote, _repo, "empty-remote-url"));

	cl_assert(remote->url == NULL);
	cl_assert(remote->pushurl == NULL);

	cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL));

	cl_assert(giterr_last() != NULL);
	cl_assert(giterr_last()->klass == GITERR_INVALID);

	git_remote_free(remote);
}
Пример #26
0
void test_online_fetch__remote_symrefs(void)
{
	const git_remote_head **refs;
	size_t refs_len;
	git_remote *remote;

	cl_git_pass(git_remote_create(&remote, _repo, "test",
				"http://github.com/libgit2/TestGitRepository.git"));
	cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
	git_remote_disconnect(remote);
	cl_git_pass(git_remote_ls(&refs, &refs_len, remote));

	cl_assert_equal_s("HEAD", refs[0]->name);
	cl_assert_equal_s("refs/heads/master", refs[0]->symref_target);

	git_remote_free(remote);
}
Пример #27
0
void test_online_fetch__ls_disconnected(void)
{
	const git_remote_head **refs;
	size_t refs_len_before, refs_len_after;
	git_remote *remote;

	cl_git_pass(git_remote_create(&remote, _repo, "test",
				"http://github.com/libgit2/TestGitRepository.git"));
	cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
	cl_git_pass(git_remote_ls(&refs, &refs_len_before, remote));
	git_remote_disconnect(remote);
	cl_git_pass(git_remote_ls(&refs, &refs_len_after, remote));

	cl_assert_equal_i(refs_len_before, refs_len_after);

	git_remote_free(remote);
}
Пример #28
0
void test_online_fetch__can_cancel(void)
{
	git_remote *remote;
	size_t bytes_received = 0;
	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;

	cl_git_pass(git_remote_create(&remote, _repo, "test",
				"http://github.com/libgit2/TestGitRepository.git"));

	callbacks.transfer_progress = cancel_at_half;
	callbacks.payload = &bytes_received;
	git_remote_set_callbacks(remote, &callbacks);

	cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
	cl_git_fail_with(git_remote_download(remote), -4321);
	git_remote_disconnect(remote);
	git_remote_free(remote);
}
Пример #29
0
int NotesModel::push() {
    git_push *push;
    git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
    git_repository *repo = NULL;
    git_remote *remote = NULL;


    if (!QSettings().value("gitRemoteUrl").isValid())
        return false;

    if (QSettings().value("gitRemoteUrl") == "")
        return false;

    try {
        //Open Repo
        e(git_repository_open(&repo, notesFolder().absolutePath().toUtf8().constData()));
        e(git_remote_load(&remote, repo, "upstream"));
        callbacks.credentials = cred_acquire_cb;
        e(git_remote_set_callbacks(remote, &callbacks));
        e(git_remote_connect(remote, GIT_DIRECTION_PUSH));
        int connected = git_remote_connected(remote);
        if (connected) {
            e(git_push_new(&push, remote));

            e(git_push_add_refspec(push, "refs/heads/master:refs/heads/master"));
            e(git_push_finish(push));
            e(git_push_unpack_ok(push));
            e(git_push_status_foreach(push, &status_cb, NULL) < 0);

            git_push_free(push);
        }
    }
    catch (int error) {
        const git_error *err = giterr_last();
        if (err != NULL)
            qDebug() << QString::number(err->klass) + "\t" + QString(err->message);
        emit this->error(QString(err->message));
        giterr_clear();
        git_remote_free(remote);
        git_repository_free(repo);
    }
    return true;

}
Пример #30
0
static int use_remote(git_repository *repo, char *name)
{
	git_remote *remote = NULL;
	int error;
	const git_remote_head **refs;
	size_t refs_len, i;
	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;

	// Find the remote by name
	error = git_remote_lookup(&remote, repo, name);
	if (error < 0) {
		error = git_remote_create_anonymous(&remote, repo, name);
		if (error < 0)
			goto cleanup;
	}

	/**
	 * Connect to the remote and call the printing function for
	 * each of the remote references.
	 */
	callbacks.credentials = cred_acquire_cb;
	callbacks.certificate_check = certificate_check;

	error = git_remote_connect(remote, GIT_DIRECTION_FETCH, &callbacks, NULL);
	if (error < 0)
		goto cleanup;

	/**
	 * Get the list of references on the remote and print out
	 * their name next to what they point to.
	 */
	if (git_remote_ls(&refs, &refs_len, remote) < 0)
		goto cleanup;

	for (i = 0; i < refs_len; i++) {
		char oid[GIT_OID_HEXSZ + 1] = {0};
		git_oid_fmt(oid, &refs[i]->oid);
		printf("%s\t%s\n", oid, refs[i]->name);
	}

cleanup:
	git_remote_free(remote);
	return error;
}