Function: vc-delete-working-tree

vc-delete-working-tree is an autoloaded, interactive and byte-compiled function defined in vc.el.gz.

Signature

(vc-delete-working-tree BACKEND DIRECTORY)

Documentation

Delete working tree DIRECTORY with same backing repository as this tree.

Must be called from within an existing VC working tree. When called interactively, prompts for DIRECTORY. BACKEND is the VC backend.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc.el.gz
;;;###autoload
(defun vc-delete-working-tree (backend directory)
  "Delete working tree DIRECTORY with same backing repository as this tree.
Must be called from within an existing VC working tree.
When called interactively, prompts for DIRECTORY.
BACKEND is the VC backend."
  (interactive
   (let ((backend (vc-responsible-backend default-directory)))
     (list backend
           (vc--prompt-other-working-tree backend "Delete working tree"
                                          'allow-empty))))
  (let* ((delete-this (file-in-directory-p default-directory directory))
         (directory (expand-file-name directory))
         (default-directory
          (if delete-this
              (or (car (vc-call-backend backend
                                        'known-other-working-trees))
                  (user-error "No other working trees"))
            default-directory))
         (status (vc-dir-status-files directory nil backend)))

    ;; We could consider not prompting here, thus always failing when
    ;; there is uncommitted work, and requiring the user to review and
    ;; revert the uncommitted changes before invoking this command again.
    ;; But other working trees are often created as throwaways to quickly
    ;; test some changes, so it is more useful to offer to recursively
    ;; delete them on the user's behalf.
    (when (and status
               (not (yes-or-no-p (format "\
%s contains uncommitted work.  Continue to recursively delete it?" directory))))
      (user-error "Aborted due to uncommitted work in %s" directory))
    ;; Extra prompt to avoid a surprise after accidentally typing 'RET'.
    (when (and (not status) delete-this
               (not (yes-or-no-p (format "Really delete working tree %s?"
                                         directory))))
      (user-error "Aborted"))

    (project-forget-project directory)
    (vc-call-backend backend 'delete-working-tree directory)
    (when delete-this
      (bury-buffer)
      (while (string-prefix-p directory default-directory)
        (bury-buffer)))))