]> njoseph.me Git - babashka-scripts.git/blob - git-pull-all.clj
Add babashka self-updater script
[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]
6 '[clojure.java.io :as io])
7
8 (def default-root ".")
9
10 (defn list-dirs
11 [root]
12 (filter #(.isDirectory %) (.listFiles (io/file root))))
13
14 (defn git-pull
15 [dir]
16 (p/process ["git" "-C" dir "pull" "--rebase"]))
17
18 (when (= *file* (System/getProperty "babashka.file"))
19 (let [root (get (into [] *command-line-args*) 0 default-root)
20 dirs (list-dirs root)
21 pulls (->> root
22 list-dirs
23 (map git-pull)
24 doall)
25 outputs (map #(->> % p/check :out slurp) pulls)]
26
27 ;; Print corresponding directory name when pulling
28 ;; Skip printing already up to date repos
29 (doseq [[dir out](filter #(not (.contains (second %) "is up to date."))
30 (map vector dirs outputs))]
31 (println (str dir "\n" out)))))