{"thread":{"id":"34144","subject":"[PATCH] . git.el: use commit.template if available","startedAt":"2013-06-14T17:25:35Z","lastAt":"2013-06-14T17:51:04Z","messageCount":2,"participants":["Curt Brune","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"220895","messageId":"20130614172535.GA24983@higgs.cumulusnetworks.com","threadId":"34144","inReplyTo":null,"subject":"[PATCH] . git.el: use commit.template if available","fromName":"Curt Brune","fromEmail":"curt@brune.net","sentAt":"2013-06-14T17:25:35Z","receivedAt":"2013-06-14T17:25:35Z","isPatch":true,"sender":{"key":"curt@brune.net","avatar":null},"body":"\nIf the user's git config defines commit.template then include the\ncontents of that file in the log buffer by default.\n\nIn git-setup-log-buffer, instead of supplying the default commit\nmessage insert the user's commit.template.\n\nSigned-off-by: Curt Brune <curt@brune.net>\n---\n contrib/emacs/git.el |   47 ++++++++++++++++++++++++++++-------------------\n 1 file changed, 28 insertions(+), 19 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex 5ffc506..827578f 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -296,6 +296,11 @@ the process output as a string, or nil if the git command failed.\"\n       (and (fboundp 'user-mail-address) (user-mail-address))\n       (and (boundp 'user-mail-address) user-mail-address)))\n \n+(defun git-get-commit-template ()\n+  \"Return the git commit template or nil\"\n+  ; copied from log-edit\n+  (git-config \"commit.template\"))\n+\n (defun git-get-commits-coding-system ()\n   \"Return the coding system to use for commits.\"\n   (let ((repo-config (git-config \"i18n.commitencoding\")))\n@@ -1280,29 +1285,33 @@ The FILES list must be sorted.\"\n   (let ((dir default-directory)\n         (committer-name (git-get-committer-name))\n         (committer-email (git-get-committer-email))\n+        (commit-template (git-get-commit-template))\n         (sign-off git-append-signed-off-by))\n     (with-current-buffer buffer\n       (cd dir)\n       (erase-buffer)\n-      (insert\n-       (propertize\n-        (format \"Author: %s <%s>\\n%s%s\"\n-                (or author-name committer-name)\n-                (or author-email committer-email)\n-                (if date (format \"Date: %s\\n\" date) \"\")\n-                (if merge-heads\n-                    (format \"Merge: %s\\n\"\n-                            (mapconcat 'identity merge-heads \" \"))\n-                  \"\"))\n-        'face 'git-header-face)\n-       (propertize git-log-msg-separator 'face 'git-separator-face)\n-       \"\\n\")\n-      (when subject (insert subject \"\\n\\n\"))\n-      (cond (msg (insert msg \"\\n\"))\n-            ((file-readable-p \".git/rebase-apply/msg\")\n-             (insert-file-contents \".git/rebase-apply/msg\"))\n-            ((file-readable-p \".git/MERGE_MSG\")\n-             (insert-file-contents \".git/MERGE_MSG\")))\n+      (if commit-template\n+\t  (insert-file-contents commit-template)\n+\t(progn\n+          (insert\n+           (propertize\n+            (format \"Author: %s <%s>\\n%s%s\"\n+                    (or author-name committer-name)\n+                    (or author-email committer-email)\n+                    (if date (format \"Date: %s\\n\" date) \"\")\n+                    (if merge-heads\n+                        (format \"Merge: %s\\n\"\n+                                (mapconcat 'identity merge-heads \" \"))\n+                      \"\"))\n+            'face 'git-header-face)\n+           (propertize git-log-msg-separator 'face 'git-separator-face)\n+           \"\\n\")\n+          (when subject (insert subject \"\\n\\n\"))\n+          (cond (msg (insert msg \"\\n\"))\n+                ((file-readable-p \".git/rebase-apply/msg\")\n+                 (insert-file-contents \".git/rebase-apply/msg\"))\n+                ((file-readable-p \".git/MERGE_MSG\")\n+                 (insert-file-contents \".git/MERGE_MSG\")))))\n       ; delete empty lines at end\n       (goto-char (point-min))\n       (when (re-search-forward \"\\n+\\\\'\" nil t)\n-- \n1.7.9.5\n"},{"id":"220897","messageId":"7v1u84pomv.fsf@alter.siamese.dyndns.org","threadId":"34144","inReplyTo":"20130614172535.GA24983@higgs.cumulusnetworks.com","subject":"Re: [PATCH] . git.el: use commit.template if available","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-06-14T17:51:04Z","receivedAt":"2013-06-14T17:51:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Curt Brune <curt@brune.net> writes:\n\n> If the user's git config defines commit.template then include the\n> contents of that file in the log buffer by default.\n>\n> In git-setup-log-buffer, instead of supplying the default commit\n> message insert the user's commit.template.\n>\n> Signed-off-by: Curt Brune <curt@brune.net>\n> ---\n\nInteresting.\n\nI wonder if git-do-commit still needs to reimplement the commit\nlogic using low-level plumbing in this era, which I think is the\ncause of having to constantly catch up with what \"git commit\"\nPorcelain does (like paying attention to configuration variables).\n\nI often just do\n\n\tM-x compile<ENTER>git commit args...<ENTER>\n\nwhile setting my EDITOR to 'emacsclient', and I have a suspicion\nthat the callchain from git-commit-file to git-setup-log-buffer can\nbe quite simplified if such an approach is used.  Enumerate the\nmarked file(s) to formulate the \"git commit\" command line and let\nthe underlying \"git commit\" do the heavy-lifting, that is.\n"}]}