Function: vc-move-working-tree
vc-move-working-tree is an autoloaded, interactive and byte-compiled
function defined in vc.el.gz.
Signature
(vc-move-working-tree BACKEND FROM TO)
Documentation
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 for the directory file names of each of the other working trees FROM and TO. BACKEND is the VC backend.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/vc/vc.el.gz
;;;###autoload
(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 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)))
(list backend
(vc--prompt-other-working-tree backend "Relocate working tree"
'allow-empty)
(read-directory-name "New location for working tree: "
(file-name-parent-directory (vc-root-dir))))))
(let* ((move-this (file-in-directory-p default-directory from))
(default-directory
(if move-this
(or (car (vc-call-backend backend
'known-other-working-trees))
(user-error "No other working trees"))
default-directory)))
(let ((inhibit-message t))
(project-forget-project from))
(vc-call-backend backend 'move-working-tree from to))
;; Update visited file names for buffers visiting files under FROM.
(let ((from (expand-file-name from)))
(dired-rename-subdir from (expand-file-name to))
(dolist (buf vc-dir-buffers)
(when (buffer-live-p buf)
(with-current-buffer buf
(when (string-prefix-p from default-directory)
(setq default-directory
(expand-file-name (file-relative-name default-directory from)
to))
;; If the *vc-dir* buffer has a uniquify'd name then we need
;; to obtain an new uniquify'd name for this buffer under
;; the new working tree, replacing the one for the old
;; working tree. See also `vc-dir-prepare-status-buffer'.
(when-let* ((base-name (uniquify-buffer-base-name))
(item (cl-find (current-buffer) uniquify-managed
:key #'uniquify-item-buffer)))
(let (name)
;; FIXME: There should be a way to get this information
;; without creating and killing a buffer.
(unwind-protect
(setq name (buffer-name
(create-file-buffer
(expand-file-name base-name
default-directory))))
(kill-buffer name))
(uniquify-rename-buffer item name))))))))
(when-let* ((p (project-current nil to)))
(project-remember-project p)))