Function: magit-file-relative-name
magit-file-relative-name is a byte-compiled function defined in
magit-git.el.
Signature
(magit-file-relative-name &optional FILE TRACKED)
Documentation
Return the path of FILE relative to the repository root.
If optional FILE is nil or omitted, return the relative path of the file being visited in the current buffer, if any, else nil. If the file is not inside a Git repository, then return nil.
If TRACKED is non-nil, return the path only if it matches a tracked file.
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-git.el
;;;; File Names
(defun magit-file-relative-name (&optional file tracked)
"Return the path of FILE relative to the repository root.
If optional FILE is nil or omitted, return the relative path of
the file being visited in the current buffer, if any, else nil.
If the file is not inside a Git repository, then return nil.
If TRACKED is non-nil, return the path only if it matches a
tracked file."
(with-current-buffer (or (buffer-base-buffer) (current-buffer))
(and-let* ((file (or file
(magit-buffer-file-name)
(and (derived-mode-p 'dired-mode)
default-directory)))
(dir (magit-toplevel (magit--safe-default-directory
(file-name-parent-directory file))))
(_(or (not tracked)
(magit-file-tracked-p file))))
(file-relative-name file dir))))