emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/git-commit a12018e9f8 3/3: Enable cloning repositories in


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit a12018e9f8 3/3: Enable cloning repositories in Sourcehut by name
Date: Wed, 31 Aug 2022 10:58:56 -0400 (EDT)

branch: elpa/git-commit
commit a12018e9f84bb9cef2fca7862d64b7376bbcda19
Author: Nacho Barrientos <nacho.barrientos@cern.ch>
Commit: Jonas Bernoulli <jonas@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")
+                         "git@github.com:a/b.git"))
+   (should (string-equal (magit-clone--name-to-url "b")
+                         "git@github.com:ghuser/b.git"))
+   ;; User in config
+   (should (string-equal (magit-clone--name-to-url "gh:b")
+                         "git@github.com:ghuser/b.git"))
+   (should (string-equal (magit-clone--name-to-url "gl:n")
+                         "git@gitlab.com:gluser/n.git"))
+   (should (string-equal (magit-clone--name-to-url "sh:l")
+                         "git@git.sr.ht:~shuser/l"))
+   ;; Explicit user (abbreviated service names)
+   (should (string-equal (magit-clone--name-to-url "gh:a/b")
+                         "git@github.com:a/b.git"))
+   (should (string-equal (magit-clone--name-to-url "gl:t/s")
+                         "git@gitlab.com:t/s.git"))
+   (should (string-equal (magit-clone--name-to-url "sh:x/y")
+                         "git@git.sr.ht:~x/y"))
+   ;; Explicit user (long service names)
+   (should (string-equal (magit-clone--name-to-url "github:a1/b1")
+                         "git@github.com:a1/b1.git"))
+   (should (string-equal (magit-clone--name-to-url "gitlab:t1/s1")
+                         "git@gitlab.com:t1/s1.git"))
+   (should (string-equal (magit-clone--name-to-url "sourcehut:x1/y1")
+                         "git@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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]