Skip to content

Instantly share code, notes, and snippets.

@psachin
Last active Dec 22, 2015
Embed
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
(current-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")))
(magit-log-edit-mode)
(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))
(progn
(goto-char (point-min))
(if (file-exists-p commit-template)
(insert (format "%s" (with-temp-buffer
(insert-file-contents commit-template)
(buffer-string)))))))
(goto-char (point-min))
(end-of-line))
;; --------- 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