Function: projectile--git-dir

projectile--git-dir is a byte-compiled function defined in projectile.el.

Signature

(projectile--git-dir ROOT)

Documentation

Return the git directory belonging to the checkout at ROOT, or nil.

That's <root>/.git when it is a directory, and the directory named by the gitdir: line when it is the file a linked worktree gets instead.

Nil when ROOT holds no .git at all, which is what distinguishes a checkout from a directory inside one: projectile-project-vcs deliberately answers git for a project below a repository root too, so that file listing can still go through git, but the worktrees of the enclosing repository are not other copies of such a project.

Source Code

;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
;; Everything below reads git's own files rather than running git.  Identity
;; is computed for every known project when looking for the other checkouts
;; of one, and a subprocess apiece would be seconds of latency on a machine
;; with a hundred projects - the same reason `projectile--hg-default-path'
;; parses `.hg/hgrc' directly.  The layout being read is stable and
;; documented in gitrepository-layout(5).

(defun projectile--git-dir (root)
  "Return the git directory belonging to the checkout at ROOT, or nil.

That's `<root>/.git' when it is a directory, and the directory named by
the `gitdir:' line when it is the file a linked worktree gets instead.

Nil when ROOT holds no `.git' at all, which is what distinguishes a
checkout from a directory inside one: `projectile-project-vcs'
deliberately answers `git' for a project below a repository root too, so
that file listing can still go through git, but the worktrees of the
enclosing repository are not other copies of such a project."
  (let ((dot-git (expand-file-name ".git" root)))
    (cond
     ((file-directory-p dot-git) (file-name-as-directory dot-git))
     ((file-readable-p dot-git)
      (with-temp-buffer
        (insert-file-contents dot-git)
        (goto-char (point-min))
        (when (looking-at "gitdir:[ \t]*\\(.+?\\)[ \t]*$")
          (file-name-as-directory
           (expand-file-name (match-string 1) root))))))))