From 8a4f3c30f6be5d8498ee15e2465a44e210b57cd7 Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Fri, 2 Aug 2024 19:23:08 +0200 Subject: [PATCH 01/11] Fail to reproduce issue 235 --- test/babashka/neil/dep_upgrade_test.clj | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/babashka/neil/dep_upgrade_test.clj b/test/babashka/neil/dep_upgrade_test.clj index 823f531..62f47c6 100644 --- a/test/babashka/neil/dep_upgrade_test.clj +++ b/test/babashka/neil/dep_upgrade_test.clj @@ -277,3 +277,50 @@ (is (neil/dep->upgrade {:lib 'com.wsscode/pathom3 :current {:mvn/version "2023.01.31-alpha"} :unstable true}))) + +(deftest neil-dep-upgrade-keep-git-url-constant + ;; https://github.com/babashka/neil/issues/235 + + ;; For step 1, I just want to reproduce the current behavior, and produce an error with expected behavior to make sure I understand the problem. + + ;; Problematic EDN files: + '{:deps {babashka/pods + {:git/url "https://github.com/babashka/babashka.pods" + :git/sha "47e55fe5e728578ff4dbf7d2a2caf00efea87b1e"}}} + '{:deps {cognitect/test-runner + {:git/url "https://github.com/cognitect-labs/test-runner" + :git/sha "9d36f36ff541dac680a05010e4348c744333f191"}}} + + + + (testing "Currently, neil-dep-upgrade changes the url of certain git deps" + ;; this appears to be the case where the repository has been renamed to something else. + (is (neil/dep->upgrade {:lib 'com.wsscode/pathom3 + :current {:mvn/version "2023.01.31-alpha"} + :unstable true})) + (spit test-file-path "{:deps {clj-kondo/clj-kondo + {:git/url \"https://github.com/clj-kondo/clj-kondo\" + :sha \"6ffc3934cb83d2c4fff16d84198c73b40cd8a078\"}}}") + (let [original (get-dep-version 'clj-kondo/clj-kondo)] + (test-util/neil "dep upgrade" :deps-file test-file-path) + (let [upgraded (get-dep-version 'clj-kondo/clj-kondo)] + ;; TODO + )) + ) + ) + +(comment + (set! *print-namespace-maps* false) + + (do (spit test-file-path (pr-str '{:deps {babashka/pods {:git/url "https://github.com/babashka/babashka.pods" :git/sha "47e55fe5e728578ff4dbf7d2a2caf00efea87b1e"}}})) + (test-util/neil "dep upgrade" :deps-file test-file-path) + (get-dep-version 'babashka/pods)) + ;; evaluates to + {:git/url "https://github.com/babashka/babashka.pods", :git/sha "47e55fe5e728578ff4dbf7d2a2caf00efea87b1e"} + + ;; which is NOT what I expect. + ;; I expected the URL to be changed to github.com/babashka/pods. + ;; This is weird. + ;; + ;; Next step: try tro reproduce on the command line. + ) From 74ff122250adf9b4091b89730001b4d6f9570819 Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Fri, 2 Aug 2024 19:38:47 +0200 Subject: [PATCH 02/11] comment-out half-done deftest with lint errors --- test/babashka/neil/dep_upgrade_test.clj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/babashka/neil/dep_upgrade_test.clj b/test/babashka/neil/dep_upgrade_test.clj index 62f47c6..8ffe35c 100644 --- a/test/babashka/neil/dep_upgrade_test.clj +++ b/test/babashka/neil/dep_upgrade_test.clj @@ -278,6 +278,7 @@ :current {:mvn/version "2023.01.31-alpha"} :unstable true}))) +#_ (deftest neil-dep-upgrade-keep-git-url-constant ;; https://github.com/babashka/neil/issues/235 @@ -291,8 +292,6 @@ {:git/url "https://github.com/cognitect-labs/test-runner" :git/sha "9d36f36ff541dac680a05010e4348c744333f191"}}} - - (testing "Currently, neil-dep-upgrade changes the url of certain git deps" ;; this appears to be the case where the repository has been renamed to something else. (is (neil/dep->upgrade {:lib 'com.wsscode/pathom3 From cd257b7cf6cdb0d47f164c2127a31ad02a751283 Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Sun, 4 Aug 2024 17:51:21 +0200 Subject: [PATCH 03/11] Reproduce it right this time --- test/babashka/neil/dep_upgrade_test.clj | 75 +++++++++++-------------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/test/babashka/neil/dep_upgrade_test.clj b/test/babashka/neil/dep_upgrade_test.clj index 8ffe35c..c0907ac 100644 --- a/test/babashka/neil/dep_upgrade_test.clj +++ b/test/babashka/neil/dep_upgrade_test.clj @@ -278,48 +278,41 @@ :current {:mvn/version "2023.01.31-alpha"} :unstable true}))) -#_ -(deftest neil-dep-upgrade-keep-git-url-constant - ;; https://github.com/babashka/neil/issues/235 - - ;; For step 1, I just want to reproduce the current behavior, and produce an error with expected behavior to make sure I understand the problem. - - ;; Problematic EDN files: - '{:deps {babashka/pods - {:git/url "https://github.com/babashka/babashka.pods" - :git/sha "47e55fe5e728578ff4dbf7d2a2caf00efea87b1e"}}} - '{:deps {cognitect/test-runner - {:git/url "https://github.com/cognitect-labs/test-runner" - :git/sha "9d36f36ff541dac680a05010e4348c744333f191"}}} - - (testing "Currently, neil-dep-upgrade changes the url of certain git deps" - ;; this appears to be the case where the repository has been renamed to something else. - (is (neil/dep->upgrade {:lib 'com.wsscode/pathom3 - :current {:mvn/version "2023.01.31-alpha"} - :unstable true})) - (spit test-file-path "{:deps {clj-kondo/clj-kondo - {:git/url \"https://github.com/clj-kondo/clj-kondo\" - :sha \"6ffc3934cb83d2c4fff16d84198c73b40cd8a078\"}}}") - (let [original (get-dep-version 'clj-kondo/clj-kondo)] - (test-util/neil "dep upgrade" :deps-file test-file-path) - (let [upgraded (get-dep-version 'clj-kondo/clj-kondo)] - ;; TODO - )) - ) - ) +(deftest neil-dep-upgrade-canonicalizes-git-urls + ;; This is the current, unwanted behavior. + ;; I expect to delete this test before the PR is merged. + (let [original-deps '{:deps {babashka/pods {:git/url "https://github.com/babashka/babashka.pods" + :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"}}} + canonicalized-url "https://github.com/babashka/pods"] + (spit test-file-path original-deps) + (test-util/neil "dep upgrade" :test-file-path test-file-path) + (is (= canonicalized-url + (:git/url (get-dep-version 'babashka/pods)))))) + +(deftest neil-dep-upgrade-does-not-touch-git-urls + ;; This is the desired behavior. + (let [original-git-url "https://github.com/babashka/babashka.pods" + original-deps {:deps {'babashka/pods {:git/url original-git-url + :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"}}}] + (spit test-file-path original-deps) + (test-util/neil "dep upgrade" :test-file-path test-file-path) + (is (= original-git-url + (:git/url (get-dep-version 'babashka/pods)))))) (comment (set! *print-namespace-maps* false) - (do (spit test-file-path (pr-str '{:deps {babashka/pods {:git/url "https://github.com/babashka/babashka.pods" :git/sha "47e55fe5e728578ff4dbf7d2a2caf00efea87b1e"}}})) - (test-util/neil "dep upgrade" :deps-file test-file-path) - (get-dep-version 'babashka/pods)) - ;; evaluates to - {:git/url "https://github.com/babashka/babashka.pods", :git/sha "47e55fe5e728578ff4dbf7d2a2caf00efea87b1e"} - - ;; which is NOT what I expect. - ;; I expected the URL to be changed to github.com/babashka/pods. - ;; This is weird. - ;; - ;; Next step: try tro reproduce on the command line. - ) + ;; We try again. + (spit test-file-path '{:deps {babashka/pods {:git/url "https://github.com/babashka/babashka.pods" + :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"}}}) + (get-dep-version 'babashka/pods) + ;; => {:git/url "https://github.com/babashka/babashka.pods", + ;; :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"} + + (test-util/neil "dep upgrade" :deps-file test-file-path) + + (get-dep-version 'babashka/pods) + ;; => {:git/url "https://github.com/babashka/pods", + ;; :git/sha "47e55fe5e728578ff4dbf7d2a2caf00efea87b1e"} + + :rcf) From e36b4f39aec57ef93b2d29d2a648bc2cbcfd8293 Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Sun, 4 Aug 2024 18:10:29 +0200 Subject: [PATCH 04/11] Don't change :git/url when updating deps --- src/babashka/neil.clj | 3 ++- test/babashka/neil/dep_upgrade_test.clj | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index d58c02d..df87abd 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -378,6 +378,7 @@ chmod +x bin/kaocha (apply prn xs))) (defn dep-add [{:keys [opts]}] + (tap> opts) (if (or (:help opts) (:h opts) (not (:lib opts))) (print-dep-add-help) (do @@ -726,7 +727,7 @@ details on the search syntax."))) version (assoc :version version) tag (assoc :tag tag) (and (not tag) sha) (assoc :sha sha) - (not (:git/url current)) (assoc :omit-git-url true))})))))) + true (assoc :omit-git-url true))})))))) (defn dep-upgrade [{:keys [opts]}] (when (or (:h opts) (:help opts)) diff --git a/test/babashka/neil/dep_upgrade_test.clj b/test/babashka/neil/dep_upgrade_test.clj index c0907ac..33a29fb 100644 --- a/test/babashka/neil/dep_upgrade_test.clj +++ b/test/babashka/neil/dep_upgrade_test.clj @@ -299,6 +299,17 @@ (is (= original-git-url (:git/url (get-dep-version 'babashka/pods)))))) +(comment + (defonce taps (atom [])) + (add-tap (partial swap! taps conj)) + (tap> "hello") + + (neil-dep-upgrade-canonicalizes-git-urls) + (last @taps) + + + :rcf) + (comment (set! *print-namespace-maps* false) From a144637faf176e3844bce99a00d099174c87072c Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Sun, 4 Aug 2024 18:11:51 +0200 Subject: [PATCH 05/11] Delete exploratory code --- test/babashka/neil/dep_upgrade_test.clj | 41 ------------------------- 1 file changed, 41 deletions(-) diff --git a/test/babashka/neil/dep_upgrade_test.clj b/test/babashka/neil/dep_upgrade_test.clj index 33a29fb..692dfad 100644 --- a/test/babashka/neil/dep_upgrade_test.clj +++ b/test/babashka/neil/dep_upgrade_test.clj @@ -278,19 +278,7 @@ :current {:mvn/version "2023.01.31-alpha"} :unstable true}))) -(deftest neil-dep-upgrade-canonicalizes-git-urls - ;; This is the current, unwanted behavior. - ;; I expect to delete this test before the PR is merged. - (let [original-deps '{:deps {babashka/pods {:git/url "https://github.com/babashka/babashka.pods" - :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"}}} - canonicalized-url "https://github.com/babashka/pods"] - (spit test-file-path original-deps) - (test-util/neil "dep upgrade" :test-file-path test-file-path) - (is (= canonicalized-url - (:git/url (get-dep-version 'babashka/pods)))))) - (deftest neil-dep-upgrade-does-not-touch-git-urls - ;; This is the desired behavior. (let [original-git-url "https://github.com/babashka/babashka.pods" original-deps {:deps {'babashka/pods {:git/url original-git-url :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"}}}] @@ -298,32 +286,3 @@ (test-util/neil "dep upgrade" :test-file-path test-file-path) (is (= original-git-url (:git/url (get-dep-version 'babashka/pods)))))) - -(comment - (defonce taps (atom [])) - (add-tap (partial swap! taps conj)) - (tap> "hello") - - (neil-dep-upgrade-canonicalizes-git-urls) - (last @taps) - - - :rcf) - -(comment - (set! *print-namespace-maps* false) - - ;; We try again. - (spit test-file-path '{:deps {babashka/pods {:git/url "https://github.com/babashka/babashka.pods" - :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"}}}) - (get-dep-version 'babashka/pods) - ;; => {:git/url "https://github.com/babashka/babashka.pods", - ;; :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"} - - (test-util/neil "dep upgrade" :deps-file test-file-path) - - (get-dep-version 'babashka/pods) - ;; => {:git/url "https://github.com/babashka/pods", - ;; :git/sha "47e55fe5e728578ff4dbf7d2a2caf00efea87b1e"} - - :rcf) From a208065047e63134a6a9612659b22e9b101aa845 Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Sun, 4 Aug 2024 18:12:11 +0200 Subject: [PATCH 06/11] Delete exploratory code --- src/babashka/neil.clj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index df87abd..7888c00 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -378,7 +378,6 @@ chmod +x bin/kaocha (apply prn xs))) (defn dep-add [{:keys [opts]}] - (tap> opts) (if (or (:help opts) (:h opts) (not (:lib opts))) (print-dep-add-help) (do From d2cef9a7f06ea785b788c1568ce01f31ef10004d Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Sun, 4 Aug 2024 18:13:32 +0200 Subject: [PATCH 07/11] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5035a23..85c8d0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ See the [New Clojure project quickstart](https://blog.michielborkent.nl/new-cloj - [#230](https://github.com/babashka/neil/issues/230): neil dep upgrade inserts git/url into upgraded dep ([@teodorlu](https://github.com/teodorlu)) - [#237](https://github.com/babashka/neil/issues/230): more specific error reporting on invalid github token ([@teodorlu](https://github.com/teodorlu)) +- [#235](https://github.com/babashka/neil/issues/230): neil dep upgrade changes git url ([@teodorlu](https://github.com/teodorlu)) ## 0.3.66 From 2bbb4512d64a9a1cf45579e5d0c0aa839002e993 Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Sun, 4 Aug 2024 18:16:02 +0200 Subject: [PATCH 08/11] neil-dep-upgrade-does-not-change-git-urls --- test/babashka/neil/dep_upgrade_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/babashka/neil/dep_upgrade_test.clj b/test/babashka/neil/dep_upgrade_test.clj index 692dfad..5ec0704 100644 --- a/test/babashka/neil/dep_upgrade_test.clj +++ b/test/babashka/neil/dep_upgrade_test.clj @@ -278,7 +278,7 @@ :current {:mvn/version "2023.01.31-alpha"} :unstable true}))) -(deftest neil-dep-upgrade-does-not-touch-git-urls +(deftest neil-dep-upgrade-does-not-change-git-urls (let [original-git-url "https://github.com/babashka/babashka.pods" original-deps {:deps {'babashka/pods {:git/url original-git-url :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"}}}] From b31fda188ee2a879b73b7ac70ddd92213756407b Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Sun, 4 Aug 2024 18:16:47 +0200 Subject: [PATCH 09/11] Add test description --- test/babashka/neil/dep_upgrade_test.clj | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/babashka/neil/dep_upgrade_test.clj b/test/babashka/neil/dep_upgrade_test.clj index 5ec0704..d7cc374 100644 --- a/test/babashka/neil/dep_upgrade_test.clj +++ b/test/babashka/neil/dep_upgrade_test.clj @@ -279,10 +279,11 @@ :unstable true}))) (deftest neil-dep-upgrade-does-not-change-git-urls - (let [original-git-url "https://github.com/babashka/babashka.pods" - original-deps {:deps {'babashka/pods {:git/url original-git-url - :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"}}}] - (spit test-file-path original-deps) - (test-util/neil "dep upgrade" :test-file-path test-file-path) - (is (= original-git-url - (:git/url (get-dep-version 'babashka/pods)))))) + (testing "When we upgrade a dep with :git/url, we don't want that git url shall not change." + (let [original-git-url "https://github.com/babashka/babashka.pods" + original-deps {:deps {'babashka/pods {:git/url original-git-url + :git/sha "6ad6045b94bc871c5107bfc75d39643b6c1bc8ba"}}}] + (spit test-file-path original-deps) + (test-util/neil "dep upgrade" :test-file-path test-file-path) + (is (= original-git-url + (:git/url (get-dep-version 'babashka/pods))))))) From 08812baa569ab5761bb9bc6f4d2e8f2f3847925c Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Sun, 4 Aug 2024 19:13:44 +0200 Subject: [PATCH 10/11] Add logging to find out where things crash --- src/babashka/neil.clj | 206 ++++++++++++++++++++++-------------------- 1 file changed, 107 insertions(+), 99 deletions(-) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 7888c00..2cb10e3 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -378,105 +378,113 @@ chmod +x bin/kaocha (apply prn xs))) (defn dep-add [{:keys [opts]}] - (if (or (:help opts) (:h opts) (not (:lib opts))) - (print-dep-add-help) - (do - (ensure-deps-file opts) - (let [edn-string (edn-string opts) - edn-nodes (edn-nodes edn-string) - lib (:lib opts) - lib (symbol lib) - lib (symbol (or (namespace lib) (name lib)) - (name lib)) - alias (:alias opts) - explicit-git-sha? (or (:sha opts) (:latest-sha opts)) - explicit-git-tag? (or (:tag opts) (:latest-tag opts)) - [version coord-type?] - (cond explicit-git-tag? - [(or (and (:tag opts) - (git/find-github-tag lib (:tag opts))) - (git/latest-github-tag lib)) :git/tag] - explicit-git-sha? - [(or (:sha opts) (git/latest-github-sha lib)) :git/sha] - :else - (or - (when-let [v (:version opts)] - [v :mvn]) - (when-let [v (latest-stable-clojars-version lib)] - [v :mvn]) - (when-let [v (latest-stable-mvn-version lib)] - [v :mvn]) - (when-let [v (git/latest-github-sha lib)] - [v :git/sha]) - (when-let [v (latest-clojars-version lib)] - [v :mvn]) - (when-let [v (latest-mvn-version lib)] - [v :mvn]))) - _ (when-not version - (throw (ex-info (str "Couldn't find version for lib: " lib) {:babashka/exit 1}))) - missing? (nil? version) - mvn? (= :mvn coord-type?) - git-sha? (= :git/sha coord-type?) - git-tag? (= :git/tag coord-type?) - git-url (when (or git-sha? git-tag?) - (or (:git/url opts) - (str "https://github.com/" (git/clean-github-lib lib)))) - as (or (:as opts) lib) - existing-aliases (-> edn-string edn/read-string :aliases) - path (if alias - [:aliases - alias - (if (get-in existing-aliases [alias :deps]) :deps :extra-deps) - as] - [:deps as]) - nl-path (if (and alias - (not (contains? existing-aliases alias))) - [:aliases alias] - path) - edn-nodes (if (r/get-in edn-nodes nl-path) - ;; if this dep already exists, don't touch it. - ;; We risk loosing :exclusions and other properties. - edn-nodes - ;; otherwise, force newlines! - ;; force newline in - ;; - ;; [:deps as] if no alias - ;; [:aliases alias] if alias DNE - ;; [:aliases alias :deps as] if :deps present - ;; [:aliases alias :extra-deps as] if alias exists - (-> edn-nodes (r/assoc-in nl-path nil) str r/parse-string)) - nodes (cond - missing? edn-nodes - mvn? - (r/assoc-in edn-nodes (conj path :mvn/version) version) - git-sha? - ;; multiple steps to force newlines - (cond-> edn-nodes - (not (:omit-git-url opts)) (r/assoc-in (conj path :git/url) - git-url) - true str - true r/parse-string - true (r/assoc-in (conj path :git/sha) version) - true (r/update-in path r/dissoc :sha)) - - git-tag? - ;; multiple steps to force newlines - (-> edn-nodes - (r/assoc-in (conj path :git/url) git-url) - str - r/parse-string - (r/assoc-in (conj path :git/tag) (-> version :name)) - str - r/parse-string - (r/assoc-in (conj path :git/sha) - (some-> version :commit :sha (subs 0 7))))) - nodes (if-let [root (and (or git-sha? git-tag?) (:deps/root opts))] - (-> nodes - (r/assoc-in (conj path :deps/root) root)) - nodes) - s (str (str/trim (str nodes)) "\n")] - (when-not missing? - (spit (:deps-file opts) s)))))) + (let [trace-id (rand) + log (fn [marker] + (babashka.neil/log + (assoc {:trace-id trace-id + :marker marker})))] + (log ::marker-1) + (if (or (:help opts) (:h opts) (not (:lib opts))) + (print-dep-add-help) + (do + (ensure-deps-file opts) + (let [edn-string (edn-string opts) + edn-nodes (edn-nodes edn-string) + lib (:lib opts) + lib (symbol lib) + lib (symbol (or (namespace lib) (name lib)) + (name lib)) + alias (:alias opts) + explicit-git-sha? (or (:sha opts) (:latest-sha opts)) + explicit-git-tag? (or (:tag opts) (:latest-tag opts)) + [version coord-type?] + (cond explicit-git-tag? + [(or (and (:tag opts) + (git/find-github-tag lib (:tag opts))) + (git/latest-github-tag lib)) :git/tag] + explicit-git-sha? + [(or (:sha opts) (git/latest-github-sha lib)) :git/sha] + :else + (or + (when-let [v (:version opts)] + [v :mvn]) + (when-let [v (latest-stable-clojars-version lib)] + [v :mvn]) + (when-let [v (latest-stable-mvn-version lib)] + [v :mvn]) + (when-let [v (git/latest-github-sha lib)] + [v :git/sha]) + (when-let [v (latest-clojars-version lib)] + [v :mvn]) + (when-let [v (latest-mvn-version lib)] + [v :mvn]))) + _ (when-not version + (throw (ex-info (str "Couldn't find version for lib: " lib) {:babashka/exit 1}))) + missing? (nil? version) + mvn? (= :mvn coord-type?) + git-sha? (= :git/sha coord-type?) + git-tag? (= :git/tag coord-type?) + git-url (when (or git-sha? git-tag?) + (or (:git/url opts) + (str "https://github.com/" (git/clean-github-lib lib)))) + as (or (:as opts) lib) + existing-aliases (-> edn-string edn/read-string :aliases) + path (if alias + [:aliases + alias + (if (get-in existing-aliases [alias :deps]) :deps :extra-deps) + as] + [:deps as]) + nl-path (if (and alias + (not (contains? existing-aliases alias))) + [:aliases alias] + path) + edn-nodes (if (r/get-in edn-nodes nl-path) + ;; if this dep already exists, don't touch it. + ;; We risk loosing :exclusions and other properties. + edn-nodes + ;; otherwise, force newlines! + ;; force newline in + ;; + ;; [:deps as] if no alias + ;; [:aliases alias] if alias DNE + ;; [:aliases alias :deps as] if :deps present + ;; [:aliases alias :extra-deps as] if alias exists + (-> edn-nodes (r/assoc-in nl-path nil) str r/parse-string)) + _ (log ::marker-2) + nodes (cond + missing? edn-nodes + mvn? + (r/assoc-in edn-nodes (conj path :mvn/version) version) + git-sha? + ;; multiple steps to force newlines + (cond-> edn-nodes + (not (:omit-git-url opts)) (r/assoc-in (conj path :git/url) + git-url) + true str + true r/parse-string + true (r/assoc-in (conj path :git/sha) version) + true (r/update-in path r/dissoc :sha)) + + git-tag? + ;; multiple steps to force newlines + (-> edn-nodes + (r/assoc-in (conj path :git/url) git-url) + str + r/parse-string + (r/assoc-in (conj path :git/tag) (-> version :name)) + str + r/parse-string + (r/assoc-in (conj path :git/sha) + (some-> version :commit :sha (subs 0 7))))) + _ (log ::marker-3) + nodes (if-let [root (and (or git-sha? git-tag?) (:deps/root opts))] + (-> nodes + (r/assoc-in (conj path :deps/root) root)) + nodes) + s (str (str/trim (str nodes)) "\n")] + (when-not missing? + (spit (:deps-file opts) s))))))) (defn dep-versions [{:keys [opts]}] (when (or (:help opts) (:h opts)) From 0e475a734dcb9ac047e44dabea151ed1707f8171 Mon Sep 17 00:00:00 2001 From: Teodor Heggelund Date: Sun, 4 Aug 2024 19:24:18 +0200 Subject: [PATCH 11/11] Revert unrelated error --- src/babashka/neil.clj | 206 ++++++++++++++++++++---------------------- 1 file changed, 99 insertions(+), 107 deletions(-) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 2cb10e3..7888c00 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -378,113 +378,105 @@ chmod +x bin/kaocha (apply prn xs))) (defn dep-add [{:keys [opts]}] - (let [trace-id (rand) - log (fn [marker] - (babashka.neil/log - (assoc {:trace-id trace-id - :marker marker})))] - (log ::marker-1) - (if (or (:help opts) (:h opts) (not (:lib opts))) - (print-dep-add-help) - (do - (ensure-deps-file opts) - (let [edn-string (edn-string opts) - edn-nodes (edn-nodes edn-string) - lib (:lib opts) - lib (symbol lib) - lib (symbol (or (namespace lib) (name lib)) - (name lib)) - alias (:alias opts) - explicit-git-sha? (or (:sha opts) (:latest-sha opts)) - explicit-git-tag? (or (:tag opts) (:latest-tag opts)) - [version coord-type?] - (cond explicit-git-tag? - [(or (and (:tag opts) - (git/find-github-tag lib (:tag opts))) - (git/latest-github-tag lib)) :git/tag] - explicit-git-sha? - [(or (:sha opts) (git/latest-github-sha lib)) :git/sha] - :else - (or - (when-let [v (:version opts)] - [v :mvn]) - (when-let [v (latest-stable-clojars-version lib)] - [v :mvn]) - (when-let [v (latest-stable-mvn-version lib)] - [v :mvn]) - (when-let [v (git/latest-github-sha lib)] - [v :git/sha]) - (when-let [v (latest-clojars-version lib)] - [v :mvn]) - (when-let [v (latest-mvn-version lib)] - [v :mvn]))) - _ (when-not version - (throw (ex-info (str "Couldn't find version for lib: " lib) {:babashka/exit 1}))) - missing? (nil? version) - mvn? (= :mvn coord-type?) - git-sha? (= :git/sha coord-type?) - git-tag? (= :git/tag coord-type?) - git-url (when (or git-sha? git-tag?) - (or (:git/url opts) - (str "https://github.com/" (git/clean-github-lib lib)))) - as (or (:as opts) lib) - existing-aliases (-> edn-string edn/read-string :aliases) - path (if alias - [:aliases - alias - (if (get-in existing-aliases [alias :deps]) :deps :extra-deps) - as] - [:deps as]) - nl-path (if (and alias - (not (contains? existing-aliases alias))) - [:aliases alias] - path) - edn-nodes (if (r/get-in edn-nodes nl-path) - ;; if this dep already exists, don't touch it. - ;; We risk loosing :exclusions and other properties. - edn-nodes - ;; otherwise, force newlines! - ;; force newline in - ;; - ;; [:deps as] if no alias - ;; [:aliases alias] if alias DNE - ;; [:aliases alias :deps as] if :deps present - ;; [:aliases alias :extra-deps as] if alias exists - (-> edn-nodes (r/assoc-in nl-path nil) str r/parse-string)) - _ (log ::marker-2) - nodes (cond - missing? edn-nodes - mvn? - (r/assoc-in edn-nodes (conj path :mvn/version) version) - git-sha? - ;; multiple steps to force newlines - (cond-> edn-nodes - (not (:omit-git-url opts)) (r/assoc-in (conj path :git/url) - git-url) - true str - true r/parse-string - true (r/assoc-in (conj path :git/sha) version) - true (r/update-in path r/dissoc :sha)) - - git-tag? - ;; multiple steps to force newlines - (-> edn-nodes - (r/assoc-in (conj path :git/url) git-url) - str - r/parse-string - (r/assoc-in (conj path :git/tag) (-> version :name)) - str - r/parse-string - (r/assoc-in (conj path :git/sha) - (some-> version :commit :sha (subs 0 7))))) - _ (log ::marker-3) - nodes (if-let [root (and (or git-sha? git-tag?) (:deps/root opts))] - (-> nodes - (r/assoc-in (conj path :deps/root) root)) - nodes) - s (str (str/trim (str nodes)) "\n")] - (when-not missing? - (spit (:deps-file opts) s))))))) + (if (or (:help opts) (:h opts) (not (:lib opts))) + (print-dep-add-help) + (do + (ensure-deps-file opts) + (let [edn-string (edn-string opts) + edn-nodes (edn-nodes edn-string) + lib (:lib opts) + lib (symbol lib) + lib (symbol (or (namespace lib) (name lib)) + (name lib)) + alias (:alias opts) + explicit-git-sha? (or (:sha opts) (:latest-sha opts)) + explicit-git-tag? (or (:tag opts) (:latest-tag opts)) + [version coord-type?] + (cond explicit-git-tag? + [(or (and (:tag opts) + (git/find-github-tag lib (:tag opts))) + (git/latest-github-tag lib)) :git/tag] + explicit-git-sha? + [(or (:sha opts) (git/latest-github-sha lib)) :git/sha] + :else + (or + (when-let [v (:version opts)] + [v :mvn]) + (when-let [v (latest-stable-clojars-version lib)] + [v :mvn]) + (when-let [v (latest-stable-mvn-version lib)] + [v :mvn]) + (when-let [v (git/latest-github-sha lib)] + [v :git/sha]) + (when-let [v (latest-clojars-version lib)] + [v :mvn]) + (when-let [v (latest-mvn-version lib)] + [v :mvn]))) + _ (when-not version + (throw (ex-info (str "Couldn't find version for lib: " lib) {:babashka/exit 1}))) + missing? (nil? version) + mvn? (= :mvn coord-type?) + git-sha? (= :git/sha coord-type?) + git-tag? (= :git/tag coord-type?) + git-url (when (or git-sha? git-tag?) + (or (:git/url opts) + (str "https://github.com/" (git/clean-github-lib lib)))) + as (or (:as opts) lib) + existing-aliases (-> edn-string edn/read-string :aliases) + path (if alias + [:aliases + alias + (if (get-in existing-aliases [alias :deps]) :deps :extra-deps) + as] + [:deps as]) + nl-path (if (and alias + (not (contains? existing-aliases alias))) + [:aliases alias] + path) + edn-nodes (if (r/get-in edn-nodes nl-path) + ;; if this dep already exists, don't touch it. + ;; We risk loosing :exclusions and other properties. + edn-nodes + ;; otherwise, force newlines! + ;; force newline in + ;; + ;; [:deps as] if no alias + ;; [:aliases alias] if alias DNE + ;; [:aliases alias :deps as] if :deps present + ;; [:aliases alias :extra-deps as] if alias exists + (-> edn-nodes (r/assoc-in nl-path nil) str r/parse-string)) + nodes (cond + missing? edn-nodes + mvn? + (r/assoc-in edn-nodes (conj path :mvn/version) version) + git-sha? + ;; multiple steps to force newlines + (cond-> edn-nodes + (not (:omit-git-url opts)) (r/assoc-in (conj path :git/url) + git-url) + true str + true r/parse-string + true (r/assoc-in (conj path :git/sha) version) + true (r/update-in path r/dissoc :sha)) + + git-tag? + ;; multiple steps to force newlines + (-> edn-nodes + (r/assoc-in (conj path :git/url) git-url) + str + r/parse-string + (r/assoc-in (conj path :git/tag) (-> version :name)) + str + r/parse-string + (r/assoc-in (conj path :git/sha) + (some-> version :commit :sha (subs 0 7))))) + nodes (if-let [root (and (or git-sha? git-tag?) (:deps/root opts))] + (-> nodes + (r/assoc-in (conj path :deps/root) root)) + nodes) + s (str (str/trim (str nodes)) "\n")] + (when-not missing? + (spit (:deps-file opts) s)))))) (defn dep-versions [{:keys [opts]}] (when (or (:help opts) (:h opts))