If the user's git config defines commit.template then include the
contents of that file in the log buffer by default.

In git-setup-log-buffer, instead of supplying the default commit
message insert the user's commit.template.

Signed-off-by: Curt Brune <c...@brune.net>
---
 contrib/emacs/git.el |   47 ++++++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 5ffc506..827578f 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -296,6 +296,11 @@ the process output as a string, or nil if the git command 
failed."
       (and (fboundp 'user-mail-address) (user-mail-address))
       (and (boundp 'user-mail-address) user-mail-address)))
 
+(defun git-get-commit-template ()
+  "Return the git commit template or nil"
+  ; copied from log-edit
+  (git-config "commit.template"))
+
 (defun git-get-commits-coding-system ()
   "Return the coding system to use for commits."
   (let ((repo-config (git-config "i18n.commitencoding")))
@@ -1280,29 +1285,33 @@ The FILES list must be sorted."
   (let ((dir default-directory)
         (committer-name (git-get-committer-name))
         (committer-email (git-get-committer-email))
+        (commit-template (git-get-commit-template))
         (sign-off git-append-signed-off-by))
     (with-current-buffer buffer
       (cd dir)
       (erase-buffer)
-      (insert
-       (propertize
-        (format "Author: %s <%s>\n%s%s"
-                (or author-name committer-name)
-                (or author-email committer-email)
-                (if date (format "Date: %s\n" date) "")
-                (if merge-heads
-                    (format "Merge: %s\n"
-                            (mapconcat 'identity merge-heads " "))
-                  ""))
-        'face 'git-header-face)
-       (propertize git-log-msg-separator 'face 'git-separator-face)
-       "\n")
-      (when subject (insert subject "\n\n"))
-      (cond (msg (insert msg "\n"))
-            ((file-readable-p ".git/rebase-apply/msg")
-             (insert-file-contents ".git/rebase-apply/msg"))
-            ((file-readable-p ".git/MERGE_MSG")
-             (insert-file-contents ".git/MERGE_MSG")))
+      (if commit-template
+         (insert-file-contents commit-template)
+       (progn
+          (insert
+           (propertize
+            (format "Author: %s <%s>\n%s%s"
+                    (or author-name committer-name)
+                    (or author-email committer-email)
+                    (if date (format "Date: %s\n" date) "")
+                    (if merge-heads
+                        (format "Merge: %s\n"
+                                (mapconcat 'identity merge-heads " "))
+                      ""))
+            'face 'git-header-face)
+           (propertize git-log-msg-separator 'face 'git-separator-face)
+           "\n")
+          (when subject (insert subject "\n\n"))
+          (cond (msg (insert msg "\n"))
+                ((file-readable-p ".git/rebase-apply/msg")
+                 (insert-file-contents ".git/rebase-apply/msg"))
+                ((file-readable-p ".git/MERGE_MSG")
+                 (insert-file-contents ".git/MERGE_MSG")))))
       ; delete empty lines at end
       (goto-char (point-min))
       (when (re-search-forward "\n+\\'" nil t)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to