]> njoseph.me Git - babashka-scripts.git/blame - git-pull-all.clj
Utility to install deb packages using gdebi
[babashka-scripts.git] / git-pull-all.clj
CommitLineData
fa20f4c6
JN
1#! /usr/bin/env bb
2
3; Runs `git pull` on all the git repositories in a directory
4
0b0f2aa3 5(require '[babashka.process :as p] '[clojure.java.io :as io])
fa20f4c6
JN
6
7(def default-root ".")
fa20f4c6 8
0b0f2aa3
JN
9(defn list-dirs [root] (filter #(.isDirectory %) (.listFiles (io/file root))))
10
11(defn git-pull [dir] (p/process ["git" "-C" dir "pull" "--rebase"]))
fa20f4c6
JN
12
13(when (= *file* (System/getProperty "babashka.file"))
0b0f2aa3
JN
14 (let [root (get (into [] *command-line-args*) 0 default-root)
15 dirs (list-dirs root)
fa20f4c6
JN
16 pulls (->> root
17 list-dirs
18 (map git-pull)
19 doall)
0b0f2aa3
JN
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)))))