add status
This commit is contained in:
parent
bfe5d7f8e4
commit
6e983f08e8
93
commitly
93
commitly
@ -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,33 +131,45 @@
|
|||||||
(if (empty? args)
|
(if (empty? args)
|
||||||
(do
|
(do
|
||||||
(println "Usage: commitly [-p] <commit-message>")
|
(println "Usage: commitly [-p] <commit-message>")
|
||||||
(println " -p Push changes after committing (or just push if no message)")
|
(println " commitly status")
|
||||||
|
(println "")
|
||||||
|
(println "Options:")
|
||||||
|
(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 [push? (some #(= "-p" %) args)
|
(let [first-arg (first args)]
|
||||||
message-args (remove #(= "-p" %) args)
|
(cond
|
||||||
commit-message (str/join " " message-args)]
|
;; Status command
|
||||||
(if (and (str/blank? commit-message) push?)
|
(= "status" first-arg)
|
||||||
;; If -p is enabled and no message, just push without committing
|
(status-all)
|
||||||
(do
|
|
||||||
(println "No commit message provided with -p flag. Pushing only...")
|
;; Commit/push command
|
||||||
(let [current-dir (fs/cwd)
|
:else
|
||||||
subrepos (find-subrepos current-dir)]
|
(let [push? (some #(= "-p" %) args)
|
||||||
(println "\nPushing changes...")
|
message-args (remove #(= "-p" %) args)
|
||||||
(let [push-results (map push-changes subrepos)]
|
commit-message (str/join " " message-args)]
|
||||||
(doseq [result push-results]
|
(if (and (str/blank? commit-message) push?)
|
||||||
(if (:success result)
|
;; If -p is enabled and no message, just push without committing
|
||||||
(println (format "✓ %s" (fs/file-name (:repo result))))
|
(do
|
||||||
(println (format "✗ %s: %s" (fs/file-name (:repo result)) (:error result)))))
|
(println "No commit message provided with -p flag. Pushing only...")
|
||||||
(let [failed (filter #(not (:success %)) push-results)]
|
(let [current-dir (fs/cwd)
|
||||||
(when (seq failed)
|
subrepos (find-subrepos current-dir)]
|
||||||
(println (format "\n%d repositories failed to push" (count failed)))
|
(println "\nPushing changes...")
|
||||||
(System/exit 1))))))
|
(let [push-results (map push-changes subrepos)]
|
||||||
;; Otherwise, require commit message
|
(doseq [result push-results]
|
||||||
(do
|
(if (:success result)
|
||||||
(when (str/blank? commit-message)
|
(println (format "✓ %s" (fs/file-name (:repo result))))
|
||||||
(println "Error: commit message cannot be empty")
|
(println (format "✗ %s: %s" (fs/file-name (:repo result)) (:error result)))))
|
||||||
(System/exit 1))
|
(let [failed (filter #(not (:success %)) push-results)]
|
||||||
(commitly commit-message :push? push?))))))
|
(when (seq failed)
|
||||||
|
(println (format "\n%d repositories failed to push" (count failed)))
|
||||||
|
(System/exit 1))))))
|
||||||
|
;; Otherwise, require commit message
|
||||||
|
(do
|
||||||
|
(when (str/blank? commit-message)
|
||||||
|
(println "Error: commit message cannot be empty")
|
||||||
|
(System/exit 1))
|
||||||
|
(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*))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user