Function: vc-clone

vc-clone is an interactive and byte-compiled function defined in vc.el.gz.

Signature

(vc-clone REMOTE &optional BACKEND DIRECTORY REV OPEN-DIR)

Documentation

Clone repository REMOTE using version-control BACKEND, into DIRECTORY.

If successful, return the string with the directory of the checkout; otherwise return nil. REMOTE should be a string, the URL of the remote repository or the name of a directory (if the repository is local).

When called interactively, prompt for REMOTE, BACKEND and DIRECTORY, except attempt to determine BACKEND automatically based on REMOTE.

If DIRECTORY is nil or omitted, it defaults to default-directory. If BACKEND is nil or omitted, the function iterates through every known backend in vc-handled-backends until one succeeds to clone REMOTE. If REV is non-nil, it indicates a specific revision to check out after cloning; the syntax of REV depends on what BACKEND accepts. If OPEN-DIR is non-nil, as it is interactively, also switches to a buffer visiting DIRECTORY.

Probably introduced at or before Emacs version 31.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc.el.gz
(defun vc-clone (remote &optional backend directory rev open-dir)
  "Clone repository REMOTE using version-control BACKEND, into DIRECTORY.
If successful, return the string with the directory of the checkout;
otherwise return nil.
REMOTE should be a string, the URL of the remote repository or the name
of a directory (if the repository is local).

When called interactively, prompt for REMOTE, BACKEND and DIRECTORY,
except attempt to determine BACKEND automatically based on REMOTE.

If DIRECTORY is nil or omitted, it defaults to `default-directory'.
If BACKEND is nil or omitted, the function iterates through every known
backend in `vc-handled-backends' until one succeeds to clone REMOTE.
If REV is non-nil, it indicates a specific revision to check out after
cloning; the syntax of REV depends on what BACKEND accepts.
If OPEN-DIR is non-nil, as it is interactively, also switches to a
buffer visiting DIRECTORY."
  (interactive
   (let* ((url (read-string "Remote: " nil 'vc--remotes-history))
          (backend (or (vc-guess-url-backend url)
                       (intern (completing-read
                                "Backend: " vc-handled-backends nil t)))))
     (list url backend
           (read-directory-name
            "Clone into new or empty directory: " nil nil
            (lambda (dir) (or (not (file-exists-p dir))
                              (directory-empty-p dir))))
           nil t)))
  (let* ((directory (expand-file-name (or directory default-directory)))
         (backend (or backend (vc-guess-url-backend remote)))
         (directory (if backend
                        (progn
                          (unless (memq backend vc-handled-backends)
                            (error "Unknown VC backend %s" backend))
                          (vc-call-backend backend 'clone remote directory rev))
                      (catch 'ok
                        (dolist (backend vc-handled-backends)
                          (ignore-error vc-not-supported
                            (when-let* ((res (vc-call-backend
                                              backend 'clone
                                              remote directory rev)))
                              (throw 'ok res))))))))
    (when (file-directory-p directory)
      (when open-dir
        (find-file directory))
      directory)))