diff options
| author | Omni Worker <bot@omni.agent> | 2025-11-21 21:34:46 -0500 |
|---|---|---|
| committer | Omni Worker <bot@omni.agent> | 2025-11-21 21:34:46 -0500 |
| commit | a08cbd6bef26c138b1cb8089cefe767822d0e494 (patch) | |
| tree | 956a2a880dc5766edab2474a31be4ebe90457bf0 /Omni | |
| parent | 9224442f7f99059706384b3641f69e41c9633d64 (diff) | |
fix(agent): handle empty commits gracefully
Amp-Thread-ID:
https://ampcode.com/threads/T-79499d9e-f4f4-40de-893c-524c32a45483
Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'Omni')
| -rw-r--r-- | Omni/Agent/Git.hs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Omni/Agent/Git.hs b/Omni/Agent/Git.hs index f4a7de5..60e6709 100644 --- a/Omni/Agent/Git.hs +++ b/Omni/Agent/Git.hs @@ -25,8 +25,8 @@ import Omni.Test ((@=?)) 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.IO.Temp as Temp import qualified System.Process as Process main :: IO () @@ -167,7 +167,7 @@ cleanupStaleRebase repo = do -- 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} @@ -178,7 +178,15 @@ commit :: FilePath -> Text -> IO () commit repo msg = do Log.info ["git", "commit", msg] git repo ["add", "."] - git repo ["commit", "-m", Text.unpack msg] + + -- Check for changes before committing to avoid error + let checkCmd = (Process.proc "git" ["diff", "--cached", "--quiet"]) {Process.cwd = Just repo} + (code, _, _) <- Process.readCreateProcessWithExitCode checkCmd "" + + case code of + Exit.ExitSuccess -> Log.warn ["git", "nothing to commit", "skipping"] + Exit.ExitFailure 1 -> git repo ["commit", "-m", Text.unpack msg] + Exit.ExitFailure c -> panic <| "git diff failed with code " <> show c createBranch :: FilePath -> Text -> IO () createBranch repo branch = do |
