vc-refresh-state: Override default-directory for backend functions

I ran into the issue described in the comment with the current
code in project-find-file-in and project-find-dir, when using
'C-x p p' to switch between projects.

* lisp/vc/vc-hooks.el (vc-refresh-state): When calling into the
backend, override any let-bindings of default-directory.
This commit is contained in:
Sean Whitton 2026-05-18 22:15:29 +01:00
parent 389874c533
commit 28a13b01c7

View file

@ -955,10 +955,16 @@ In the latter case, VC mode is deactivated for this buffer."
(cond
((setq backend (with-demoted-errors "VC refresh error: %S"
(vc-backend buffer-file-name)))
;; Let the backend setup any buffer-local things he needs.
(vc-call-backend backend 'find-file-hook)
;; Compute the state and put it in the mode line.
(vc-mode-line buffer-file-name backend)
;; When `auto-revert-handler' calls us then `default-directory'
;; may be let-bound to something else for the purpose of some
;; command that's currently doing some minibuffer prompting.
;; Backend find-file-hook and mode-line-string functions should
;; not need to be written so as to handle that possibility.
(let ((default-directory (buffer-local-toplevel-value 'default-directory)))
;; Let the backend setup any buffer-local things it needs.
(vc-call-backend backend 'find-file-hook)
;; Compute the state and put it in the mode line.
(vc-mode-line buffer-file-name backend))
(unless vc-make-backup-files
;; Use this variable, not make-backup-files,
;; because this is for things that depend on the file name.