From 560aee2fb2403a6c7205798e05725abda2bc5cbc Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 8 Aug 2025 11:47:00 +0100 Subject: [PATCH] vc-move-working-tree: Also update VC-Dir buffers * lisp/vc/vc.el (vc-move-working-tree): Also update VC-Dir buffers to follow the working tree move. --- lisp/vc/vc-dir.el | 2 +- lisp/vc/vc.el | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el index 93a05412a04..80d6dd3a4ff 100644 --- a/lisp/vc/vc-dir.el +++ b/lisp/vc/vc-dir.el @@ -194,7 +194,7 @@ That is, refreshing the VC-Dir buffer also hides `up-to-date' and (cl-return buffer)))))))) (or buf ;; Create a new buffer named BNAME. - ;; We pass a filename to create-file-buffer because it is what + ;; We pass a filename to `create-file-buffer' because it is what ;; the function expects, and also what uniquify needs (if active) (with-current-buffer (create-file-buffer (expand-file-name bname dir)) (setq default-directory dir) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 4fe87d860d1..63a4fafc56c 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -4472,8 +4472,8 @@ BACKEND is the VC backend." (defun vc-move-working-tree (backend from to) "Relocate a working tree from FROM to TO, two directory file names. Must be called from within an existing VC working tree. -When called interactively, prompts the directory file names of each of -the other working trees FROM and TO. +When called interactively, prompts for the directory file names of each +of the other working trees FROM and TO. BACKEND is the VC backend." (interactive (let ((backend (vc-responsible-backend default-directory))) @@ -4486,8 +4486,29 @@ BACKEND is the VC backend." (vc-call-backend backend 'move-working-tree from to) ;; Update visited file names for buffers visiting files under FROM. - ;; FIXME: Also update VC-Dir buffers. - (dired-rename-subdir (expand-file-name from) (expand-file-name to)) + (let ((from (expand-file-name from))) + (dired-rename-subdir from (expand-file-name to)) + (dolist (buf vc-dir-buffers) + (with-current-buffer buf + (when (string-prefix-p from default-directory) + (setq default-directory + (expand-file-name (file-relative-name default-directory from) + to)) + ;; Obtain an appropriately uniquify'd name for a *vc-dir* + ;; buffer in the new working tree. In particular if this + ;; *vc-dir* buffer already has a uniquify'd name appropriate + ;; for the old working tree, we must replace that. + ;; See also `vc-dir-prepare-status-buffer'. + ;; FIXME: There should be a way to get this information + ;; without creating and killing a buffer. + (let (name) + (unwind-protect + (setq name (buffer-name + (create-file-buffer + (expand-file-name "*vc-dir*" + default-directory)))) + (kill-buffer name)) + (rename-buffer name)))))) (when-let* ((p (project-current nil to))) (project-remember-project p)))