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