sync, merge: Added --allow-unrelated-histories option
Which is the same as the git merge option. After last commit, this turns out to be needed in the test suite, and when doing git-annex import from special remote, followed by a git-annex merge. Sponsored-by: Svenne Krap on Patreon
This commit is contained in:
parent
b6bea0d3f2
commit
3d50b47ded
7 changed files with 67 additions and 34 deletions
|
@ -1,6 +1,6 @@
|
|||
{- git-annex command
|
||||
-
|
||||
- Copyright 2011-2019 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2011-2021 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -12,22 +12,34 @@ import qualified Annex.Branch
|
|||
import qualified Git
|
||||
import qualified Git.Branch
|
||||
import Annex.CurrentBranch
|
||||
import Command.Sync (prepMerge, mergeLocal, mergeConfig, merge, SyncOptions(..))
|
||||
import Command.Sync (prepMerge, mergeLocal, mergeConfig, merge, notOnlyAnnexOption, parseUnrelatedHistoriesOption)
|
||||
import Git.Types
|
||||
|
||||
cmd :: Command
|
||||
cmd = command "merge" SectionMaintenance
|
||||
"merge changes from remotes"
|
||||
(paramOptional paramRef) (withParams seek)
|
||||
(paramOptional paramRef) (seek <$$> optParser)
|
||||
|
||||
seek :: CmdParams -> CommandSeek
|
||||
seek [] = do
|
||||
prepMerge
|
||||
commandAction mergeAnnexBranch
|
||||
commandAction mergeSyncedBranch
|
||||
seek bs = do
|
||||
prepMerge
|
||||
forM_ bs (commandAction . mergeBranch . Git.Ref . encodeBS')
|
||||
data MergeOptions = MergeOptions
|
||||
{ mergeBranches :: [String]
|
||||
, allowUnrelatedHistories :: Bool
|
||||
}
|
||||
|
||||
optParser :: CmdParamsDesc -> Parser MergeOptions
|
||||
optParser desc = MergeOptions
|
||||
<$> cmdParams desc
|
||||
<*> parseUnrelatedHistoriesOption
|
||||
|
||||
seek :: MergeOptions -> CommandSeek
|
||||
seek o
|
||||
| mergeBranches o == [] = do
|
||||
prepMerge
|
||||
commandAction mergeAnnexBranch
|
||||
commandAction (mergeSyncedBranch o)
|
||||
| otherwise = do
|
||||
prepMerge
|
||||
forM_ (mergeBranches o) $
|
||||
commandAction . mergeBranch o . Git.Ref . encodeBS'
|
||||
|
||||
mergeAnnexBranch :: CommandStart
|
||||
mergeAnnexBranch = starting "merge" ai si $ do
|
||||
|
@ -39,17 +51,17 @@ mergeAnnexBranch = starting "merge" ai si $ do
|
|||
ai = ActionItemOther (Just (fromRef Annex.Branch.name))
|
||||
si = SeekInput []
|
||||
|
||||
mergeSyncedBranch :: CommandStart
|
||||
mergeSyncedBranch = do
|
||||
mc <- mergeConfig False
|
||||
mergeSyncedBranch :: MergeOptions -> CommandStart
|
||||
mergeSyncedBranch o = do
|
||||
mc <- mergeConfig (allowUnrelatedHistories o)
|
||||
mergeLocal mc def =<< getCurrentBranch
|
||||
|
||||
mergeBranch :: Git.Ref -> CommandStart
|
||||
mergeBranch r = starting "merge" ai si $ do
|
||||
mergeBranch :: MergeOptions -> Git.Ref -> CommandStart
|
||||
mergeBranch o r = starting "merge" ai si $ do
|
||||
currbranch <- getCurrentBranch
|
||||
let o = def { notOnlyAnnexOption = True }
|
||||
mc <- mergeConfig False
|
||||
next $ merge currbranch mc o Git.Branch.ManualCommit r
|
||||
mc <- mergeConfig (allowUnrelatedHistories o)
|
||||
let so = def { notOnlyAnnexOption = True }
|
||||
next $ merge currbranch mc so Git.Branch.ManualCommit r
|
||||
where
|
||||
ai = ActionItemOther (Just (Git.fromRef r))
|
||||
si = SeekInput []
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{- git-annex command
|
||||
-
|
||||
- Copyright 2011 Joachim Breitner <mail@joachim-breitner.de>
|
||||
- Copyright 2011-2020 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2011-2021 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -24,6 +24,7 @@ module Command.Sync (
|
|||
syncBranch,
|
||||
updateBranches,
|
||||
seekExportContent,
|
||||
parseUnrelatedHistoriesOption,
|
||||
SyncOptions(..),
|
||||
) where
|
||||
|
||||
|
@ -102,6 +103,7 @@ data SyncOptions = SyncOptions
|
|||
, cleanupOption :: Bool
|
||||
, keyOptions :: Maybe KeyOptions
|
||||
, resolveMergeOverride :: Bool
|
||||
, allowUnrelatedHistories :: Bool
|
||||
}
|
||||
|
||||
instance Default SyncOptions where
|
||||
|
@ -120,6 +122,7 @@ instance Default SyncOptions where
|
|||
, cleanupOption = False
|
||||
, keyOptions = Nothing
|
||||
, resolveMergeOverride = False
|
||||
, allowUnrelatedHistories = False
|
||||
}
|
||||
|
||||
optParser :: CmdParamsDesc -> Parser SyncOptions
|
||||
|
@ -177,6 +180,13 @@ optParser desc = SyncOptions
|
|||
<*> invertableSwitch "resolvemerge" True
|
||||
( help "do not automatically resolve merge conflicts"
|
||||
)
|
||||
<*> parseUnrelatedHistoriesOption
|
||||
|
||||
parseUnrelatedHistoriesOption :: Parser Bool
|
||||
parseUnrelatedHistoriesOption =
|
||||
invertableSwitch "allow-unrelated-histories" False
|
||||
( help "allow merging unrelated histories"
|
||||
)
|
||||
|
||||
-- Since prepMerge changes the working directory, FilePath options
|
||||
-- have to be adjusted.
|
||||
|
@ -196,6 +206,7 @@ instance DeferredParseClass SyncOptions where
|
|||
<*> pure (cleanupOption v)
|
||||
<*> pure (keyOptions v)
|
||||
<*> pure (resolveMergeOverride v)
|
||||
<*> pure (allowUnrelatedHistories v)
|
||||
|
||||
seek :: SyncOptions -> CommandSeek
|
||||
seek o = do
|
||||
|
@ -218,7 +229,7 @@ seek' o = do
|
|||
commandAction (withbranch cleanupLocal)
|
||||
mapM_ (commandAction . withbranch . cleanupRemote) gitremotes
|
||||
else do
|
||||
mc <- mergeConfig False
|
||||
mc <- mergeConfig (allowUnrelatedHistories o)
|
||||
|
||||
-- Syncing involves many actions, any of which
|
||||
-- can independently fail, without preventing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue