diff options
Diffstat (limited to 'Omni/Agent/Git.hs')
| -rw-r--r-- | Omni/Agent/Git.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Omni/Agent/Git.hs b/Omni/Agent/Git.hs index a7afb20..7ee8a16 100644 --- a/Omni/Agent/Git.hs +++ b/Omni/Agent/Git.hs @@ -7,6 +7,10 @@ -- : dep temporary module Omni.Agent.Git ( checkout, + syncWithLive, + commit, + createBranch, + getCurrentBranch, main, test, ) @@ -136,3 +140,38 @@ git dir args = do Log.info [Text.pack err] Log.br panic <| "git command failed: git " <> show args + +syncWithLive :: FilePath -> IO () +syncWithLive repo = do + Log.info ["git", "syncing with live"] + git repo ["fetch", "origin", "live"] + + -- Try rebase, if fail, abort + let cmd = (Process.proc "git" ["rebase", "origin/live"]) {Process.cwd = Just repo} + (code, _, err) <- Process.readCreateProcessWithExitCode cmd "" + case code of + Exit.ExitSuccess -> pure () + Exit.ExitFailure _ -> do + Log.warn ["rebase failed, aborting", Text.pack err] + let abort = (Process.proc "git" ["rebase", "--abort"]) {Process.cwd = Just repo} + _ <- Process.readCreateProcessWithExitCode abort "" + panic "Sync with live failed (rebase conflict)" + +commit :: FilePath -> Text -> IO () +commit repo msg = do + Log.info ["git", "commit", msg] + git repo ["add", "."] + git repo ["commit", "-m", Text.unpack msg] + +createBranch :: FilePath -> Text -> IO () +createBranch repo branch = do + Log.info ["git", "create branch", branch] + git repo ["checkout", "-b", Text.unpack branch] + +getCurrentBranch :: FilePath -> IO Text +getCurrentBranch repo = do + let cmd = (Process.proc "git" ["branch", "--show-current"]) {Process.cwd = Just repo} + (code, out, _) <- Process.readCreateProcessWithExitCode cmd "" + case code of + Exit.ExitSuccess -> pure <| Text.strip (Text.pack out) + _ -> panic "git branch failed" |
