From ecfe52f71cc604407c5ef15e8a2f73845af9d2c8 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 18 Feb 2019 18:25:57 -0500 Subject: [PATCH] Fix +magit/clone to no longer use magithub --- modules/tools/magit/autoload.el | 49 ++++++++++++++++----------------- modules/tools/magit/config.el | 5 ++++ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/modules/tools/magit/autoload.el b/modules/tools/magit/autoload.el index a3b1d12b5..451b64e30 100644 --- a/modules/tools/magit/autoload.el +++ b/modules/tools/magit/autoload.el @@ -92,33 +92,30 @@ control in buffers." "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." + "Like `magit-clone', but supports additional formats on top of absolute URLs: + ++ USER/REPO: assumes {`+magit-default-clone-url'}/USER/REPO ++ REPO: assumes {`+magit-default-clone-url'}/{USER}/REPO, where {USER} is + ascertained from your global gitconfig." (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))) + (let* ((user (ghub--username (ghub--host))) + (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: " + magit-clone-default-directory + name nil name)))) + (magit-clone + (cond ((string-match-p "^[^/]+$" url-or-repo) + (format +magit-default-clone-url (ghub--username (ghub--host)) url-or-repo)) + ((string-match-p "^\\([^/]+\\)/\\([^/]+\\)/?$" url-or-repo) + (apply #'format +magit-default-clone-url (split-string url-or-repo "/" t))) + (url-or-repo)) + dir)) ;; diff --git a/modules/tools/magit/config.el b/modules/tools/magit/config.el index 5550cf5d2..bccf6162d 100644 --- a/modules/tools/magit/config.el +++ b/modules/tools/magit/config.el @@ -1,5 +1,10 @@ ;;; tools/magit/config.el -*- lexical-binding: t; -*- +(defvar +magit-default-clone-url "https://github.com/%s/%s" + "The default location for `+magit/clone' to clone relative URLs from. +It is passed a user and repository name.") + + ;; ;; Packages