[gitg] Add support for commit.template config setting



commit 40808feda59e6c930fcb275940279a967f73438a
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Tue Dec 22 09:57:08 2015 +0100

    Add support for commit.template config setting

 gitg/commit/gitg-commit-dialog.vala |   35 ++++++++++++++++++++++++++++++++---
 gitg/commit/gitg-commit.vala        |    2 +-
 2 files changed, 33 insertions(+), 4 deletions(-)
---
diff --git a/gitg/commit/gitg-commit-dialog.vala b/gitg/commit/gitg-commit-dialog.vala
index 1412799..2b8076e 100644
--- a/gitg/commit/gitg-commit-dialog.vala
+++ b/gitg/commit/gitg-commit-dialog.vala
@@ -88,6 +88,11 @@ class Dialog : Gtk.Dialog
                construct set { d_diff = value; }
        }
 
+       public Gitg.Repository repository
+       {
+               owned get; construct set;
+       }
+
        public int max_visible_stat_items
        {
                get;
@@ -636,6 +641,29 @@ class Dialog : Gtk.Dialog
                });
 
                update_highlight();
+               
+               try
+               {
+                       Ggit.Config config;
+
+                       config = repository.get_config().snapshot();
+
+                       var template_path = config.get_string("commit.template");
+
+                       if (template_path != null)
+                       {
+                               var path = Gitg.Utils.expand_home_dir(template_path);
+
+                               string contents;
+                               size_t len;
+
+                               FileUtils.get_contents(path, out contents, out len);
+                               d_source_view_message.buffer.set_text(Gitg.Convert.utf8(contents, 
(ssize_t)len));
+                       }
+               }
+               catch (Error e) {
+                       stderr.printf(@"ERROR: Failed to read commit.template: $(e.message)\n");
+               }
        }
 
        private void update_highlight()
@@ -733,10 +761,11 @@ class Dialog : Gtk.Dialog
                }
        }
 
-       public Dialog(Ggit.Signature author,
-                     Ggit.Diff?     diff)
+       public Dialog(Gitg.Repository repository,
+                     Ggit.Signature  author,
+                     Ggit.Diff?      diff)
        {
-               Object(author: author, diff: diff, use_header_bar: 1);
+               Object(repository: repository, author: author, diff: diff, use_header_bar: 1);
        }
 
        private void update_font_settings()
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index c5eccd2..e872363 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -1192,7 +1192,7 @@ namespace GitgCommit
                                                         Ggit.Signature committer,
                                                         Ggit.Diff?     diff)
                {
-                       var dlg = new Dialog(author, diff);
+                       var dlg = new Dialog(application.repository, author, diff);
 
                        dlg.set_transient_for((Gtk.Window)d_main.get_toplevel());
                        dlg.set_default_response(Gtk.ResponseType.OK);


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