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?

有帮助吗?

解决方案

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))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top