Skip to content

Commit

Permalink
support optional .git at end of git remote (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
leahneukirchen authored Jan 22, 2024
1 parent 6e0e772 commit 31326c1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
;; always force unix line endings to make hashing consistent
* text eol=lf
*.png binary
*.db binary
2 changes: 1 addition & 1 deletion src/nextjournal/clerk/git.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#_(shell-out-str "zonk")

(defn ->github-project [remote-url]
(second (re-find #"^git@github\.com:(.*)(\.git)?$" remote-url)))
(second (re-find #"^git@github\.com:(.*?)(\.git)?$" remote-url)))

(defn ->https-git-url
"Takes a git `remote-url` and tries to convert it into a https url for
Expand Down
24 changes: 24 additions & 0 deletions test/nextjournal/clerk/git_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(ns nextjournal.clerk.git-test
(:require [clojure.test :refer [deftest is testing]]
[nextjournal.clerk.git :as git]))

(deftest ->github-project
(testing "works with .git suffix"
(is (= "nextjournal/clerk"
(git/->github-project "git@github.com:nextjournal/clerk.git"))))
(testing "works without .git suffix"
(is (= "nextjournal/clerk"
(git/->github-project "git@github.com:nextjournal/clerk"))))
(testing "works only for github"
(is (nil? (git/->github-project "git@gitlab.com:other/host.git")))))

(deftest ->https-git-url
(testing "works for https"
(is (= "https://github.com/nextjournal/clerk"
(git/->https-git-url "https://github.com/nextjournal/clerk.git")))
(is (= "https://gitlab.com/other/host"
(git/->https-git-url "https://gitlab.com/other/host.git"))))
(testing "rewrites github ssh to https"
(is (= "https://github.com/nextjournal/clerk"
(git/->https-git-url "git@github.com:nextjournal/clerk.git")))))

0 comments on commit 31326c1

Please sign in to comment.