summaryrefslogtreecommitdiff
path: root/Omni/Agent/Git.hs
diff options
context:
space:
mode:
authorOmni Worker <bot@omni.agent>2025-11-21 18:07:54 -0500
committerOmni Worker <bot@omni.agent>2025-11-21 18:07:54 -0500
commit75d71e31caad0d81e1f7179134e63a6d2a24a146 (patch)
tree80237a656621fb1a33cb8f1ced707c796b2d7173 /Omni/Agent/Git.hs
parent45521bda259c54458404ca8cda18615f0d36b492 (diff)
feat(agent): implement smart base branch selection
Amp-Thread-ID: https://ampcode.com/threads/T-79499d9e-f4f4-40de-893c-524c32a45483 Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'Omni/Agent/Git.hs')
-rw-r--r--Omni/Agent/Git.hs16
1 files changed, 16 insertions, 0 deletions
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 <branch> <target>
+ 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)