summaryrefslogtreecommitdiff
path: root/Command/ResolveMerge.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-07-11 16:45:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-07-11 16:45:18 -0400
commit2a727e8c5f8d003af7102ea7de22e45a5faec421 (patch)
tree661d008aeb7f13c873c9afb7dcfa360aed60a528 /Command/ResolveMerge.hs
parent64b74f4c616bd1aa42e7833b449586b64dac1ba5 (diff)
resolvemerge: New plumbing command that runs the automatic merge conflict resolver.
Diffstat (limited to 'Command/ResolveMerge.hs')
-rw-r--r--Command/ResolveMerge.hs38
1 files changed, 38 insertions, 0 deletions
diff --git a/Command/ResolveMerge.hs b/Command/ResolveMerge.hs
new file mode 100644
index 000000000..b1091e981
--- /dev/null
+++ b/Command/ResolveMerge.hs
@@ -0,0 +1,38 @@
+{- git-annex command
+ -
+ - Copyright 2014 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Command.ResolveMerge where
+
+import Common.Annex
+import Command
+import qualified Git
+import Git.Sha
+import qualified Git.Branch
+import Annex.AutoMerge
+
+def :: [Command]
+def = [command "resolvemerge" paramNothing seek SectionPlumbing
+ "resolve merge conflicts"]
+
+seek :: CommandSeek
+seek ps = withNothing start ps
+
+start :: CommandStart
+start = do
+ showStart "resolvemerge" ""
+ us <- fromMaybe nobranch <$> inRepo Git.Branch.current
+ d <- fromRepo Git.localGitDir
+ let merge_head = d </> "MERGE_HEAD"
+ them <- fromMaybe (error nomergehead) . extractSha
+ <$> liftIO (readFile merge_head)
+ ifM (resolveMerge (Just us) them)
+ ( next $ next $ return True
+ , error "Merge conflict could not be automatically resolved."
+ )
+ where
+ nobranch = error "No branch is currently checked out."
+ nomergehead = error "No SHA found in .git/merge_head"