3

What is the predicate function to determine if a given file is under version control? (I'm using git.)

4

The canonical way is to call (vc-backend <file>), AFAIK.

2

Try (vc-git-responsible-p (buffer-file-name)).

  • Thanks, that's 95% of the way there. The main hold-up is that it will incorrectly declare a file under version control if it is in a VC'd directory, even if the file itself is supposed to be ignored by VC. It's enough for my limited purposes, but let me leave the post open a bit longer to see if anyone can figure out the last little bit. – Dan Jan 18 '16 at 13:58
  • @Dan, follow up with vc-state – abo-abo Jan 18 '16 at 14:00
  • I think that does it, although the docstring suggests that vc-state could return nil, ignored, or unregistered for a non-VC'd file. Could you add the vc-state part to your answer? (By the way, that looks to be the VC system-agnostic answer.) – Dan Jan 18 '16 at 14:08
0

vc-registered is correct. You just pass it the file path and it will work with any backend. Use vc-responsible-backend to get the backend name.

(vc-registered (buffer-file-name))
;; => t

(vc-responsible-backend (buffer-file-name))
;; => Git
  • Precision from vc-responsible-backend docstring: "If FILE is already registered, return the backend of FILE. If FILE is not registered, then the first backend in `vc-handled-backends' that declares itself responsible for FILE is returned." – JeanPierre Dec 16 '16 at 20:55
-1

These answers are wrong.

You should use (vc-git-registered (file)). Returns t or nil.

(vc-state (file)) returns state of repository. Not a state of a single file. vc-state returns 'up-to-date on file which is not under version control but it's located in directory which us under control of GIT.

  • vc-git-registered seems indeed a good choice if the VC is git, but how is using vc-backend wrong? What you say about vc-state is not what the docstring says, nor what the quick tests I did show. – JeanPierre Mar 20 '16 at 9:46
  • It's because vc-backend gives false results on GIT. It cannot see a difference between files added/staged to git but not commited. vc-backend returns nil on file which is staged already. – Marcin Antczak Mar 21 '16 at 8:52
  • After tesing again, on emacs 24.4.1 both vc-state and vc-backend do recognize staged files. – JeanPierre Mar 28 '16 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.