branch: elpa/git-commit commit a12018e9f84bb9cef2fca7862d64b7376bbcda19 Author: Nacho Barrientos <nacho.barrien...@cern.ch> Commit: Jonas Bernoulli <jo...@bernoul.li>
Enable cloning repositories in Sourcehut by name This patch adds a new item to the default value of `magit-clone-name-alist' so Magit knows about Sourcehut. The default value of `magit-clone-url-format' has to be also changed to accommodate the URL scheme used by Sourcehut which differs from the ones provided by Github and Gitlab. --- lisp/magit-clone.el | 7 +++++-- test/magit-tests.el | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lisp/magit-clone.el b/lisp/magit-clone.el index 26e616579b..23abff7afe 100644 --- a/lisp/magit-clone.el +++ b/lisp/magit-clone.el @@ -69,7 +69,8 @@ directly." (defcustom magit-clone-name-alist '(("\\`\\(?:github:\\|gh:\\)?\\([^:]+\\)\\'" "github.com" "github.user") - ("\\`\\(?:gitlab:\\|gl:\\)\\([^:]+\\)\\'" "gitlab.com" "gitlab.user")) + ("\\`\\(?:gitlab:\\|gl:\\)\\([^:]+\\)\\'" "gitlab.com" "gitlab.user") + ("\\`\\(?:sourcehut:\\|sh:\\)\\([^:]+\\)\\'" "git.sr.ht" "sourcehut.user")) "Alist mapping repository names to repository urls. Each element has the form (REGEXP HOSTNAME USER). When the user @@ -92,7 +93,9 @@ as the username itself." (string :tag "Hostname") (string :tag "User name or git variable")))) -(defcustom magit-clone-url-format "git@%h:%n.git" +(defcustom magit-clone-url-format + '(("git.sr.ht" . "git@%h:~%n") + (t . "git@%h:%n.git")) "Format(s) used when turning repository names into urls. In a format string, %h is the hostname and %n is the repository diff --git a/test/magit-tests.el b/test/magit-tests.el index da99d1df6f..82630365e8 100644 --- a/test/magit-tests.el +++ b/test/magit-tests.el @@ -305,6 +305,38 @@ Enter passphrase for key '/home/user/.ssh/id_rsa': " ;;; Clone +(ert-deftest magit-clone:--name-to-url-format-defaults () + (magit-with-test-repository + (magit-git "config" "--add" "sourcehut.user" "shuser") + (magit-git "config" "--add" "github.user" "ghuser") + (magit-git "config" "--add" "gitlab.user" "gluser") + ;; No explicit service + (should (string-equal (magit-clone--name-to-url "a/b") + "g...@github.com:a/b.git")) + (should (string-equal (magit-clone--name-to-url "b") + "g...@github.com:ghuser/b.git")) + ;; User in config + (should (string-equal (magit-clone--name-to-url "gh:b") + "g...@github.com:ghuser/b.git")) + (should (string-equal (magit-clone--name-to-url "gl:n") + "g...@gitlab.com:gluser/n.git")) + (should (string-equal (magit-clone--name-to-url "sh:l") + "g...@git.sr.ht:~shuser/l")) + ;; Explicit user (abbreviated service names) + (should (string-equal (magit-clone--name-to-url "gh:a/b") + "g...@github.com:a/b.git")) + (should (string-equal (magit-clone--name-to-url "gl:t/s") + "g...@gitlab.com:t/s.git")) + (should (string-equal (magit-clone--name-to-url "sh:x/y") + "g...@git.sr.ht:~x/y")) + ;; Explicit user (long service names) + (should (string-equal (magit-clone--name-to-url "github:a1/b1") + "g...@github.com:a1/b1.git")) + (should (string-equal (magit-clone--name-to-url "gitlab:t1/s1") + "g...@gitlab.com:t1/s1.git")) + (should (string-equal (magit-clone--name-to-url "sourcehut:x1/y1") + "g...@git.sr.ht:~x1/y1")))) + (ert-deftest magit-clone:--name-to-url-format-single-string () (let ((magit-clone-url-format "bird@%h:%n.git") (magit-clone-name-alist