[gitg] Add get_verified_committer to GitgExt.Application



commit ee1b47cc95d8495a4bf2cc7f27d8d822c69c3456
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Thu Aug 13 08:09:58 2015 +0200

    Add get_verified_committer to GitgExt.Application

 gitg/commit/gitg-commit.vala          |   55 +++++++-------------------------
 gitg/gitg-window.vala                 |   48 ++++++++++++++++++++++++++++
 libgitg-ext/gitg-ext-application.vala |    7 ++++
 3 files changed, 67 insertions(+), 43 deletions(-)
---
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index a2c4399..8a876ef 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -1241,54 +1241,23 @@ namespace GitgCommit
 
                private void on_commit_clicked()
                {
-                       string? user = null;
-                       string? email = null;
-                       Ggit.Signature? committer = null;
-                       Ggit.Signature? author = null;
+                       Ggit.Signature? committer;
+                       Ggit.Signature author;
 
-                       try
-                       {
-                               committer = get_signature("COMMITTER");
-                               author = get_signature("AUTHOR");
+                       committer = application.get_verified_committer();
 
-                               user = committer.get_name();
-                               email = committer.get_email();
-
-                               if (user == "")
-                               {
-                                       user = null;
-                               }
-
-                               if (email == "")
-                               {
-                                       email = null;
-                               }
+                       if (committer == null)
+                       {
+                               return;
                        }
-                       catch {}
 
-                       if (user == null || email == null)
+                       try
                        {
-                               string secmsg;
-
-                               if (user == null && email == null)
-                               {
-                                       secmsg = _("Your user name and email are not configured yet. Please 
go to the user configuration and provide your name and email.");
-                               }
-                               else if (user == null)
-                               {
-                                       secmsg = _("Your user name is not configured yet. Please go to the 
user configuration and provide your name.");
-                               }
-                               else
-                               {
-                                       secmsg = _("Your email is not configured yet. Please go to the user 
configuration and provide your email.");
-                               }
-
-                               // TODO: better to show user info dialog directly or something
-                               application.show_infobar(_("Failed to pass pre-commit"),
-                                                        secmsg,
-                                                        Gtk.MessageType.ERROR);
-
-                               return;
+                               author = 
application.repository.get_signature_with_environment(application.environment, "AUTHOR");
+                       }
+                       catch
+                       {
+                               author = committer;
                        }
 
                        if (d_main.skip_hooks)
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index d7588e2..c33b70e 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -920,6 +920,54 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                owned get { return d_environment; }
        }
 
+       public Ggit.Signature? get_verified_committer()
+       {
+               string? user = null;
+               string? email = null;
+               Ggit.Signature? committer = null;
+
+               try
+               {
+                       committer = repository.get_signature_with_environment(environment, "COMMITTER");
+
+                       user = committer.get_name();
+                       email = committer.get_email();
+
+                       if (user == "")
+                       {
+                               user = null;
+                       }
+
+                       if (email == "")
+                       {
+                               email = null;
+                       }
+               } catch {}
+
+               if (user == null || email == null)
+               {
+                       string secmsg;
+
+                       if (user == null && email == null)
+                       {
+                               secmsg = _("Your user name and email are not configured yet. Please go to the 
user configuration and provide your name and email.");
+                       }
+                       else if (user == null)
+                       {
+                               secmsg = _("Your user name is not configured yet. Please go to the user 
configuration and provide your name.");
+                       }
+                       else
+                       {
+                               secmsg = _("Your email is not configured yet. Please go to the user 
configuration and provide your email.");
+                       }
+
+                       show_infobar(_("Missing author details"), secmsg, Gtk.MessageType.ERROR);
+                       return null;
+               }
+
+               return committer;
+       }
+
        public bool busy
        {
                get { return d_busy; }
diff --git a/libgitg-ext/gitg-ext-application.vala b/libgitg-ext/gitg-ext-application.vala
index 39662d2..03858a5 100644
--- a/libgitg-ext/gitg-ext-application.vala
+++ b/libgitg-ext/gitg-ext-application.vala
@@ -53,6 +53,13 @@ public interface Application : Object
        public abstract Gee.Map<string, string> environment { owned get; }
 
        /**
+        * Get the committer signature and verify that both its name and
+        * e-mail are set. If not, the application will show an approppriate
+        * error message and return null.
+        */
+       public abstract Ggit.Signature? get_verified_committer();
+
+       /**
         * Get the notifications manager for the application.
         */
        public abstract Notifications notifications { owned get; }


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