2012-06-23 14:22:56 +00:00
|
|
|
{- git merging
|
|
|
|
-
|
2016-04-22 18:26:44 +00:00
|
|
|
- Copyright 2012-2016 Joey Hess <id@joeyh.name>
|
2012-06-23 14:22:56 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2016-04-22 18:26:44 +00:00
|
|
|
module Git.Merge (
|
|
|
|
MergeConfig(..),
|
|
|
|
CommitMode(..),
|
|
|
|
merge,
|
|
|
|
merge',
|
|
|
|
stageMerge,
|
|
|
|
) where
|
2012-06-23 14:22:56 +00:00
|
|
|
|
|
|
|
import Common
|
|
|
|
import Git
|
|
|
|
import Git.Command
|
2016-04-22 19:56:13 +00:00
|
|
|
import qualified Git.BuildVersion
|
|
|
|
import qualified Git.Version
|
2014-07-04 15:36:59 +00:00
|
|
|
import Git.Branch (CommitMode(..))
|
2012-06-23 14:22:56 +00:00
|
|
|
|
2016-04-22 18:26:44 +00:00
|
|
|
data MergeConfig
|
|
|
|
= MergeNonInteractive
|
|
|
|
-- ^ avoids recent git's interactive merge
|
|
|
|
| MergeUnrelatedHistories
|
|
|
|
-- ^ avoids recent git's prevention of merging unrelated histories
|
|
|
|
deriving (Eq)
|
2016-04-06 22:40:28 +00:00
|
|
|
|
2016-04-22 18:26:44 +00:00
|
|
|
merge :: Ref -> [MergeConfig] -> CommitMode -> Repo -> IO Bool
|
|
|
|
merge = merge' []
|
|
|
|
|
|
|
|
merge' :: [CommandParam] -> Ref -> [MergeConfig] -> CommitMode -> Repo -> IO Bool
|
|
|
|
merge' extraparams branch mergeconfig commitmode r
|
2016-04-22 19:56:13 +00:00
|
|
|
| MergeNonInteractive `notElem` mergeconfig || Git.BuildVersion.older "1.7.7.6" =
|
2016-04-22 18:26:44 +00:00
|
|
|
go [Param $ fromRef branch]
|
|
|
|
| otherwise = go [Param "--no-edit", Param $ fromRef branch]
|
2013-03-03 17:39:07 +00:00
|
|
|
where
|
2016-04-22 19:56:13 +00:00
|
|
|
go ps = merge'' (sp ++ [Param "merge"] ++ ps ++ extraparams) mergeconfig r
|
2016-04-06 22:40:28 +00:00
|
|
|
sp
|
2014-07-04 15:36:59 +00:00
|
|
|
| commitmode == AutomaticCommit =
|
|
|
|
[Param "-c", Param "commit.gpgsign=false"]
|
|
|
|
| otherwise = []
|
2014-06-09 22:01:30 +00:00
|
|
|
|
2016-04-22 19:56:13 +00:00
|
|
|
merge'' :: [CommandParam] -> [MergeConfig] -> Repo -> IO Bool
|
|
|
|
merge'' ps mergeconfig r
|
|
|
|
| MergeUnrelatedHistories `elem` mergeconfig =
|
|
|
|
ifM (Git.Version.older "2.8.2")
|
|
|
|
( go (ps ++ [Param "--allow-unrelated-histories"])
|
|
|
|
, go ps
|
|
|
|
)
|
|
|
|
| otherwise = go ps
|
|
|
|
where
|
|
|
|
go ps' = runBool ps' r
|
|
|
|
|
2014-06-09 22:01:30 +00:00
|
|
|
{- Stage the merge into the index, but do not commit it.-}
|
2016-04-22 18:26:44 +00:00
|
|
|
stageMerge :: Ref -> [MergeConfig] -> Repo -> IO Bool
|
2016-04-22 19:56:13 +00:00
|
|
|
stageMerge branch = merge''
|
2014-06-09 22:01:30 +00:00
|
|
|
[ Param "merge"
|
|
|
|
, Param "--quiet"
|
|
|
|
, Param "--no-commit"
|
|
|
|
-- Without this, a fast-forward merge is done, since it involves no
|
|
|
|
-- commit.
|
|
|
|
, Param "--no-ff"
|
|
|
|
, Param $ fromRef branch
|
2016-04-22 19:56:13 +00:00
|
|
|
]
|