Skip to content

Instantly share code, notes, and snippets.

Last active Dec 22, 2015
What would you like to do?
Custom commit.template for magit-1.2.0
;; Commit template location.
;; It can also be ~/.gitmessage.txt
(defcustom commit-template "./.git/COMMIT_EDITMSG"
"Path to custom message template file. If nil, no custom
message will be inserted to *magit-edit-log* buffer. The path can
be relative as well as absolute."
:group 'magit
:type 'string)
;; and modify this function accordingly
(defun magit-pop-to-log-edit (operation)
(let ((dir default-directory)
(magit-buf (current-buffer))
(buf (get-buffer-create magit-log-edit-buffer-name)))
(setq magit-pre-log-edit-window-configuration
(pop-to-buffer buf)
(setq default-directory dir)
(when (file-exists-p (concat (magit-git-dir) "MERGE_MSG"))
(insert-file-contents (concat (magit-git-dir) "MERGE_MSG")))
(make-local-variable 'magit-buffer-internal)
(setq magit-buffer-internal magit-buf)
;; -------- patch -------
(with-current-buffer magit-log-edit-buffer-name
(if (= (point-min) (point-max))
(goto-char (point-min))
(if (file-exists-p commit-template)
(insert (format "%s" (with-temp-buffer
(insert-file-contents commit-template)
(goto-char (point-min))
;; --------- patch ends here ----------
(message "Type C-c C-c to %s (C-c C-k to cancel)." operation)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment