From 31326c1f2854e3f23f7cb15bb43cb3f561ad579e Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 22 Jan 2024 16:22:06 +0100 Subject: [PATCH] support optional .git at end of git remote (#621) --- .gitattributes | 1 + src/nextjournal/clerk/git.clj | 2 +- test/nextjournal/clerk/git_test.clj | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/nextjournal/clerk/git_test.clj diff --git a/.gitattributes b/.gitattributes index 8de406f72..2c30d7fd0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ ;; always force unix line endings to make hashing consistent * text eol=lf *.png binary +*.db binary diff --git a/src/nextjournal/clerk/git.clj b/src/nextjournal/clerk/git.clj index ba78d283e..89e504961 100644 --- a/src/nextjournal/clerk/git.clj +++ b/src/nextjournal/clerk/git.clj @@ -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 diff --git a/test/nextjournal/clerk/git_test.clj b/test/nextjournal/clerk/git_test.clj new file mode 100644 index 000000000..7664f204f --- /dev/null +++ b/test/nextjournal/clerk/git_test.clj @@ -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"))))) +