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

    magit-read-branch-or-commit: Fallback to commit at point as default
    
    If the branch at point isn't used as the default because it is equal
    to the excluded branch, then fall back to the commit at point.
---
 lisp/magit-git.el | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index 1cfc274d63..53a428e74d 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -2622,14 +2622,19 @@ and this option only controls what face is used.")
 
 (defun magit-read-branch-or-commit (prompt &optional secondary-default exclude)
   (let ((current (magit-get-current-branch))
-        (atpoint (magit-branch-or-commit-at-point))
+        (branch-at-point (magit-branch-at-point))
+        (commit-at-point (magit-commit-at-point))
+        (choices (delete exclude (magit-list-refnames nil t)))
         (minibuffer-default-add-function (magit--minibuf-default-add-commit)))
-    (or (magit-completing-read prompt
-                               (delete exclude (magit-list-refnames nil t))
-                               nil nil nil 'magit-revision-history
-                               (or (and (not (equal atpoint exclude)) atpoint)
-                                   secondary-default
-                                   (and (not (equal current exclude)) 
current)))
+    (when (equal current exclude)
+      (setq current nil))
+    (when (equal branch-at-point exclude)
+      (setq branch-at-point nil))
+    (when (and commit-at-point (not branch-at-point))
+      (setq choices (cons commit-at-point choices)))
+    (or (magit-completing-read
+         prompt choices nil nil nil 'magit-revision-history
+         (or branch-at-point commit-at-point secondary-default current))
         (user-error "Nothing selected"))))
 
 (defun magit-read-range-or-commit (prompt &optional secondary-default)

Reply via email to