]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new command to clone a repository
authorPhilip Kaludercic <philipk@posteo.net>
Mon, 14 Feb 2022 11:33:11 +0000 (12:33 +0100)
committerPhilip Kaludercic <philipk@posteo.net>
Mon, 14 Feb 2022 13:59:04 +0000 (14:59 +0100)
* vc.el (vc-clone): Add command

lisp/vc/vc.el

index a6124acadd2ce42aa3b3557b4aae44fc8b211896..fd0192fad2b03d8bf400250af90c772194fbbfb0 100644 (file)
 ;;   containing FILE-OR-DIR.  The optional REMOTE-NAME specifies the
 ;;   remote (in Git parlance) whose URL is to be returned.  It has
 ;;   only a meaning for distributed VCS and is ignored otherwise.
+;;
+;; - clone (remote directory)
+;;
+;;   Attempt to clone a REMOTE repository, into a local DIRECTORY.
+;;   Returns the symbol of the backend used if successful.
 
 ;;; Changes from the pre-25.1 API:
 ;;
@@ -3233,6 +3238,27 @@ to provide the `find-revision' operation instead."
   (interactive)
   (vc-call-backend (vc-backend buffer-file-name) 'check-headers))
 
+(defun vc-clone (backend remote &optional directory)
+  "Use BACKEND to clone REMOTE into DIRECTORY.
+If successful, returns the symbol of the backed used to clone.
+If BACKEND is nil, iterate through every known backend in
+`vc-handled-backends' until one succeeds."
+  (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)
+        backend)
+    (catch 'ok
+      (dolist (backend vc-handled-backends)
+        (ignore-error vc-not-supported
+          (when-let (res (vc-call-backend
+                          backend 'clone
+                          remote directory))
+            (throw 'ok backend)))))))
+
 \f
 
 ;; These things should probably be generally available