2012-06-23 14:22:56 +00:00
|
|
|
{- git merging
|
|
|
|
-
|
2021-07-19 15:28:31 +00:00
|
|
|
- Copyright 2012-2021 Joey Hess <id@joeyh.name>
|
2012-06-23 14:22:56 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2012-06-23 14:22:56 +00:00
|
|
|
-}
|
|
|
|
|
2016-04-22 18:26:44 +00:00
|
|
|
module Git.Merge (
|
|
|
|
MergeConfig(..),
|
|
|
|
CommitMode(..),
|
|
|
|
merge,
|
|
|
|
merge',
|
2019-03-22 17:47:16 +00:00
|
|
|
mergeUnrelatedHistoriesParam,
|
2016-04-22 18:26:44 +00:00
|
|
|
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.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
|
2021-07-19 15:28:31 +00:00
|
|
|
-- ^ avoids interactive merge with commit message edit
|
2016-04-22 18:26:44 +00:00
|
|
|
| MergeUnrelatedHistories
|
2020-09-07 17:03:51 +00:00
|
|
|
-- ^ avoids git's prevention of merging unrelated histories
|
2021-07-19 15:28:31 +00:00
|
|
|
| MergeQuiet
|
|
|
|
-- ^ avoids usual output when merging, but errors will still be
|
|
|
|
-- displayed
|
2016-04-22 18:26:44 +00:00
|
|
|
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
|
2019-09-11 20:10:25 +00:00
|
|
|
| MergeNonInteractive `notElem` mergeconfig =
|
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
|
2021-07-19 15:28:31 +00:00
|
|
|
go ps = merge'' (sp ++ [Param "merge"] ++ qp ++ 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 = []
|
2021-07-19 15:28:31 +00:00
|
|
|
qp
|
|
|
|
| MergeQuiet `notElem` mergeconfig = []
|
|
|
|
| otherwise = [Param "--quiet"]
|
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
|
2019-03-22 17:47:16 +00:00
|
|
|
| MergeUnrelatedHistories `elem` mergeconfig = do
|
|
|
|
up <- mergeUnrelatedHistoriesParam
|
|
|
|
go (ps ++ maybeToList up)
|
2016-04-22 19:56:13 +00:00
|
|
|
| otherwise = go ps
|
|
|
|
where
|
|
|
|
go ps' = runBool ps' r
|
|
|
|
|
2019-03-22 17:47:16 +00:00
|
|
|
{- Git used to default to merging unrelated histories; newer versions need
|
|
|
|
- an option. -}
|
|
|
|
mergeUnrelatedHistoriesParam :: IO (Maybe CommandParam)
|
|
|
|
mergeUnrelatedHistoriesParam = ifM (Git.Version.older "2.9.0")
|
|
|
|
( return Nothing
|
|
|
|
, return (Just (Param "--allow-unrelated-histories"))
|
|
|
|
)
|
|
|
|
|
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
|
|
|
]
|