summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-06-21 19:09:20 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-06-21 19:09:20 -0400
commit5d20ac5800f6577fb40ebfa7c8d68df43757a3e1 (patch)
treefc62a89be0fb294b8b05f9653f7e18cfc2a9939b
parent40ec8a9726586f24357a5ae2057a092a971c1046 (diff)
export the commit function and generalize
-rw-r--r--GitUnionMerge.hs21
-rw-r--r--git-union-merge.hs4
2 files changed, 14 insertions, 11 deletions
diff --git a/GitUnionMerge.hs b/GitUnionMerge.hs
index ba9ea79e4..bc12cbe27 100644
--- a/GitUnionMerge.hs
+++ b/GitUnionMerge.hs
@@ -6,7 +6,9 @@
-}
module GitUnionMerge (
- unionMerge
+ merge,
+ stage,
+ commit
) where
import System.Cmd.Utils
@@ -23,10 +25,10 @@ import Utility
- Use indexpopulated only if the index file already contains exactly the
- contents of aref.
-}
-unionMerge :: Git.Repo -> String -> String -> String -> Bool -> IO ()
-unionMerge g aref bref newref indexpopulated = do
+merge :: Git.Repo -> String -> String -> String -> Bool -> IO ()
+merge g aref bref newref indexpopulated = do
stage g aref bref indexpopulated
- commit g aref bref newref
+ commit g "union merge" newref [aref, bref]
{- Stages the content of both refs into the index. -}
stage :: Git.Repo -> String -> String -> Bool -> IO ()
@@ -68,14 +70,15 @@ stage g aref bref indexpopulated = do
sha <- Git.hashObject g $ unionmerge content
return $ Just $ ls_tree_line sha file
-{- Commits the index into the specified branch, as a merge commit. -}
-commit :: Git.Repo -> String -> String -> String -> IO ()
-commit g aref bref newref = do
+{- Commits the index into the specified branch. If refs are specified,
+ - commits a merge. -}
+commit :: Git.Repo -> String -> String -> [String] -> IO ()
+commit g message newref mergedrefs = do
tree <- Git.getSha "write-tree" $ ignorehandle $
pipeFrom "git" ["write-tree"]
sha <- Git.getSha "commit-tree" $ ignorehandle $
- pipeBoth "git" ["commit-tree", tree, "-p", aref, "-p", bref]
- "union merge"
+ pipeBoth "git" (["commit-tree", tree] ++ ps) message
Git.run g "update-ref" [Param newref, Param sha]
where
ignorehandle a = return . snd =<< a
+ ps = concatMap (\r -> ["-p", r]) mergedrefs
diff --git a/git-union-merge.hs b/git-union-merge.hs
index e8ac0a0c5..f02db6be3 100644
--- a/git-union-merge.hs
+++ b/git-union-merge.hs
@@ -10,7 +10,7 @@ import System.FilePath
import System.Directory
import Control.Monad (when)
-import GitUnionMerge
+import qualified GitUnionMerge
import qualified GitRepo as Git
header :: String
@@ -44,5 +44,5 @@ main = do
g <- Git.configRead =<< Git.repoFromCwd
Git.useIndex (tmpIndex g)
setup g
- unionMerge g aref bref newref False
+ GitUnionMerge.merge g aref bref newref False
cleanup g