branch: elpa/magit
commit 6d0075f523eb1d26b91c9f816df0ce0fad987936
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    magit--minibuf-default-add-commit: Handle nil function
    
    `minibuffer-default-add-function' may be nil.
---
 CHANGELOG         |  3 +++
 lisp/magit-git.el | 19 ++++++++++---------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index f482902f363..967f0cfed80 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -19,6 +19,9 @@ Bug fixes:
 - Adapted to a change in ~define-globalized-minor-mode~ in Emacs 30,
   which caused ~diff-hl-mode~ to be enabled in blob buffers.  #5229
 
+- When adding the commit at point to the completion defaults, it was
+  assumed that ~minibuffer-default-add-function~ cannot be nil.
+
 * v4.1.0    2024-09-01
 
 - The library ~git-commit.el~ is no longer distributed as a separate
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index 53a428e74de..1571ee1bcad 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -2603,15 +2603,16 @@ and this option only controls what face is used.")
 (defun magit--minibuf-default-add-commit ()
   (let ((fn minibuffer-default-add-function))
     (lambda ()
-      (if-let ((commit (with-selected-window (minibuffer-selected-window)
-                         (or (magit-thing-at-point 'git-revision-range t)
-                             (magit-commit-at-point)))))
-          (let ((rest (cons commit (delete commit (funcall fn))))
-                (def minibuffer-default))
-            (if (listp def)
-                (append def rest)
-              (cons def (delete def rest))))
-        (funcall fn)))))
+      (let ((rest (and (functionp fn) (funcall fn))))
+        (if-let ((commit (with-selected-window (minibuffer-selected-window)
+                           (or (magit-thing-at-point 'git-revision-range t)
+                               (magit-commit-at-point)))))
+            (let ((rest (cons commit (delete commit rest)))
+                  (def minibuffer-default))
+              (if (listp def)
+                  (append def rest)
+                (cons def (delete def rest))))
+          rest)))))
 
 (defun magit-read-branch (prompt &optional secondary-default)
   (magit-completing-read prompt (magit-list-branch-names)

Reply via email to