branch: elpa/magit
commit 95fee388632149b479a63cb81f8bda06d287ebe4
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    magit-find-file-noselect: Accept nil as synonym for "{worktree}"
    
    Eventually we should instead explicitly signal an error.
---
 lisp/magit-files.el | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lisp/magit-files.el b/lisp/magit-files.el
index 0096e8933a..3a4dc2e08f 100644
--- a/lisp/magit-files.el
+++ b/lisp/magit-files.el
@@ -87,10 +87,13 @@ the line and column corresponding to that location."
 (defun magit-find-file-noselect (rev file &optional no-restore-position)
   "Read FILE from REV into a buffer and return the buffer.
 REV is a revision or one of \"{worktree}\" or \"{index}\"."
-  (when (and (equal rev "{index}")
-             (length> (magit--file-index-stages file) 1))
-    (setq rev "{worktree}"))
-  (let* ((topdir (magit-toplevel))
+  (let* ((rev (pcase rev
+                ('nil "{worktree}")
+                ((and "{index}"
+                      (guard (length> (magit--file-index-stages file) 1)))
+                 "{worktree}")
+                (rev rev)))
+         (topdir (magit-toplevel))
          (file (expand-file-name file topdir))
          (file-relative (file-relative-name file topdir))
          (buffer

Reply via email to