Notify on all git operation failures, not just merge conflicts

Generalize notifyConflict into notifyUser that accepts an arbitrary
title and body.  Call notify-send for commit failures and pull
failures in addition to the existing merge-conflict notification.
"Nothing to commit" is intentionally excluded — it is an expected
no-op, not a failure.
This commit is contained in:
2026-05-13 22:05:26 -04:00
parent bcf43d5d83
commit eb847c03f6
+16 -13
View File
@@ -28,7 +28,7 @@ module Converge (
checkIndicatorFiles,
-- * Notifications
notifyConflict,
notifyUser,
-- * File filtering
isGitIgnored,
@@ -266,8 +266,11 @@ syncRepo opts logger repo = do
| "nothing to commit" `T.isInfixOf` commitOut
|| "nothing to commit" `T.isInfixOf` commitErr ->
logRepo logger repo "nothing to commit (working tree clean)"
| otherwise ->
| otherwise -> do
logRepo logger repo ("commit FAILED (exit " <> T.pack (show commitCode) <> "): " <> T.strip (commitOut <> commitErr))
notifyUser opts
"Converge: Commit Failed"
("Commit failed in " <> rcPath repo <> " (exit " <> show commitCode <> ")")
-- Pull
logRepo logger repo ("pulling " <> rcRemote repo <> "/" <> rcBranch repo)
(pullCode, pullOut, pullErr) <- gitPull repo
@@ -277,14 +280,19 @@ syncRepo opts logger repo = do
if T.null trimmed
then logRepo logger repo "pull: already up to date"
else logRepo logger repo ("pull succeeded:\n" <> trimmed)
_ ->
_ -> do
logRepo logger repo ("pull FAILED (exit " <> T.pack (show pullCode) <> "): " <> T.strip (pullOut <> pullErr))
notifyUser opts
"Converge: Pull Failed"
("Pull failed in " <> rcPath repo <> " (exit " <> show pullCode <> ")")
-- Conflict check
conflicted <- hasConflicts (rcPath repo)
if conflicted
then do
logRepo logger repo "*** MERGE CONFLICT detected! ***"
notifyConflict opts repo
notifyUser opts
"Converge: Merge Conflict"
("A merge conflict occurred in " <> rcPath repo <> ". Manual resolution required.")
else logRepo logger repo "sync complete, no conflicts"
----------------------------------------------------------------------
@@ -361,16 +369,11 @@ checkIndicatorFiles gitDir = do
-- Notifications
----------------------------------------------------------------------
-- | Send a desktop notification about a merge conflict.
notifyConflict :: Options -> RepoConfig -> IO ()
notifyConflict opts repo = do
-- | Send a desktop notification.
notifyUser :: Options -> String -> String -> IO ()
notifyUser opts title body = do
let cmd = T.unpack (optNotifyCmd opts)
title = "Converge: Merge Conflict"
body =
"A merge conflict occurred in "
<> T.pack (rcPath repo)
<> ". Manual resolution required."
_ <- spawnProcess cmd ["--urgency=critical", title, T.unpack body]
_ <- spawnProcess cmd ["--urgency=critical", title, body]
pure ()
----------------------------------------------------------------------