1

vc-git-root walks up the tree until it finds the directory that contains the .git subdir and declares that to be the root of the repo.

But if there is not .git folder in the root directory, (vc-git-root (buffer-file-name)) gives following error Error running timer: (void-function vc-git-root).

How could I fix it?

config:

(defun my-find-files ()
  (interactive)
  (message "press t to toggle mark for all files found && Press Q for Query-Replace in Files...")
  (find-dired (vc-git-root (buffer-file-name)) "-name \\*.py"))

Related:

alper
  • 1,238
  • 11
  • 30
  • Have you tried `condition-case`, testing for such an error? Or if you want to ignore all errors, `ignore-error`. – Drew Oct 26 '21 at 19:51
  • What timers do you have running? *What* are they running? Why is `vc-git-root` called from a timer? What does the error have to do with `my-find-files`? IN my experiment, if there is no `.git` file found, then `vc-git-root` returns `nil`. – NickD Oct 26 '21 at 20:26
  • @NickD I am not sure what timer is running on the background. I just have following function related to `vc-git-root` in my config file. And I forget to use `(require 'vc-git)` – alper Oct 27 '21 at 10:28
  • You might want to find out: `(list-timers)` and maybe chase it down further. Or not ... – NickD Oct 27 '21 at 12:18

1 Answers1

1

But if there is not .git folder in the root directory ... (void-function vc-git-root)

That error means that the function hasn't been defined.

The problem is that you haven't loaded the vc-git library before trying to use one of its functions. That was only working in other cases because when you are in a git directory, vc figures that out and loads the library for you.

(require 'vc-git)
phils
  • 48,657
  • 3
  • 76
  • 115