From 9224442f7f99059706384b3641f69e41c9633d64 Mon Sep 17 00:00:00 2001 From: Omni Worker Date: Fri, 21 Nov 2025 21:28:07 -0500 Subject: fix(agent): detect stale rebase before aborting Amp-Thread-ID: https://ampcode.com/threads/T-79499d9e-f4f4-40de-893c-524c32a45483 Co-authored-by: Amp --- Omni/Agent/Git.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'Omni') diff --git a/Omni/Agent/Git.hs b/Omni/Agent/Git.hs index 1144774..f4a7de5 100644 --- a/Omni/Agent/Git.hs +++ b/Omni/Agent/Git.hs @@ -26,6 +26,7 @@ import qualified Omni.Test as Test import qualified System.Directory as Directory import qualified System.Exit as Exit import qualified System.IO.Temp as Temp +import System.FilePath (()) import qualified System.Process as Process main :: IO () @@ -163,10 +164,15 @@ syncWithLive repo = do cleanupStaleRebase :: FilePath -> IO () cleanupStaleRebase repo = do - -- Try to abort any in-progress rebase. Ignore failure (e.g. if no rebase in progress) - let abort = (Process.proc "git" ["rebase", "--abort"]) {Process.cwd = Just repo} - _ <- Process.readCreateProcessWithExitCode abort "" - pure () + -- Check if a rebase is in progress + rebaseMerge <- Directory.doesDirectoryExist (repo ".git/rebase-merge") + rebaseApply <- Directory.doesDirectoryExist (repo ".git/rebase-apply") + + when (rebaseMerge || rebaseApply) <| do + Log.warn ["git", "detected stale rebase", "aborting"] + let abort = (Process.proc "git" ["rebase", "--abort"]) {Process.cwd = Just repo} + _ <- Process.readCreateProcessWithExitCode abort "" + pure () commit :: FilePath -> Text -> IO () commit repo msg = do -- cgit v1.2.3