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, checkIndicatorFiles,
-- * Notifications -- * Notifications
notifyConflict, notifyUser,
-- * File filtering -- * File filtering
isGitIgnored, isGitIgnored,
@@ -266,8 +266,11 @@ syncRepo opts logger repo = do
| "nothing to commit" `T.isInfixOf` commitOut | "nothing to commit" `T.isInfixOf` commitOut
|| "nothing to commit" `T.isInfixOf` commitErr -> || "nothing to commit" `T.isInfixOf` commitErr ->
logRepo logger repo "nothing to commit (working tree clean)" 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)) 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 -- Pull
logRepo logger repo ("pulling " <> rcRemote repo <> "/" <> rcBranch repo) logRepo logger repo ("pulling " <> rcRemote repo <> "/" <> rcBranch repo)
(pullCode, pullOut, pullErr) <- gitPull repo (pullCode, pullOut, pullErr) <- gitPull repo
@@ -277,14 +280,19 @@ syncRepo opts logger repo = do
if T.null trimmed if T.null trimmed
then logRepo logger repo "pull: already up to date" then logRepo logger repo "pull: already up to date"
else logRepo logger repo ("pull succeeded:\n" <> trimmed) else logRepo logger repo ("pull succeeded:\n" <> trimmed)
_ -> _ -> do
logRepo logger repo ("pull FAILED (exit " <> T.pack (show pullCode) <> "): " <> T.strip (pullOut <> pullErr)) 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 -- Conflict check
conflicted <- hasConflicts (rcPath repo) conflicted <- hasConflicts (rcPath repo)
if conflicted if conflicted
then do then do
logRepo logger repo "*** MERGE CONFLICT detected! ***" 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" else logRepo logger repo "sync complete, no conflicts"
---------------------------------------------------------------------- ----------------------------------------------------------------------
@@ -361,16 +369,11 @@ checkIndicatorFiles gitDir = do
-- Notifications -- Notifications
---------------------------------------------------------------------- ----------------------------------------------------------------------
-- | Send a desktop notification about a merge conflict. -- | Send a desktop notification.
notifyConflict :: Options -> RepoConfig -> IO () notifyUser :: Options -> String -> String -> IO ()
notifyConflict opts repo = do notifyUser opts title body = do
let cmd = T.unpack (optNotifyCmd opts) let cmd = T.unpack (optNotifyCmd opts)
title = "Converge: Merge Conflict" _ <- spawnProcess cmd ["--urgency=critical", title, body]
body =
"A merge conflict occurred in "
<> T.pack (rcPath repo)
<> ". Manual resolution required."
_ <- spawnProcess cmd ["--urgency=critical", title, T.unpack body]
pure () pure ()
---------------------------------------------------------------------- ----------------------------------------------------------------------