How can I get the root directory of the current git repo? I could run
shell-command-to-string on something like
git rev-parse --show-toplevel. Is there a better way? Does
magit or any other git front-end expose this info?
As mentioned by abo-abo, in Emacs 25, there is a function called
vc-root-dir that does what you need in a backend-agnostic manner. For earlier versions of Emacs, the following is a suitable replacement:
(defun vc-root-dir () (let ((backend (vc-deduce-backend))) (and backend (ignore-errors (vc-call-backend backend 'root default-directory)))))
As mentioned by Kyle, Magit provides the function
magit-get-top-dir, which simply calls
git rev-parse --show-cdup and interprets the result.