Fork me on GitHub
#babashka
<
2022-05-20
>
craftybones05:05:05

What would be an ideal way to do some git wrangling with babashka? Is jgit available?

pavlosmelissinos05:05:54

I usually shell out (even from Clojure)

jumar05:05:04

Yep, we run it via clojure.java.shell and we use git very extensively (although we don't use babashka)

borkdude06:05:01

Shell out indeed

borkdude06:05:39

Even the Clojure CLI itself does this nowadays for pulling git deps

jumar08:05:45

I've been thinking about if it was useful to use a proper git library instead of shelling out to avoid overhead of sub-process execution but my guess is that when this matters, the command line git client is probably gonna be more performant than the library anyway.

borkdude08:05:38

the clojure CLI (tools jar) used a git library before, but this turned out to be problematic and did not reflect what people got when they executed git on the command line.

wilkerlucio12:05:54

an ideia is just to wrap the shell out in some helper functions to feel like an API

borkdude12:05:47

(defn git [& args] (apply babashka.tasks/shell "git" args))
;)

👍 1
wilkerlucio12:05:23

yup, Im just thinking the part of parsing the response, for commands to pull logs and etc

borkdude12:05:23

since https://github.com/clojure/tools.gitlibs migrated to shelling out, it works with babashka from source as well

👍 1
craftybones16:05:48

Thanks all. Just shelled out 😄

craftybones16:05:04

I used git log --format="{:author \"%an\"}" etc to have git return me a nicely formatted object that I can then simply read-string with

5
russmatney19:05:33

i just did something similar a few weeks ago here: https://github.com/russmatney/clawe/blob/master/src/ralphie/git.clj#L334-L392 - i love the format-string -> edn/read-string pattern for reading from command line tools into babashka, it's quite nice

borkdude19:05:02

thanks! should we add ps1 to the list by default maybe? @U013JFLRFS8?

lread19:05:01

I dunno… you can’t launch a .ps1 without a powershell -command

borkdude19:05:26

I guess you also could've used (fs/which "mything.ps1")

borkdude19:05:35

and conj that onto the results

lread19:05:52

yeah mebbe… I was looking to report on the location of lein on my system, it is lein.cmd (a scoop shim) on others it is lein.bat and still others lein.ps1.

borkdude19:05:29

lein.ps1... really?

lread19:05:42

I was as surprised as you are. But it is available and what setup-clojure GitHub Action installs.

borkdude19:05:56

I'm fine with removing the comment and support :win-exts

borkdude19:05:13

PR / doc change welcome

cap10morgan20:05:17

Can a dep add tasks when it's added to bb.edn? Like, just by including it in bb.edn I get new tasks it defines w/o explicitly listing them? a "task library" of sorts

borkdude20:05:52

@cap10morgan That you can't, but you can of course make a library with functions and use that from tasks

cap10morgan20:05:47

Hmm, yep. I was playing around with the idea of generating tasks for the fns in your build.clj file. And then applying babashka smarts like not running some if source files weren't newer like make.

borkdude20:05:39

I guess you could build something like a project.edn which declaratively describes what your build input, output (jar, etc) is and some bb library which does the most common things, including checking if stuff is up to date and then calling tools.build. That's kind of what James's build project is doing too.

borkdude20:05:45

For completeness sake I will also mention the (experimental!) tools.bbuild: https://github.com/babashka/tools.bbuild