コード例 #1
0
ファイル: ggit-branch.c プロジェクト: hsoft/libgit2-glib
/**
 * 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;
}
コード例 #2
0
/**
 * ggit_branch_move:
 * @branch: a #GgitBranch.
 * @new_branch_name: target name of the branch once the move is performed; this name is validated for consistency.
 * @flags: a #GgitCreateFlags.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Moves/renames an existing branch reference.
 *
 * Returns: (transfer full): the new branch.
 **/
GgitBranch *
ggit_branch_move (GgitBranch       *branch,
                  const gchar      *new_branch_name,
                  GgitCreateFlags   flags,
                  GError          **error)
{
	git_reference *out;
	gboolean force;
	gint ret;

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

	force = flags & GGIT_CREATE_FORCE;

	ret = git_branch_move (&out,
	                       _ggit_native_get (branch),
	                       new_branch_name,
	                       force ? 1 : 0);

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

	return _ggit_branch_wrap (out);
}
コード例 #3
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;
}