Add +magit/clone command & bind to SPC g C #633
magithub-clone doesn't support full urls, magit-clone doesn't support user/repo notation. +magit/clone supports both.
This commit is contained in:
parent
183ccbb8f1
commit
3a16b70022
2 changed files with 32 additions and 1 deletions
|
@ -20,3 +20,34 @@
|
|||
(kill-process process)
|
||||
(kill-buffer buf)))))))
|
||||
|
||||
(defvar +magit-clone-history nil
|
||||
"History for `+magit/clone' prompt.")
|
||||
;;;###autoload
|
||||
(defun +magit/clone (url-or-repo dir)
|
||||
"Delegates to `magit-clone' or `magithub-clone' depending on the repo url
|
||||
format."
|
||||
(interactive
|
||||
(progn
|
||||
(require 'magithub)
|
||||
(let* ((user (ghubp-username))
|
||||
(repo (read-from-minibuffer
|
||||
"Clone repository (user/repo or url): "
|
||||
(if user (concat user "/"))
|
||||
nil nil '+magit-clone-history))
|
||||
(name (car (last (split-string repo "/" t)))))
|
||||
(list repo
|
||||
(read-directory-name
|
||||
"Destination: "
|
||||
magithub-clone-default-directory
|
||||
name nil name)))))
|
||||
(require 'magithub)
|
||||
(if (string-match "^\\([^/]+\\)/\\([^/]+\\)$" url-or-repo)
|
||||
(let ((repo `((owner (login . ,(match-string 1 url-or-repo)))
|
||||
(name . ,(match-string 2 url-or-repo)))))
|
||||
(and (or (magithub-request
|
||||
(ghubp-get-repos-owner-repo repo))
|
||||
(let-alist repo
|
||||
(user-error "Repository %s/%s does not exist"
|
||||
.owner.login .name)))
|
||||
(magithub-clone repo dir)))
|
||||
(magit-clone url-or-repo dir)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue