[gitg] Allow creating a tag without a message.



commit 1b8890771fe96fc95d518746a5af188589507e79
Author: Jonny Lamb <jonnylamb gnome org>
Date:   Mon Mar 1 00:54:18 2010 +0000

    Allow creating a tag without a message.
    
    gitg only creates annotated or signed tags. However, sometimes you
    just don't want to use a message in your tag. This patch enables you
    to do that.
    
    If you give a message, but don't ask to sign the tag, the tag will be
    an annotated tag. If you give a message and ask to sign the tag, the
    tag will be a signed tag (zomg). If you omit a message, then the tag
    will be created without a message (not signed or annotated).
    
    The UI will complain appropriately if you screw up.
    
    Signed-off-by: Jonny Lamb <jonnylamb gnome org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=611434

 gitg/gitg-branch-actions.c |   34 ++++++++++++++++++++++++----------
 gitg/gitg-window.c         |   19 +++++++++++++++----
 2 files changed, 39 insertions(+), 14 deletions(-)
---
diff --git a/gitg/gitg-branch-actions.c b/gitg/gitg-branch-actions.c
index 62ec4f5..d105683 100644
--- a/gitg/gitg-branch-actions.c
+++ b/gitg/gitg-branch-actions.c
@@ -1554,21 +1554,35 @@ gitg_branch_actions_tag (GitgWindow *window, gchar const *sha1, gchar const *nam
 	g_return_val_if_fail (GITG_IS_WINDOW (window), FALSE);
 	g_return_val_if_fail (sha1 != NULL, FALSE);
 	g_return_val_if_fail (name != NULL, FALSE);
-	g_return_val_if_fail (message != NULL, FALSE);
 
 	GitgRepository *repository;
+	gboolean result = FALSE;
 
 	repository = gitg_window_get_repository (window);
 
-	if (!gitg_repository_commandv (repository,
-	                               NULL,
-	                               "tag",
-	                               "-m",
-	                               message,
-	                               sign ? "-s" : "-a",
-	                               name,
-	                               sha1,
-	                               NULL))
+	if (message != NULL && message[0] != '\0')
+	{
+		result = gitg_repository_commandv (repository,
+		                                   NULL,
+		                                   "tag",
+		                                   "-m",
+		                                   message,
+		                                   sign ? "-s" : "-a",
+		                                   name,
+		                                   sha1,
+		                                   NULL);
+	}
+	else
+	{
+		result = gitg_repository_commandv (repository,
+		                                   NULL,
+		                                   "tag",
+		                                   name,
+		                                   sha1,
+		                                   NULL);
+	}
+
+	if (!result)
 	{
 		gchar const *secondary;
 
diff --git a/gitg/gitg-window.c b/gitg/gitg-window.c
index 3ee0cbf..9a2ff46 100644
--- a/gitg/gitg-window.c
+++ b/gitg/gitg-window.c
@@ -2467,6 +2467,7 @@ on_tag_dialog_response (GtkWidget *dialog, gint response, TagInfo *info)
 	if (response == GTK_RESPONSE_ACCEPT)
 	{
 		gchar const *name = gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (info->builder, "entry_name")));
+		gboolean sign = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (info->builder, "check_button_sign")));
 
 		GtkTextView *view = GTK_TEXT_VIEW (gtk_builder_get_object (info->builder, "text_view_message"));
 		GtkTextIter start;
@@ -2475,7 +2476,18 @@ on_tag_dialog_response (GtkWidget *dialog, gint response, TagInfo *info)
 		gtk_text_buffer_get_bounds (gtk_text_view_get_buffer (view), &start, &end);
 		gchar *message = gtk_text_iter_get_text (&start, &end);
 
-		if (!*name || !*message)
+		const gchar *secondary_text = NULL;
+
+		if (sign && (!*name || !*message))
+		{
+			secondary_text = _("Please make sure to fill in both the tag name and the commit message");
+		}
+		else if (!sign && !*name)
+		{
+			secondary_text = _("Please make sure to fill in the tag name");
+		}
+
+		if (secondary_text)
 		{
 			GtkWidget *dlg = gtk_message_dialog_new (GTK_WINDOW (dialog),
 			                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -2483,7 +2495,8 @@ on_tag_dialog_response (GtkWidget *dialog, gint response, TagInfo *info)
 			                                         GTK_BUTTONS_OK,
 			                                         _("Not all fields are correctly filled in"));
 			gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
-			                                          _("Please make sure to fill in both the tag name and the commit message"));
+			                                          "%s",
+			                                          secondary_text);
 
 			g_signal_connect (dlg, "response", G_CALLBACK (gtk_widget_destroy), NULL);
 			gtk_widget_show (dlg);
@@ -2492,8 +2505,6 @@ on_tag_dialog_response (GtkWidget *dialog, gint response, TagInfo *info)
 		}
 		else
 		{
-			gboolean sign = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (info->builder, "check_button_sign")));
-
 			gchar *sha1 = gitg_revision_get_sha1 (info->revision);
 			if (!gitg_branch_actions_tag (info->window,
 			                              sha1,



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