Format all Clojure files using zprint
[babashka-scripts.git] / git-pull-all.clj
1 #! /usr/bin/env bb
2
3 ; Runs `git pull` on all the git repositories in a directory
4
5 (require '[babashka.process :as p] '[clojure.java.io :as io])
6
7 (def default-root ".")
8
9 (defn list-dirs [root] (filter #(.isDirectory %) (.listFiles (io/file root))))
10
11 (defn git-pull [dir] (p/process ["git" "-C" dir "pull" "--rebase"]))
12
13 (when (= *file* (System/getProperty "babashka.file"))
14 (let [root (get (into [] *command-line-args*) 0 default-root)
15 dirs (list-dirs root)
16 pulls (->> root
17 list-dirs
18 (map git-pull)
19 doall)
20 outputs (map #(->> %
21 p/check
22 :out
23 slurp)
24 pulls)]
25 ;; Print corresponding directory name when pulling
26 ;; Skip printing already up to date repos
27 (doseq [[dir out] (filter #(not (.contains (second %) "is up to date."))
28 (map vector dirs outputs))]
29 (println (str dir "\n" out)))))