Example #1
0
/**
 * ggit_branch_get_upstream:
 * @branch: a #GgitBranch.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Gets the reference supporting the remote tracking branch,
 * given a local branch reference.
 *
 * Returns: (transfer full) (allow-none): the reference supporting the remote tracking branch.
 */
GgitRef *
ggit_branch_get_upstream (GgitBranch  *branch,
                          GError     **error)
{
	gint ret;
	git_reference *upstream;
	const gchar *name;
	GgitRef *ref;

	g_return_val_if_fail (GGIT_IS_BRANCH (branch), NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);

	ret = git_branch_upstream (&upstream,
	                           _ggit_native_get (branch));

	if (ret != GIT_OK)
	{
		_ggit_error_set (error, ret);
		return NULL;
	}

	name = git_reference_name (_ggit_native_get (upstream));

	if (g_str_has_prefix (name, "refs/heads/"))
	{
		ref = GGIT_REF (_ggit_branch_wrap (upstream));
	}
	else
	{
		ref = _ggit_ref_wrap (upstream);
	}

	return ref;
}
Example #2
0
GgitRef *
_ggit_ref_wrap (git_reference *ref,
                gboolean       owned)
{
	GgitRef *gref;

	if (git_reference_is_branch (ref))
	{
		gref = GGIT_REF (_ggit_branch_wrap (ref));
	}
	else
	{
		gref = g_object_new (GGIT_TYPE_REF,
		                     "native", ref,
		                     NULL);
	}

	if (owned)
	{
		_ggit_native_set_destroy_func (gref,
		                               (GDestroyNotify)git_reference_free);
	}

	return gref;
}