From 283b47ab2e38503aa657d877f5cf353e652e1cd7 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Tue, 5 May 2026 12:17:53 +0100 Subject: [PATCH] vc-switch-working-tree: Don't find non-VC projects * lisp/vc/vc.el (project-current-directory-override): Delete declaration. (project-find-matching-buffer-function): Declare. (vc-switch-working-tree): Don't find non-VC projects (bug#80939). --- lisp/vc/vc.el | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 303926b8159..4ecfb2d1e98 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -5772,7 +5772,7 @@ If ALLOW-CURRENT is non-nil, allow selecting the current working tree." 'require-known)) (if (string-empty-p res) (vc-root-dir) res))) -(defvar project-current-directory-override) +(defvar project-find-matching-buffer-function) ;;;###autoload (defun vc-switch-working-tree (directory) @@ -5786,8 +5786,17 @@ to the root of this working tree." (list (vc--prompt-other-working-tree (vc-responsible-backend default-directory) "Other working tree to visit"))) - (let ((project-current-directory-override directory)) - (project-find-matching-buffer))) + (let ((backend (or (vc-deduce-backend) + (vc-responsible-backend default-directory) + (error "No VC backend")))) + ;; Manually construct VC project objects because `project-current' + ;; might find a non-VC project within the VC working tree containing + ;; DIRECTORY, but we should ignore that (bug#80939). + (funcall project-find-matching-buffer-function + `(vc ,backend ,(vc-root-dir backend)) + `(vc ,backend + ,(let ((default-directory directory)) + (vc-root-dir backend)))))) ;;;###autoload (defun vc-working-tree-switch-project (dir)