[gitg] Implemented pushing local branches to remotes



commit a8832f93d563d9c040f05a15ed828d68339fe6bb
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Mon Jun 29 00:34:17 2009 +0200

    Implemented pushing local branches to remotes
    
    This is currently blocking (bad)

 gitg/gitg-branch-actions.c |   57 ++++++++++++++++++++++++++++++++++++++++++++
 gitg/gitg-branch-actions.h |    2 +-
 gitg/gitg-window.c         |   11 +++++++-
 3 files changed, 67 insertions(+), 3 deletions(-)
---
diff --git a/gitg/gitg-branch-actions.c b/gitg/gitg-branch-actions.c
index 88fb5bb..d2b6f50 100644
--- a/gitg/gitg-branch-actions.c
+++ b/gitg/gitg-branch-actions.c
@@ -336,6 +336,63 @@ gitg_branch_actions_rebase (GitgWindow *window,
 	return FALSE;
 }
 
+
+gboolean
+gitg_branch_actions_push (GitgWindow *window,
+                          GitgRef    *source,
+                          GitgRef    *dest)
+{
+	g_return_val_if_fail (GITG_IS_WINDOW (window), FALSE);
+	g_return_val_if_fail (gitg_ref_get_ref_type (source) == GITG_REF_TYPE_BRANCH, FALSE);
+	g_return_val_if_fail (gitg_ref_get_ref_type (dest) == GITG_REF_TYPE_REMOTE, FALSE);
+	
+	GitgRepository *repository = gitg_window_get_repository (window);
+
+	if (message_dialog (window,
+	                    GTK_MESSAGE_QUESTION,
+	                    _("Are you sure you want to push <%s> to <%s>?"),
+	                    NULL,
+	                    _("Push"),
+	                    gitg_ref_get_shortname (source),
+	                    gitg_ref_get_shortname (dest)) != GTK_RESPONSE_ACCEPT)
+	{
+		return FALSE;
+	}
+
+	gchar const *prefix = gitg_ref_get_prefix (dest);
+	gchar *local = gitg_ref_get_local_name (dest);
+	gchar const *name = gitg_ref_get_shortname (source);
+	gboolean ret = FALSE;
+	
+	gchar *spec = g_strconcat (name, ":", local, NULL);
+	
+	if (!gitg_repository_commandv (repository,
+	                               NULL,
+	                               "push",
+	                               prefix,
+	                               spec,
+	                               NULL))
+	{
+		message_dialog (window,
+		                GTK_MESSAGE_ERROR,
+		                _("Failed to push local branch <%s> to remote <%s>"),
+		                NULL,
+		                NULL,
+		                name,
+		                gitg_ref_get_shortname (dest));
+	}
+	else
+	{
+		gitg_repository_reload (repository);
+		ret = TRUE;
+	}
+	
+	g_free (spec);
+	g_free (local);
+	
+	return ret;
+}
+
 gboolean
 gitg_branch_actions_apply_stash (GitgWindow *window,
                                  GitgRef    *stash)
diff --git a/gitg/gitg-branch-actions.h b/gitg/gitg-branch-actions.h
index 3a8eb4e..9e0d6ea 100644
--- a/gitg/gitg-branch-actions.h
+++ b/gitg/gitg-branch-actions.h
@@ -32,7 +32,7 @@ gboolean gitg_branch_actions_remove (GitgWindow *window, GitgRef *ref);
 gboolean gitg_branch_actions_checkout (GitgWindow *window, GitgRef *ref);
 gboolean gitg_branch_actions_merge (GitgWindow *window, GitgRef *source, GitgRef *dest);
 gboolean gitg_branch_actions_rebase (GitgWindow *window, GitgRef *source, GitgRef *dest);
-
+gboolean gitg_branch_actions_push (GitgWindow *window, GitgRef *source, GitgRef *dest);
 G_END_DECLS
 
 #endif /* __GITG_BRANCH_ACTIONS_H__ */
diff --git a/gitg/gitg-window.c b/gitg/gitg-window.c
index f7d8ad5..e38f86f 100644
--- a/gitg/gitg-window.c
+++ b/gitg/gitg-window.c
@@ -466,9 +466,16 @@ on_refs_dnd (GitgRef *source, GitgRef *dest, gboolean dropped, GitgWindow *windo
 		return FALSE;
 	}
 
+	gboolean ret = FALSE;
+
+	if (gitg_ref_get_ref_type (source) == GITG_REF_TYPE_BRANCH &&
+	    gitg_ref_get_ref_type (dest) == GITG_REF_TYPE_REMOTE)
+	{
+		ret = gitg_branch_actions_push (window, source, dest);
+	}
+
 	gtk_statusbar_push (window->priv->statusbar, 0, "");
-	
-	return FALSE;
+	return ret;
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]