Block handoffs from a dirty working tree

Unrelated tracked changes could ride along with a handoff. Refuse to send when
git status --porcelain is non-empty, list the offending files, and keep the
draft so it can be fixed and resent. SWARMFORGE_ALLOW_DIRTY=1 overrides.

By specifier.
This commit is contained in:
Chris Troutner
2026-09-15 18:28:45 -07:00
parent a5f8967a71
commit 0942b2ef40
2 changed files with 23 additions and 7 deletions
+15
View File
@@ -302,6 +302,20 @@
(fs/move tmp-file outbox-file)
outbox-file))
(defn dirty-files []
(->> (:out (command "." "git" "status" "--porcelain"))
str/split-lines
(remove str/blank?)))
(defn guard-clean-tree! []
(let [dirty (dirty-files)]
(when (and (seq dirty) (not (System/getenv "SWARMFORGE_ALLOW_DIRTY")))
(binding [*out* *err*]
(println "HANDOFF BLOCKED: working tree has uncommitted changes.")
(doseq [line dirty] (println " " line))
(println "Commit or stash them, or set SWARMFORGE_ALLOW_DIRTY=1 to send anyway."))
(System/exit 3))))
(defn error-report [draft errors]
(binding [*out* *err*]
(println "HANDOFF INVALID:" (str draft))
@@ -328,6 +342,7 @@
(when (seq all-errors)
(error-report draft all-errors)
(System/exit 2))
(guard-clean-tree!)
(let [outbox-file (write-handoff! {:headers headers
:recipients (:recipients validation)
:canonical-commit (:canonical-commit validation)