X-Git-Url: https://njoseph.me/gitweb/babashka-scripts.git/blobdiff_plain/ec37ad05d576d79b3dc2d05b2bcae632a93e8c35..4dcdd4a9d879b2787550e849673e7e967878fd92:/scripts/git.clj diff --git a/scripts/git.clj b/scripts/git.clj index b84cffb..e722c08 100755 --- a/scripts/git.clj +++ b/scripts/git.clj @@ -6,8 +6,6 @@ ; Utilities for git operations -(def default-root ".") - (defn- has-git-repo [dir] (first (filter #(= ".git" %) @@ -19,11 +17,13 @@ (filter #(has-git-repo %) (filter #(.isDirectory %) (.listFiles (io/file root))))) -(defn- git-pull [dir] +(defn- git-pull + "Do a git pull with rebase." + [dir] (p/process ["git" "-C" dir "pull" "--rebase"])) (defn git-pull-all - "Runs `git-pull` on all the git repositories in a directory" + "Runs `git-pull` on all the git repositories in a directory." [root] (let [dirs (list-dirs root) pulls (->> root @@ -34,23 +34,21 @@ p/check :out slurp) - pulls)] + pulls)] ;; Print corresponding directory name when pulling ;; Skip printing already up to date repos (doseq [[dir out] (filter #(not (.contains (second %) "is up to date.")) - (map vector dirs outputs))] + (map vector dirs outputs))] (println (str dir "\n" out))))) (defn git-pull-rebase-branch - "Do git pull and rebase branch with master" + "Do git pull and rebase branch with master." [dir] + (git-pull dir) (let [current-branch (str/trim (run-cmd ["git" "branch" "--show-current"]))] - (git-pull dir) (when (not (contains? #{"master" "main"} current-branch)) (run! print (map run-cmd - '[["git" "checkout" "master"] - ["git" "pull" "--rebase"] - ["git" "checkout" "-"] - ["git" "rebase" "master"]]))))) + [["git" "checkout" "master"] ["git" "pull" "--rebase"] + ["git" "checkout" current-branch] ["git" "rebase" "master"]])))))