From 3379d7f46710e158adf4aee6a95940bbd60d53c8 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Sat, 7 Mar 2015 13:04:16 -0800 Subject: [PATCH] [commit-patch-buffer] Retrieve last comment when amending. This only works in Git, but then amending really only works in git. --- commit-patch-buffer.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/commit-patch-buffer.el b/commit-patch-buffer.el index 17ca98c..57ecb7a 100644 --- a/commit-patch-buffer.el +++ b/commit-patch-buffer.el @@ -34,6 +34,23 @@ (let ((current (or load-file-name (buffer-file-name)))) (expand-file-name "commit-patch" (file-name-directory current)))) +;; Based on vc-git-expanded-log-entry, but don't indent and only grab the full comment using --pretty +(defun commit-patch-git-log-comment (revision) + (with-temp-buffer + (apply 'vc-git-command t nil nil (list "log" "--pretty=format:%B" revision "-1")) + (goto-char (point-min)) + (unless (eobp) + (buffer-string)))) + +;; Currently commit-patch only supports --amend with Git and Darcs. +;; But Darcs amend is very interactive, so we don't support it here. +(defun commit-patch-last-log-comment (directory) + (let ((default-directory directory)) + (pcase (vc-responsible-backend directory) + (`Git + (commit-patch-git-log-comment "HEAD"))))) + + (defun commit-patch-buffer-in-directory (buffer directory &optional amend) "Commit the patch found in BUFFER by applying it to the repository in DIRECTORY with commit-patch(1). If AMEND is @@ -53,6 +70,11 @@ one." (with-current-buffer buf (vc-buffer-sync)) (add-to-list 'visiting-buffers buf))) (setq f (cdr f))) + (if amend + (with-current-buffer (get-buffer-create "*commit*") + (erase-buffer) + (insert (or (commit-patch-last-log-comment directory) "")) + (goto-char 0))) (log-edit `(lambda () (interactive) (let ((patch (make-temp-file "commit-buffer" nil)) -- 2.51.2