Currently, `magit-log-edit-commit' erases and buries the commit log buffer, then
proceeds to do things that rely on the `magit-git-dir'. This function isn't
going to work as expected unless the buffer that is current after `bury-buffer'
is located under the `magit-git-dir' -- but there is no guarantee of that.
Indeed there is no guarantee that any such buffers exist (they may all have been
deleted). Given the semantics of `bury-buffer' it is sheer luck if you end
up in the right place, and it is quite likely that `magit-git-dir' will simply
crash.
The solution is to record the *magit* buffer itself (not its name, the buffer
itself) in a variable local to the commit log buffer, so that it is guaranteed
that we always have a suitable buffer to switch back to even if it's been
killed, then switch back to it at `magit-log-edit-commit' time.
---
magit.el | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/magit.el b/magit.el
index ec43fcc..fb7b142 100644
--- a/magit.el
+++ b/magit.el
@@ -4448,7 +4448,9 @@ environment (potentially empty)."
(if sign-off '("--signoff") '()))))))))
;; shouldn't we kill that buffer altogether?
(erase-buffer)
- (bury-buffer)
+ (let ((magit-buf magit-buffer))
+ (bury-buffer)
+ (set-buffer magit-buf))
(when (file-exists-p (concat (magit-git-dir) "MERGE_MSG"))
(delete-file (concat (magit-git-dir) "MERGE_MSG")))
;; potentially the local environment has been altered with settings that
@@ -4502,6 +4504,7 @@ This means that the eventual commit does 'git commit
--allow-empty'."
(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))
@@ -4510,6 +4513,8 @@ This means that the eventual commit does 'git commit
--allow-empty'."
(insert-file-contents (concat (magit-git-dir) "MERGE_MSG")))
(setq default-directory dir)
(magit-log-edit-mode)
+ (make-local-variable 'magit-buffer)
+ (setq magit-buffer magit-buf)
(message "Type C-c C-c to %s (C-c C-k to cancel)." operation)))
(defun magit-log-edit (&optional arg)
--
1.7.10.151.g08b2b