diff options
| author | Ben Sima <ben@bensima.com> | 2025-11-22 13:55:28 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-11-22 13:55:28 -0500 |
| commit | 10a2b488519c061eb86c9147cc96b38c82f51ef8 (patch) | |
| tree | 14abeeab9654353259e1baaf8cf462322c58d659 /Omni/Agent/Git.hs | |
| parent | 8697fd8a11a1cf368db1e6c05afddf87906e8de3 (diff) | |
| parent | 960f7226139abd5408454e5285ead2024e0da643 (diff) | |
task: complete t-rWcqsDZFM.2 (Merge)
Amp-Thread-ID:
https://ampcode.com/threads/T-ca3b086b-5a85-422a-b13d-256784c04221
Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'Omni/Agent/Git.hs')
| -rw-r--r-- | Omni/Agent/Git.hs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Omni/Agent/Git.hs b/Omni/Agent/Git.hs index b1978f2..4c06cf6 100644 --- a/Omni/Agent/Git.hs +++ b/Omni/Agent/Git.hs @@ -13,6 +13,10 @@ module Omni.Agent.Git getCurrentBranch, branchExists, isMerged, + listBranches, + showFile, + getRepoRoot, + runGit, main, test, ) @@ -199,3 +203,30 @@ isMerged repo branch target = do 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) + +listBranches :: FilePath -> Text -> IO [Text] +listBranches repo pat = do + let cmd = (Process.proc "git" ["branch", "--list", Text.unpack pat, "--format=%(refname:short)"]) {Process.cwd = Just repo} + (code, out, _) <- Process.readCreateProcessWithExitCode cmd "" + case code of + Exit.ExitSuccess -> pure <| filter (not <. Text.null) (Text.lines (Text.pack out)) + _ -> panic "git branch list failed" + +showFile :: FilePath -> Text -> FilePath -> IO (Maybe Text) +showFile repo branch path = do + let cmd = (Process.proc "git" ["show", Text.unpack branch <> ":" <> path]) {Process.cwd = Just repo} + (code, out, _) <- Process.readCreateProcessWithExitCode cmd "" + case code of + Exit.ExitSuccess -> pure <| Just (Text.pack out) + _ -> pure Nothing + +getRepoRoot :: FilePath -> IO FilePath +getRepoRoot dir = do + let cmd = (Process.proc "git" ["rev-parse", "--show-toplevel"]) {Process.cwd = Just dir} + (code, out, _) <- Process.readCreateProcessWithExitCode cmd "" + case code of + Exit.ExitSuccess -> pure <| strip out + _ -> panic "git rev-parse failed" + +runGit :: FilePath -> [String] -> IO () +runGit = git |
