add status

This commit is contained in:
Adam Jeniski 2026-01-05 02:37:41 -05:00
parent bfe5d7f8e4
commit 6e983f08e8

View File

@ -57,6 +57,35 @@
(catch Exception e (catch Exception e
{:success false :repo repo-path :error (.getMessage e)}))) {:success false :repo repo-path :error (.getMessage e)})))
(defn show-status [repo-path]
"Show git status for a repository"
(let [result (process/shell {:dir (str repo-path)
:out :string
:err :string
:continue true}
"git status")]
{:repo repo-path
:status (:out result)}))
(defn status-all []
"Show git status for all modified subrepos"
(let [current-dir (fs/cwd)
subrepos (find-subrepos current-dir)
modified-repos (filter has-changes? subrepos)]
(when (empty? modified-repos)
(println "No repositories with changes found.")
(System/exit 0))
(println (format "Found %d repositories with changes:\n" (count modified-repos)))
(doseq [repo modified-repos]
(let [repo-name (fs/file-name repo)
status-result (show-status repo)]
(println (str "=== " repo-name " ==="))
(println (:status status-result))
(println)))))
(defn commitly [commit-message & {:keys [push?]}] (defn commitly [commit-message & {:keys [push?]}]
"Main function: commit changes across all modified subrepos" "Main function: commit changes across all modified subrepos"
(let [current-dir (fs/cwd) (let [current-dir (fs/cwd)
@ -102,8 +131,20 @@
(if (empty? args) (if (empty? args)
(do (do
(println "Usage: commitly [-p] <commit-message>") (println "Usage: commitly [-p] <commit-message>")
(println " commitly status")
(println "")
(println "Options:")
(println " -p Push changes after committing (or just push if no message)") (println " -p Push changes after committing (or just push if no message)")
(println " status Show git status for all subrepos with changes")
(System/exit 1)) (System/exit 1))
(let [first-arg (first args)]
(cond
;; Status command
(= "status" first-arg)
(status-all)
;; Commit/push command
:else
(let [push? (some #(= "-p" %) args) (let [push? (some #(= "-p" %) args)
message-args (remove #(= "-p" %) args) message-args (remove #(= "-p" %) args)
commit-message (str/join " " message-args)] commit-message (str/join " " message-args)]
@ -128,7 +169,7 @@
(when (str/blank? commit-message) (when (str/blank? commit-message)
(println "Error: commit message cannot be empty") (println "Error: commit message cannot be empty")
(System/exit 1)) (System/exit 1))
(commitly commit-message :push? push?)))))) (commitly commit-message :push? push?))))))))
(when (= *file* (System/getProperty "babashka.file")) (when (= *file* (System/getProperty "babashka.file"))
(apply -main *command-line-args*)) (apply -main *command-line-args*))