Skip to content

Commit

Permalink
Allow repo names with trailing slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Jan 14, 2016
1 parent 9607014 commit 1521bb6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 8 additions & 7 deletions github-clone.el
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@
(error "Unable to fork %s" (eieio-oref repo github-clone-url-slot)))))

(defun github-clone-repo-name (url)
(cond ((string-match "\\.git$" url)
(github-clone-repo-name (replace-match "" nil nil url)))
((string-match "\\([[:alnum:]\-_.]+\\)/\\([[:alnum:]\-_.]+\\)$" url)
(cons (match-string 1 url) (match-string 2 url)))
((string-match "^\\([[:alnum:]\-_.]+\\)$" url)
(cons (github-clone-user-name) (match-string 1 url)))
(t (error "Cannot parse repo name %s" url))))
(let ((url1 (replace-regexp-in-string "/$" "" url)))
(cond ((string-match "\\.git$" url1)
(github-clone-repo-name (replace-match "" nil nil url1)))
((string-match "\\([[:alnum:]\-_.]+\\)/\\([[:alnum:]\-_.]+\\)$" url1)
(cons (match-string 1 url) (match-string 2 url1)))
((string-match "^\\([[:alnum:]\-_.]+\\)$" url1)
(cons (github-clone-user-name) (match-string 1 url1)))
(t (error "Cannot parse repo name %s" url1)))))

(defvar github-clone--user nil "Cache for current github login.")
(defun github-clone-user-name ()
Expand Down
4 changes: 4 additions & 0 deletions test/github-clone-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
(should (equal (github-clone-repo-name "https://github.com/dgtized/github-clone.el")
(cons "dgtized" "github-clone.el"))))

(ert-deftest github-clone-repo-name-matches-url-trailing-slashes ()
(should (equal (github-clone-repo-name "https://github.com/dgtized/github-clone.el/")
(cons "dgtized" "github-clone.el"))))

(ert-deftest github-clone-repo-name-works-with-magit ()
(should (equal (github-clone-repo-name "https://github.com/magit/magit")
(cons "magit" "magit"))))
Expand Down

0 comments on commit 1521bb6

Please sign in to comment.