Example #1
0
int Branch_upstream__set__(Branch *self, Reference *py_ref)
{
    int err;
    const char *branch_name = NULL;

    CHECK_REFERENCE_INT(self);

    if ((PyObject *)py_ref != Py_None) {
        if (!PyObject_TypeCheck(py_ref, (PyTypeObject *)&ReferenceType)) {
            PyErr_SetObject(PyExc_TypeError, (PyObject *)py_ref);
            return -1;
        }

        CHECK_REFERENCE_INT(py_ref);
        err = git_branch_name(&branch_name, py_ref->reference);
        if (err < GIT_OK) {
            Error_set(err);
            return -1;
        }
    }

    err = git_branch_set_upstream(self->reference, branch_name);
    if (err < GIT_OK) {
        Error_set(err);
        return -1;
    }

    return 0;
}
Example #2
0
/*
 *  call-seq:
 *    branch.upstream = branch
 *
 *  Set the upstream configuration for a given local branch.
 *
 *  Takes a local or remote Rugged::Branch instance or a Rugged::Reference
 *  pointing to a branch.
 */
static VALUE rb_git_branch_set_upstream(VALUE self, VALUE rb_branch)
{
	git_reference *branch, *target_branch;
	const char *target_branch_name;

	Data_Get_Struct(self, git_reference, branch);
	if (!NIL_P(rb_branch)) {
		if (!rb_obj_is_kind_of(rb_branch, rb_cRuggedReference))
			rb_raise(rb_eTypeError, "Expecting a Rugged::Reference instance");

		Data_Get_Struct(rb_branch, git_reference, target_branch);

		rugged_exception_check(
			git_branch_name(&target_branch_name, target_branch)
		);
	} else {
		target_branch_name = NULL;
	}

	rugged_exception_check(
		git_branch_set_upstream(branch, target_branch_name)
	);

	return rb_branch;
}
Example #3
0
/**
 * ggit_branch_set_upstream:
 * @branch: a #GgitBranch.
 * @upstream_branch_name: name of the upstream branch; if %NULL unsets it.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Sets the upstream branch, for a given local branch reference
 */
void
ggit_branch_set_upstream (GgitBranch   *branch,
                          const gchar  *upstream_branch_name,
                          GError      **error)
{
	gint ret;

	g_return_if_fail (GGIT_IS_BRANCH (branch));
	g_return_if_fail (error == NULL || *error == NULL);

	ret = git_branch_set_upstream (_ggit_native_get (branch), upstream_branch_name);

	if (ret != GIT_OK)
	{
		_ggit_error_set (error, ret);
	}
}
Example #4
0
static void
checkout(git_repository *repo)
{
	git_reference *master_ref, *remote_ref, *HEAD_ref, *tmpr;
	git_checkout_options co_opts;
	const char *remote_br_name;
	git_commit *remote_commit;
	git_object *remote_obj;
	char *remotebr;
	int rc;

	remotebr = NULL;
	xasprintf(&remotebr, "refs/remotes/%s/%s", option_origin,
	    option_trunk);

	rc = git_reference_lookup(&remote_ref, repo, remotebr);
	if (rc)
		die("git_reference_lookup(%s): %d", remotebr, rc);

	rc = git_branch_name(&remote_br_name, remote_ref);
	if (rc)
		die("git_branch_name: %d", rc);

	rc = git_reference_peel(&remote_obj, remote_ref, GIT_OBJ_COMMIT);
	if (rc)
		die("git_reference_peel");

	rc = git_commit_lookup(&remote_commit, repo,
	    git_object_id(remote_obj));
	if (rc)
		die("git_commit_lookup");

	rc = git_branch_create(&master_ref, repo, "master", remote_commit,
	    false, NULL, NULL);
	if (rc)
		die("git_branch_create: %d", rc);

	rc = git_reference_symbolic_create(&HEAD_ref, repo, "HEAD",
	    "refs/heads/master", false, NULL, NULL);
	if (rc && rc != GIT_EEXISTS)
		die("git_reference_symbolic_create: %d", rc);

	rc = git_branch_set_upstream(master_ref, remote_br_name);
	if (rc)
		/* TODO: '' is not a valid remote name */
#if 0
		die("git_branch_set_upstream: %d (%d/%s)", rc,
		    giterr_last()->klass, giterr_last()->message);
#else
		printf("XXXgit_branch_set_upstream: %d (%d/%s)\n", rc,
		    giterr_last()->klass, giterr_last()->message);
#endif

	rc = git_reference_lookup(&tmpr, repo, "refs/heads/master");
	if (rc)
		die("%s: reference_lookup: master doesn't exist?", __func__);
	if (git_reference_cmp(tmpr, master_ref) != 0)
		die("mismatched master");

	co_opts = (git_checkout_options) GIT_CHECKOUT_OPTIONS_INIT;
	co_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
	rc = git_checkout_head(repo, &co_opts);
	if (rc)
		die("git_checkout_head");

	free(remotebr);
	git_commit_free(remote_commit);
	git_object_free(remote_obj);
	git_reference_free(tmpr);
	git_reference_free(HEAD_ref);
	git_reference_free(master_ref);
	git_reference_free(remote_ref);
}
Example #5
0
void Branch::setUpstream(const std::string& upstreamName)
{
	Exception::git2_assert(git_branch_set_upstream(data(), upstreamName.c_str()));
}