From 75d71e31caad0d81e1f7179134e63a6d2a24a146 Mon Sep 17 00:00:00 2001 From: Omni Worker Date: Fri, 21 Nov 2025 18:07:54 -0500 Subject: feat(agent): implement smart base branch selection Amp-Thread-ID: https://ampcode.com/threads/T-79499d9e-f4f4-40de-893c-524c32a45483 Co-authored-by: Amp --- Omni/Agent/Git.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Omni/Agent/Git.hs') diff --git a/Omni/Agent/Git.hs b/Omni/Agent/Git.hs index cf9a122..7717cee 100644 --- a/Omni/Agent/Git.hs +++ b/Omni/Agent/Git.hs @@ -11,6 +11,8 @@ module Omni.Agent.Git commit, createBranch, getCurrentBranch, + branchExists, + isMerged, main, test, ) @@ -175,3 +177,17 @@ getCurrentBranch repo = do case code of Exit.ExitSuccess -> pure <| Text.strip (Text.pack out) _ -> panic "git branch failed" + +branchExists :: FilePath -> Text -> IO Bool +branchExists repo branch = do + let cmd = (Process.proc "git" ["show-ref", "--verify", "refs/heads/" <> Text.unpack branch]) {Process.cwd = Just repo} + (code, _, _) <- Process.readCreateProcessWithExitCode cmd "" + pure (code == Exit.ExitSuccess) + +isMerged :: FilePath -> Text -> Text -> IO Bool +isMerged repo branch target = do + -- Check if 'branch' is merged into 'target' + -- git merge-base --is-ancestor + let cmd = (Process.proc "git" ["merge-base", "--is-ancestor", Text.unpack branch, Text.unpack target]) {Process.cwd = Just repo} + (code, _, _) <- Process.readCreateProcessWithExitCode cmd "" + pure (code == Exit.ExitSuccess) -- cgit v1.2.3