Function: magit-gitdir
magit-gitdir is a byte-compiled function defined in magit-git.el.
Signature
(magit-gitdir &optional DIRECTORY)
Documentation
Return the absolute and resolved path of the .git directory.
If the GIT_DIR environment variable is defined, return that.
Otherwise return the .git directory for DIRECTORY, or if that is
nil, then for default-directory instead. If the directory is
not located inside a Git repository, then return nil.
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-git.el
(defun magit-gitdir (&optional directory)
"Return the absolute and resolved path of the .git directory.
If the `GIT_DIR' environment variable is defined, return that.
Otherwise return the .git directory for DIRECTORY, or if that is
nil, then for `default-directory' instead. If the directory is
not located inside a Git repository, then return nil."
(let ((default-directory (or directory default-directory)))
(magit--with-refresh-cache (list default-directory 'magit-gitdir)
(magit--with-safe-default-directory nil
(and-let*
((dir (magit-rev-parse-safe "--git-dir"))
(dir (file-name-as-directory (magit-expand-git-file-name dir))))
(if (file-remote-p dir)
dir
(concat (file-remote-p default-directory) dir)))))))