I call git get the toplevel dir (according to Is there a way to get the git root directory in one command? ).
(let ((tmpbuffer (get-buffer-create (make-temp-
Assuming it is stored in a variable output-string, the final newline at the end can be removed this way:
output-string
(substring output-string 0 -1)
With the shell-command way, it would look like this:
shell-command
(substring (shell-command-to-string "git rev-parse --show-toplevel") 0 -1)