]> git.eshelyaron.com Git - emacs.git/commitdiff
vc-clone: Make interactive; call vc-guess-url-backend
authorAleksandr Vityazev <avityazev@disroot.org>
Thu, 24 Oct 2024 12:19:34 +0000 (15:19 +0300)
committerEshel Yaron <me@eshelyaron.com>
Fri, 25 Oct 2024 06:31:52 +0000 (08:31 +0200)
* lisp/vc/vc.el (vc-clone): Make interactive.  Call
vc-guess-url-backend.  Always return DIRECTORY if it names a
directory.  New optional argument OPEN-DIR.
(vc--remotes-history): New defvar.
* etc/NEWS: Announce these changes.

(cherry picked from commit be29879850028d316592ba82cd859d31a67c1ffe)

etc/NEWS
lisp/vc/vc.el

index 6cff82c7e07743f0c8564754e8910f9adf4d4691..c09c8276f85001e083d7a5c4c75e68eee91506a5 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -547,6 +547,16 @@ even though Emacs thinks it is dangerous.
 
 So far, this applies only to using 'e' from Log View mode for Git.
 
+*** 'vc-clone' is now an interactive command.
+When called interactively, 'vc-clone' now prompts for the remote
+repository address, the backend for cloning, if it has not been
+determined automatically according to the URL, and the directory to
+clone the repository into.
+
+*** 'vc-clone' now accepts an optional argument OPEN-DIR.
+When the argument is non-nil, the function switches to a buffer visiting
+directory to which the repository was cloned.
+
 \f
 * New Modes and Packages in Emacs 31.1
 
index 54e5d0ce067f6394884e07bb1ce16c0268fc30a6..f6436ebb9bf9c181a6fb673d855a613512cf1cbc 100644 (file)
@@ -3876,7 +3876,9 @@ to provide the `find-revision' operation instead."
   (interactive)
   (vc-call-backend (vc-backend buffer-file-name) 'check-headers))
 
-(defun vc-clone (remote &optional backend directory rev)
+(defvar vc--remotes-history)
+
+(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.
@@ -3886,21 +3888,42 @@ 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."
-  (unless directory
-    (setq directory default-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)))))))
+cloning; the syntax of REV depends on what BACKEND accepts.
+If OPEN-DIR is non-nil, switches to a buffer visiting DIRECTORY to
+which the repository was cloned.  It would be useful in scripts, but not
+in regular code.
+If called interactively, prompt for REMOTE, DIRECTORY and BACKEND,
+if BACKEND has not been automatically determined according to the REMOTE
+URL, in the minibuffer."
+  (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)))
 
 (declare-function log-view-current-tag "log-view" (&optional pos))
 (defun vc-default-last-change (_backend file line)