Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the VC root in Emacs Lisp

In an Emacs Lisp function, I want to know the VC root of an arbitrary folder (if under source control), the same as something like vc-print-root-log does it. I'm trying to do it from outside the VC file/folder (though creating a temporary buffer to do this would be fine). I currently have a git-only solution through magit - (magit-get-top-dir dir-name).

I tried using (vc-deduce-backend) and the 'root command, but the variables that vc-deduce-backend checks seems to only be set in existing vc mode (e.g. log-view-mode) buffers.

Is there a simple way to get this out of VC?

like image 940
Jesse Millikan Avatar asked Apr 20 '13 21:04

Jesse Millikan


1 Answers

Looking at your own example of vc-print-root-log, the following seems to be what you're after:

(require 'vc)
(let ((path "~/.emacs.d/el-get/"))
  (vc-call-backend (vc-responsible-backend path) 'root path))
like image 192
phils Avatar answered Sep 27 '22 22:09

phils