diff options
Diffstat (limited to 'Git/Branch.hs')
-rw-r--r-- | Git/Branch.hs | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/Git/Branch.hs b/Git/Branch.hs index d4a684016..7b3297d74 100644 --- a/Git/Branch.hs +++ b/Git/Branch.hs @@ -13,7 +13,7 @@ import Common import Git import Git.Sha import Git.Command -import Git.Ref (headRef) +import qualified Git.Ref {- The currently checked out branch. - @@ -36,7 +36,7 @@ current r = do {- The current branch, which may not really exist yet. -} currentUnsafe :: Repo -> IO (Maybe Git.Ref) currentUnsafe r = parse . firstLine - <$> pipeReadStrict [Param "symbolic-ref", Param $ show headRef] r + <$> pipeReadStrict [Param "symbolic-ref", Param $ show Git.Ref.headRef] r where parse l | null l = Nothing @@ -96,8 +96,38 @@ commit message branch parentrefs repo = do pipeReadStrict [Param "write-tree"] repo sha <- getSha "commit-tree" $ pipeWriteRead (map Param $ ["commit-tree", show tree] ++ ps) - message repo - run [Param "update-ref", Param $ show branch, Param $ show sha] repo + (Just $ flip hPutStr message) repo + update branch sha repo return sha where ps = concatMap (\r -> ["-p", show r]) parentrefs + +{- A leading + makes git-push force pushing a branch. -} +forcePush :: String -> String +forcePush b = "+" ++ b + +{- Updates a branch (or other ref) to a new Sha. -} +update :: Branch -> Sha -> Repo -> IO () +update branch sha = run + [ Param "update-ref" + , Param $ show branch + , Param $ show sha + ] + +{- Checks out a branch, creating it if necessary. -} +checkout :: Branch -> Repo -> IO () +checkout branch = run + [ Param "checkout" + , Param "-q" + , Param "-B" + , Param $ show $ Git.Ref.base branch + ] + +{- Removes a branch. -} +delete :: Branch -> Repo -> IO () +delete branch = run + [ Param "branch" + , Param "-q" + , Param "-D" + , Param $ show $ Git.Ref.base branch + ] |