Function: eca--git-common-dir
eca--git-common-dir is a natively compiled function defined in
eca-util.el.
Signature
(eca--git-common-dir DIR)
Documentation
Return the absolute git common dir for DIR, or nil if not in a git repo.
Uses `git rev-parse --git-common-dir` to find the shared git
directory, which is the same for all worktrees of a repository.
Results are cached in eca--git-common-dir-cache since this can
be called repeatedly (e.g. resolving sessions from timers) and
spawning git each time causes visible lag (#275).
Source Code
;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-util.el
(defun eca--git-common-dir (dir)
"Return the absolute git common dir for DIR, or nil if not in a git repo.
Uses `git rev-parse --git-common-dir` to find the shared git
directory, which is the same for all worktrees of a repository.
Results are cached in `eca--git-common-dir-cache' since this can
be called repeatedly (e.g. resolving sessions from timers) and
spawning git each time causes visible lag (#275)."
(let* ((dir (expand-file-name dir))
(cached (gethash dir eca--git-common-dir-cache)))
(if cached
(unless (eq cached :none) cached)
(let* ((default-directory dir)
(output (ignore-errors
(string-trim
(with-output-to-string
(with-current-buffer standard-output
;; TRAMP-aware, no intermediate shell,
;; stderr discarded.
(process-file "git" nil '(t nil) nil
"rev-parse" "--git-common-dir"))))))
(result (when (and output
(not (string-empty-p output))
;; Git < 2.5 echoes the flag back literally
(not (string= output "--git-common-dir")))
(expand-file-name output default-directory))))
(puthash dir (or result :none) eca--git-common-dir-cache)
result))))