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.
This commit is contained in:
Sean Whitton 2025-08-08 11:47:00 +01:00
parent 74cbe6d740
commit 560aee2fb2
2 changed files with 26 additions and 5 deletions

View file

@ -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)

View file

@ -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)))