2 (:require [babashka.process :as p]
3 [clojure.java.io :as io]
4 [clojure.string :as str]
5 [lib :refer [run-cmd]]))
7 ; Utilities for git operations
11 (first (filter #(= ".git" %)
13 (filter #(.isDirectory %) (.listFiles (io/file dir)))))))
17 (filter #(has-git-repo %)
18 (filter #(.isDirectory %) (.listFiles (io/file root)))))
20 (defn- git-pull [dir] (p/process ["git" "-C" dir "pull" "--rebase"]))
23 "Runs `git-pull` on all the git repositories in a directory"
25 (let [dirs (list-dirs root)
35 ;; Print corresponding directory name when pulling
36 ;; Skip printing already up to date repos
37 (doseq [[dir out] (filter #(not (.contains (second %) "is up to date."))
38 (map vector dirs outputs))]
39 (println (str dir "\n" out)))))
42 (defn git-pull-rebase-branch
43 "Do git pull and rebase branch with master"
45 (run-cmd ["git" "pull" "--rebase"])
46 (let [current-branch (str/trim (run-cmd ["git" "branch" "--show-current"]))]
47 (when (not (contains? #{"master" "main"} current-branch))
50 [["git" "checkout" "master"] ["git" "pull" "--rebase"]
51 ["git" "checkout" current-branch] ["git" "rebase" "master"]])))))