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

    magit-find-file-noselect: Assert file is in repository
    
    Also no longer claim that FILE must be a relative to the repository
    top-level.  That stopped being the case a while ago.  While the file
    still usually is given as a relative path, that is no longer required.
    Also update docstring of `magit-find-file-index-noselect' accordingly.
---
 lisp/magit-files.el | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/magit-files.el b/lisp/magit-files.el
index fd705cf2ba9..73541d74c7e 100644
--- a/lisp/magit-files.el
+++ b/lisp/magit-files.el
@@ -112,10 +112,9 @@ the line and column corresponding to that location."
 
 (defun magit-find-file-noselect (rev file &optional revert)
   "Read FILE from REV into a buffer and return the buffer.
-REV is a revision or one of \"{worktree}\" or \"{index}\".  FILE must
-be relative to the top directory of the repository.  Non-nil REVERT
-means to revert the buffer.  If `ask-revert', then only after asking.
-A non-nil value for REVERT is ignored if REV is \"{worktree}\"."
+REV is a revision or one of \"{worktree}\" or \"{index}\".  Non-nil
+REVERT means to revert the buffer.  If `ask-revert', then only after
+asking.  A non-nil value for REVERT is ignored if REV is \"{worktree}\"."
   (cond-let*
     [[topdir (magit-toplevel)]
      [file (expand-file-name file topdir)]]
@@ -129,6 +128,8 @@ A non-nil value for REVERT is ignored if REV is 
\"{worktree}\"."
     ([_ topdir]
      [defdir (file-name-directory file)]
      [rev (magit--abbrev-if-hash rev)]
+     (unless (file-in-directory-p file topdir)
+       (error "%s is not in repository %s" file topdir))
      (with-current-buffer (magit-get-revision-buffer-create
                            rev
                            (file-relative-name file topdir))
@@ -198,8 +199,7 @@ See also https://github.com/doomemacs/doomemacs/pull/6309.";
 ;;; Find Index
 
 (defun magit-find-file-index-noselect (file &optional revert)
-  "Read FILE from the index into a buffer and return the buffer.
-FILE must to be relative to the top directory of the repository."
+  "Read FILE from the index into a buffer and return the buffer."
   (magit-find-file-noselect "{index}" file (or revert 'ask-revert)))
 
 (defun magit-update-index ()

Reply via email to