threads / patch / 34144

patch. git.el: use commit.template if available

Subject: [PATCH] . git.el: use commit.template if available

## tl;dr

2 messages between Jun 14, 2013 and Jun 14, 2013. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Curt Brune· Jun 14, 2013, 17:25 UTC · lore

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 <curt@brune.net>
---
 contrib/emacs/git.el |   47 ++++++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 19 deletions(-)
Show changes to contrib/emacs/git.el +28 −19
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
Junio C Hamano· Jun 14, 2013, 17:51 UTC · re: Curt Brune · lore

Re: [PATCH] . git.el: use commit.template if available

Curt Brune <curt@brune.net> writes:
Show 8 quoted lines
> 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 <curt@brune.net>
> ---
Interesting.

I wonder if git-do-commit still needs to reimplement the commit logic using low-level plumbing in this era, which I think is the cause of having to constantly catch up with what "git commit" Porcelain does (like paying attention to configuration variables).

I often just do
	M-x compile<ENTER>git commit args...<ENTER>

while setting my EDITOR to 'emacsclient', and I have a suspicion that the callchain from git-commit-file to git-setup-log-buffer can be quite simplified if such an approach is used. Enumerate the marked file(s) to formulate the "git commit" command line and let the underlying "git commit" do the heavy-lifting, that is.

← back to recent threads