Skip to content

Commit

Permalink
git: use remote-url of current branch instead of guessing (#566)
Browse files Browse the repository at this point in the history
Previously, the first remote that followed a github-style URL schema
was used; now we use the actual remote of the branch.
  • Loading branch information
leahneukirchen authored Oct 25, 2023
1 parent 424bf35 commit 78d2ffa
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/nextjournal/clerk/git.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

(defn ^:private shell-out-str
"Shell helper, calls a cmd and returns it output string trimmed."
[cmd]
(str/trim (:out (p/shell {:out :string} cmd))))
[& cmd]
(str/trim (:out (apply p/shell {:out :string} cmd))))

#_(shell-out-str "git rev-parse HEAD")
#_(shell-out-str "zonk")
Expand All @@ -24,17 +24,19 @@
(str/replace remote-url #"\.git$" "")

(->github-project remote-url)
(str "https://github.com/%s" (->github-project remote-url))))
(str "https://github.com/" (->github-project remote-url))))

#_(->https-git-url "https://github.com/nextjournal/clerk.git")
#_(->https-git-url "[email protected]:nextjournal/clerk.git")

(defn read-git-attrs []
(try {:git/sha (shell-out-str "git rev-parse HEAD")
:git/url (some ->https-git-url
(map #(shell-out-str (str "git remote get-url " %))
(str/split-lines (shell-out-str "git remote"))))}
(catch Exception _
:git/url (let [branch (shell-out-str "git symbolic-ref --short HEAD")
remote (shell-out-str "git" "config" (str "branch." branch ".remote"))
remote-url (shell-out-str "git" "remote" "get-url" remote)]
(->https-git-url remote-url))}
(catch Exception e
(prn e)
{})))

#_(read-git-attrs)

0 comments on commit 78d2ffa

Please sign in to comment.