Пример #1
0
PyObject *
Repository_remotes__get__(Repository *self)
{
    git_strarray remotes;
    git_remote *remote = NULL;
    PyObject *py_list = NULL;
    PyObject *py_remote = NULL;
    size_t i;
    int err;

    git_remote_list(&remotes, self->repo);

    py_list = PyList_New(remotes.count);
    for (i=0; i < remotes.count; ++i) {
        err = git_remote_load(&remote, self->repo, remotes.strings[i]);
        if (err < 0)
            goto cleanup;
        py_remote = wrap_remote(remote, self);
        if (py_remote == NULL)
            goto cleanup;
        PyList_SetItem(py_list, i, py_remote);
    }

    git_strarray_free(&remotes);
    return (PyObject*) py_list;

cleanup:
    git_strarray_free(&remotes);
    if (py_list)
        Py_DECREF(py_list);
    if (err < 0)
        return Error_set(err);
    return NULL;
}
Пример #2
0
/**
 * Get the configured remotes for a repo
 *
 * @param repo S4 class git_repository
 * @return Character vector with name of the remotes
 */
SEXP git2r_remote_list(SEXP repo)
{
    int err;
    size_t i;
    git_strarray rem_list;
    SEXP list = R_NilValue;
    git_repository *repository;

    repository = git2r_repository_open(repo);
    if (!repository)
        git2r_error(__func__, NULL, git2r_err_invalid_repository, NULL);

    err = git_remote_list(&rem_list, repository);
    if (err)
        goto cleanup;

    PROTECT(list = allocVector(STRSXP, rem_list.count));
    for (i = 0; i < rem_list.count; i++)
        SET_STRING_ELT(list, i, mkChar(rem_list.strings[i]));

cleanup:
    git_strarray_free(&rem_list);

    if (repository)
        git_repository_free(repository);

    if (R_NilValue != list)
        UNPROTECT(1);

    if (err)
        git2r_error(__func__, giterr_last(), NULL, NULL);

    return list;
}
Пример #3
0
void test_network_remotes__list(void)
{
	git_strarray list;
	git_config *cfg;

	cl_git_pass(git_remote_list(&list, _repo));
	cl_assert(list.count == 1);
	git_strarray_free(&list);

	cl_git_pass(git_repository_config(&cfg, _repo));
	cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
	cl_git_pass(git_remote_list(&list, _repo));
	cl_assert(list.count == 2);
	git_strarray_free(&list);

	git_config_free(cfg);
}
static int remote_name(git_buf *buf, git_repository *repo, const char *canonical_branch_name)
{
	git_strarray remote_list = {0};
	size_t i;
	git_remote *remote;
	const git_refspec *fetchspec;
	int error = 0;
	char *remote_name = NULL;

	assert(buf && repo && canonical_branch_name);

	/* Verify that this is a remote branch */
	if (!git_reference__is_remote(canonical_branch_name)) {
		giterr_set(GITERR_INVALID, "Reference '%s' is not a remote branch.",
			canonical_branch_name);
		error = GIT_ERROR;
		goto cleanup;
	}

	/* Get the remotes */
	if ((error = git_remote_list(&remote_list, repo)) < 0)
		goto cleanup;

	/* Find matching remotes */
	for (i = 0; i < remote_list.count; i++) {
		if ((error = git_remote_load(&remote, repo, remote_list.strings[i])) < 0)
			continue;

		fetchspec = git_remote__matching_dst_refspec(remote, canonical_branch_name);
		if (fetchspec) {
			/* If we have not already set out yet, then set
			 * it to the matching remote name. Otherwise
			 * multiple remotes match this reference, and it
			 * is ambiguous. */
			if (!remote_name) {
				remote_name = remote_list.strings[i];
			} else {
				git_remote_free(remote);
				error = GIT_EAMBIGUOUS;
				goto cleanup;
			}
		}

		git_remote_free(remote);
	}

	if (remote_name) {
		git_buf_clear(buf);
		error = git_buf_puts(buf, remote_name);
	} else {
		error = GIT_ENOTFOUND;
	}

cleanup:
	git_strarray_free(&remote_list);
	return error;
}
Пример #5
0
emacs_value egit_remote_list(emacs_env *env, emacs_value _repo)
{
    EGIT_ASSERT_REPOSITORY(_repo);
    git_repository *repo = EGIT_EXTRACT(_repo);

    git_strarray out = {NULL, 0};
    int retval = git_remote_list(&out, repo);
    EGIT_CHECK_ERROR(retval);

    EGIT_RET_STRARRAY(out);
}
Пример #6
0
void test_network_remote_remotes__list(void)
{
	git_strarray list;
	git_config *cfg;

	cl_git_pass(git_remote_list(&list, _repo));
	cl_assert(list.count == 5);
	git_strarray_free(&list);

	cl_git_pass(git_repository_config(&cfg, _repo));

	/* Create a new remote */
	cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));

	/* Update a remote (previously without any url/pushurl entry) */
	cl_git_pass(git_config_set_string(cfg, "remote.no-remote-url.pushurl", "http://example.com"));

	cl_git_pass(git_remote_list(&list, _repo));
	cl_assert(list.count == 7);
	git_strarray_free(&list);

	git_config_free(cfg);
}
Пример #7
0
static void gbr_for_each_remote(git_repository *repo,
				void (*cb)(git_repository *repo, const char *remote, void *arg),
				void *arg)
{
	git_strarray remotes;
	int i;

	git_remote_list(&remotes, repo);

	for (i = 0; i < remotes.count; i++) {
		cb(repo, remotes.strings[i], arg);
	}

	git_strarray_free(&remotes);
}
static VALUE rb_git_remote_collection__each(VALUE self, int only_names)
{
	git_repository *repo;
	git_strarray remotes;
	size_t i;
	int error = 0;
	int exception = 0;

	VALUE rb_repo;

	if (!rb_block_given_p()) {
		if (only_names)
			return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_name"));
		else
			return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each"));
	}

	rb_repo = rugged_owner(self);
	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_remote_list(&remotes, repo);
	rugged_exception_check(error);

	if (only_names) {
		for (i = 0; !exception && i < remotes.count; ++i) {
			rb_protect(rb_yield, rb_str_new_utf8(remotes.strings[i]), &exception);
		}
	} else {
		for (i = 0; !exception && !error && i < remotes.count; ++i) {
			git_remote *remote;

			if (!(error = git_remote_lookup(&remote, repo, remotes.strings[i])))
				rb_protect(rb_yield, rugged_remote_new(rb_repo, remote), &exception);
		}
	}

	git_strarray_free(&remotes);

	if (exception)
		rb_jump_tag(exception);

	rugged_exception_check(error);

	return Qnil;
}
Пример #9
0
static VALUE rb_git_remote_names(VALUE klass, VALUE rb_repo)
{
	git_repository *repo;
	git_strarray remotes;
	VALUE rb_remote_names;
	int error;

	rugged_check_repo(rb_repo);

	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_remote_list(&remotes, repo);
	rugged_exception_check(error);

	rb_remote_names = rugged_strarray_to_rb_ary(&remotes);
	git_strarray_free(&remotes);
	return rb_remote_names;
}
Пример #10
0
PyObject *
Repository_remotes__get__(Repository *self)
{
    git_strarray remotes;
    PyObject* py_list = NULL, *py_tmp;
    size_t i;

    git_remote_list(&remotes, self->repo);

    py_list = PyList_New(remotes.count);
    for (i=0; i < remotes.count; ++i) {
        py_tmp = INSTANCIATE_CLASS(RemoteType, Py_BuildValue("Os", self, remotes.strings[i]));
        PyList_SetItem(py_list, i, py_tmp);
    }

    git_strarray_free(&remotes);

    return py_list;
}
Пример #11
0
PyObject *
Repository_remotes__get__(Repository *self)
{
    git_strarray remotes;
    PyObject* py_list = NULL, *py_args = NULL;
    Remote *py_remote;
    size_t i;

    git_remote_list(&remotes, self->repo);

    py_list = PyList_New(remotes.count);
    for (i=0; i < remotes.count; ++i) {
        py_remote = PyObject_New(Remote, &RemoteType);
        py_args = Py_BuildValue("Os", self, remotes.strings[i]);
        Remote_init(py_remote, py_args, NULL);
        PyList_SetItem(py_list, i, (PyObject*) py_remote);
    }

    git_strarray_free(&remotes);

    return (PyObject*) py_list;
}
Пример #12
0
/* :nodoc: */
static VALUE rb_git_remote_each(VALUE klass, VALUE rb_repo)
{
	git_repository *repo;
	git_strarray remotes;
	size_t i;
	int error = 0;
	int exception = 0;

	if (!rb_block_given_p())
		return rb_funcall(klass, rb_intern("to_enum"), 2, CSTR2SYM("each"), rb_repo);

	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_remote_list(&remotes, repo);
	rugged_exception_check(error);

	for (i = 0; !exception && !error && i < remotes.count; ++i) {
		git_remote *remote;
		error = git_remote_load(&remote, repo, remotes.strings[i]);

		if (!error) {
			rb_protect(
				rb_yield, rugged_remote_new(klass, rb_repo, remote),
				&exception);
		}
	}

	git_strarray_free(&remotes);

	if (exception)
		rb_jump_tag(exception);

	rugged_exception_check(error);
	return Qnil;
}
Пример #13
0
int NotesModel::pull() {

    git_repository *repo = NULL;
    git_remote *remote = NULL;
    git_merge_head *merge_head = NULL;

    if (!QSettings().value("gitRemoteUrl").isValid()) {
        qDebug() << "gitRemoteUrl setting invalid";
        return false; }

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

    try {
        //Open Repo
        e(git_repository_open(&repo, notesFolder().absolutePath().toUtf8().constData()));

        //List repository and add one from Settings if none exists or doesn t have same URI than settings
        git_strarray   remotes = {0};
        git_remote_list(&remotes, repo);
        if (remotes.count >= 1) {
            for (size_t i = 0; i < remotes.count; i++) {
                e(git_remote_load(&remote, repo, remotes.strings[i]));
                qDebug() << git_remote_url(remote);
                if (QSettings().value("gitRemoteUrl").isValid() && git_remote_url(remote)) {
                    if (strcmp(git_remote_url(remote),QSettings().value("gitRemoteUrl").toString().toUtf8().constData()) != 0) {
                        e(git_remote_delete(remote));
                        e(git_remote_create(&remote, repo, "upstream",
                                            QSettings().value("gitRemoteUrl").toString().toUtf8().constData()));
                        e(git_remote_save(remote));
                    }

                }
            }
        } else if (remotes.count == 0) {
            e(git_remote_create(&remote, repo, "upstream",
                                QSettings().value("gitRemoteUrl").toString().toUtf8().constData()));
            e(git_remote_save(remote));
        }

        e(git_remote_load(&remote, repo, "upstream"));

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

        e(git_remote_connect(remote, GIT_DIRECTION_FETCH));
        int connected = git_remote_connected(remote);
        if (connected)
            e(git_remote_fetch(remote, NULL, NULL));


        git_checkout_options checkout_opt = GIT_CHECKOUT_OPTIONS_INIT;
        checkout_opt.checkout_strategy = GIT_CHECKOUT_FORCE;
        checkout_opt.file_mode = 0644;
        git_merge_options merge_opt = GIT_MERGE_OPTIONS_INIT;
        merge_opt.file_favor = GIT_MERGE_FILE_FAVOR_UNION;

        const git_remote_head **head = NULL;
        size_t size = 0;
        e(git_remote_ls(&head, &size, remote));
        if (size <= 0)
            e(-1);

        git_oid oid = head[0]->oid;

        e(git_merge_head_from_fetchhead(&merge_head, repo, "master", git_remote_url(remote), &oid));
        e(git_merge(repo, (const git_merge_head **)(&merge_head), 1, &merge_opt, &checkout_opt));

        //TRY TO COMMIT
        /* Create signature */
        git_signature *me = NULL;
        e(git_signature_now(&me, "sparkleNotes", "*****@*****.**"));

        //Tree Lookup
        git_object *tree_obj;
        e(git_revparse_single(&tree_obj, repo, "HEAD^{tree}"));

        // Get parent commit
        git_oid parentCommitId;
        git_commit *parent;
        git_oid remoteParentCommitId;
        git_commit *remoteParent;
        e(git_reference_name_to_id( &parentCommitId, repo, "ORIG_HEAD" ));
        e(git_commit_lookup( &parent, repo, &parentCommitId ));
        e(git_reference_name_to_id( &remoteParentCommitId, repo, "MERGE_HEAD" ));
        e(git_commit_lookup( &remoteParent, repo, &remoteParentCommitId ));

        if (remoteParent == parent) {
            //Same commit ... nothing to merge
            e(git_repository_state_cleanup(repo));
            git_merge_head_free(merge_head);
            git_remote_free(remote);
            git_repository_free(repo);
            return false;
        }
        const git_commit *parents [2] = { parent, remoteParent };

        git_oid new_commit_id;
        e(git_commit_create(
              &new_commit_id,
              repo,
              "HEAD",                           /* name of ref to update */
              me,                               /* author */
              me,                               /* committer */
              "UTF-8",                          /* message encoding */
              "Merge remote upstream/master",   /* message */
              (git_tree *) tree_obj,            /* root tree */
              2,                                /* parent count */
              parents));                        /* parents */


        git_merge_head_free(merge_head);
        git_remote_free(remote);

        e(git_repository_state_cleanup(repo));

        git_repository_free(repo);

    }

    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_merge_head_free(merge_head);
        git_remote_free(remote);
        git_repository_free(repo);
    }
    return true;
}