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