branch: elpa/magit
commit 7912c571817c11db6af7a0f3d06ecdb16cdb324d
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit-commit-diff: Do not error outside Git repository
Closes #5526.
---
lisp/git-commit.el | 6 ++++++
lisp/magit-commit.el | 8 +++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/lisp/git-commit.el b/lisp/git-commit.el
index 8f2444d513..aa6e75de82 100644
--- a/lisp/git-commit.el
+++ b/lisp/git-commit.el
@@ -504,6 +504,12 @@ Used as the local value of `header-line-format', in buffer
using
(setq git-commit-usage-message nil) ; show a shorter message")
(defun git-commit-setup ()
+ ;; If an error occurs when `emacsclient' is used, and it turns out
+ ;; to not be triggered by something in this function, then another
+ ;; likely source are functions on `server-switch-hook'. Debugging
+ ;; is suppressed while running that hook, so it may be necessary to
+ ;; force debugging by modifying those functions directly. Enabling
+ ;; `magit-process-record-invocations' may also help.
(let ((gitdir default-directory)
(cd (and git-commit-cd-to-toplevel
(or (car (rassoc default-directory magit--separated-gitdirs))
diff --git a/lisp/magit-commit.el b/lisp/magit-commit.el
index fb9df9c69e..72c5ff75cd 100644
--- a/lisp/magit-commit.el
+++ b/lisp/magit-commit.el
@@ -669,7 +669,13 @@ an alternative implementation."
'magit-commit--rebase
last-command))
(when (and git-commit-mode magit-commit-show-diff)
- (when-let ((diff-buffer (magit-get-mode-buffer 'magit-diff-mode)))
+ (when-let ((diff-buffer
+ ;; This signals an error if not inside a Git repository,
+ ;; but the user may be visiting COMMIT_EDITMSG using a
+ ;; tool other than git, which can be used outside a Git
+ ;; repository. See #5527.
+ (ignore-error magit-outside-git-repo
+ (magit-get-mode-buffer 'magit-diff-mode))))
;; This window just started displaying the commit message
;; buffer. Without this that buffer would immediately be
;; replaced with the diff buffer. See #2632.