Skip to content

Commit 0844cdd

Browse files
committed
fix install-latest of new tool with mixed versions available
1 parent ac3b03f commit 0844cdd

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/clojure/tools/tools/api.clj

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@
7676
(let [current (tool/resolve-tool as)
7777
coord (or coord (:coord current))
7878
coord-type (ext/coord-type coord)
79-
latest-coord (->> (ext/find-all-versions lib coord master-edn)
80-
(filter release-version?)
81-
(filter #(= coord-type (ext/coord-type %)))
82-
last
83-
(merge coord))]
79+
release-coords (->> (ext/find-all-versions lib coord master-edn)
80+
(filter release-version?))
81+
;; try to match existing coord-type if there is one, else prefer git
82+
available-coords (if coord-type
83+
(filter #(= coord-type (ext/coord-type %)) release-coords)
84+
(let [git-coords (filter #(= :git (ext/coord-type %)) release-coords)]
85+
(if (seq git-coords) git-coords release-coords)))
86+
latest-coord (->> available-coords
87+
last
88+
(merge coord))]
8489
(if latest-coord
8590
(if (and current (= lib (:lib current)) (zero? (ext/compare-versions lib (:coord current) latest-coord master-edn)))
8691
(println (str as ":") "Skipping, newest installed" (ext/coord-summary lib latest-coord))
@@ -149,7 +154,7 @@
149154
(def master-edn
150155
(let [{:keys [root-edn user-edn]} (deps/find-edn-maps)]
151156
(deps/merge-edns [root-edn user-edn])))
152-
(install-1 'com.github.seancorfield/deps-new "deps-new" master-edn)
157+
(install-1 'com.github.seancorfield/deps-new nil "deps-new" master-edn)
153158
(ext/find-all-versions 'com.github.seancorfield/deps-new nil master-edn)
154159
(install-latest nil)
155160
(install {'com.github.seancorfield/deps-new {:git/tag "v0.4.9" :git/sha "ba30a76"} :as "deps-new"})

test-data/empty/.HOLD

Whitespace-only changes.

test/clojure/tools/tools/api_test.clj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[clojure.java.io :as jio]
55
[clojure.string :as str]
66
[clojure.test :refer :all]
7+
[clojure.tools.deps.extensions.git :as git]
78
[clojure.tools.tools.api :as api])
89
(:import
910
[java.io File]
@@ -79,14 +80,29 @@
7980
(finally
8081
(System/setProperty "user.home" old-home#)))))
8182

83+
(println "!! env paths" (System/getenv "CLJ_CONFIG") (System/getenv "XDG_CONFIG_HOME"))
84+
85+
;; when new tool has both git and maven versions, prefer git and install
86+
(deftest install-latest-new-mixed
87+
(let-tools-dir [tools "test-data/empty"]
88+
(api/install-latest {:lib 'com.github.seancorfield/clj-new
89+
:as 'clj-new})
90+
(let [new-edn (edn/read-string (slurp (jio/file tools "clj-new.edn")))]
91+
(clojure.pprint/pprint new-edn)
92+
;; has a :git/tag
93+
(is (= 'com.github.seancorfield/clj-new (-> new-edn :lib)))
94+
(is (= "https://github.com/seancorfield/clj-new.git" (-> new-edn :lib git/auto-git-url)))
95+
(is (-> new-edn :coord :git/tag))
96+
(is (-> new-edn :coord :git/sha)))))
97+
8298
;; when out of date tool has both git and maven versions, only consider updates
8399
;; to version with the same coordinate type. here, git is installed
84-
(deftest install-latest-mixed
100+
(deftest install-latest-existing-tool-mixed
85101
(let-tools-dir [tools "test-data/tools1"]
86102
(let [old-edn (edn/read-string (slurp (jio/file tools "clj-new.edn")))
87103
old-tag (-> old-edn :coord :git/tag)]
88104
(api/install-latest {:tool "clj-new"})
89105
(let [new-edn (edn/read-string (slurp (jio/file tools "clj-new.edn")))
90106
new-tag (-> new-edn :coord :git/tag)]
91107
(is new-tag) ;; has a :git/tag
92-
(is (not= old-tag new-tag)))))) ;; ... that has been updated
108+
(is (not= old-tag new-tag)))))) ;; ... that has been updated

0 commit comments

Comments
 (0)