From 25b2cc4148e4cc8f7435cdbcf4b124cc317c1305 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 13 Dec 2011 15:08:44 -0400 Subject: move commit to Git.Branch --- Git/Branch.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Git/Branch.hs') diff --git a/Git/Branch.hs b/Git/Branch.hs index e69e96f28..8b0d1e5af 100644 --- a/Git/Branch.hs +++ b/Git/Branch.hs @@ -58,3 +58,20 @@ fastForward branch (first:rest) repo = do (True, False) -> findbest r rs -- better (False, True) -> findbest c rs -- worse (False, False) -> findbest c rs -- same + +{- Commits the index into the specified branch (or other ref), + - with the specified parent refs, and returns the committed sha -} +commit :: String -> Branch -> [Ref] -> Repo -> IO Sha +commit message branch parentrefs repo = do + tree <- getSha "write-tree" $ asString $ + pipeRead [Param "write-tree"] repo + sha <- getSha "commit-tree" $ asString $ + ignorehandle $ pipeWriteRead + (map Param $ ["commit-tree", show tree] ++ ps) + (L.pack message) repo + run "update-ref" [Param $ show branch, Param $ show sha] repo + return sha + where + ignorehandle a = snd <$> a + asString a = L.unpack <$> a + ps = concatMap (\r -> ["-p", show r]) parentrefs -- cgit v1.2.3