summaryrefslogtreecommitdiff
path: root/lisp/vc/vc.el
diff options
context:
space:
mode:
authorPhilip Kaludercic <philipk@posteo.net>2022-02-14 12:33:11 +0100
committerPhilip Kaludercic <philipk@posteo.net>2022-02-14 14:59:04 +0100
commit077c9badf9322845a8d2911e48392fa8f4c5939c (patch)
treec9f42a22d00418e367f438d45223b160fe3b7099 /lisp/vc/vc.el
parentd52d913fa032a6cd1b6422cbbd44169b318ca174 (diff)
downloademacs-077c9badf9322845a8d2911e48392fa8f4c5939c.tar.gz
Add new command to clone a repository
* vc.el (vc-clone): Add command
Diffstat (limited to 'lisp/vc/vc.el')
-rw-r--r--lisp/vc/vc.el26
1 files changed, 26 insertions, 0 deletions
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index a6124acadd2..fd0192fad2b 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -568,6 +568,11 @@
;; 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)))))))
+
;; These things should probably be generally available