make assistant aware of adjusted branches when merging

This commit is contained in:
Joey Hess 2016-02-29 15:57:47 -04:00
parent c1d7a5b97c
commit 048d513233
Failed to extract signature
4 changed files with 30 additions and 23 deletions

View file

@ -120,6 +120,6 @@ commitAdjustedTree treesha parent = go =<< catCommit parent
{- Update the currently checked out adjusted branch, merging the provided
- branch into it. -}
updateAdjustedBranch :: Adjustment -> OrigBranch -> Branch -> Annex Bool
updateAdjustedBranch mergebranch = do
updateAdjustedBranch :: Branch -> (OrigBranch, Adjustment) -> Git.Branch.CommitMode -> Annex Bool
updateAdjustedBranch tomerge (origbranch, adj) commitmode = do
error "updateAdjustedBranch"

View file

@ -17,7 +17,7 @@ import Utility.DirWatcher.Types
import qualified Annex.Branch
import qualified Git
import qualified Git.Branch
import Annex.AutoMerge
import qualified Command.Sync
import Annex.TaggedPush
import Remote (remoteFromUUID)
@ -72,19 +72,21 @@ onChange file
unlessM handleDesynced $
queueDeferredDownloads "retrying deferred download" Later
| "/synced/" `isInfixOf` file =
mergecurrent =<< liftAnnex (inRepo Git.Branch.current)
mergecurrent =<< liftAnnex (join Command.Sync.getCurrBranch)
| otherwise = noop
where
changedbranch = fileToBranch file
mergecurrent (Just current)
| equivBranches changedbranch current =
whenM (liftAnnex $ inRepo $ Git.Branch.changed current changedbranch) $ do
mergecurrent currbranch@(Just b, _)
| equivBranches changedbranch b =
whenM (liftAnnex $ inRepo $ Git.Branch.changed b changedbranch) $ do
debug
[ "merging", Git.fromRef changedbranch
, "into", Git.fromRef current
, "into", Git.fromRef b
]
void $ liftAnnex $ autoMergeFrom changedbranch (Just current) Git.Branch.AutomaticCommit
void $ liftAnnex $ Command.Sync.merge
currbranch Git.Branch.AutomaticCommit
changedbranch
mergecurrent _ = noop
handleDesynced = case fromTaggedBranch changedbranch of

View file

@ -27,7 +27,6 @@ import Annex.TaggedPush
import Annex.CatFile
import Config
import Git
import qualified Git.Branch
import qualified Types.Remote as Remote
import qualified Remote as Remote
import Remote.List

View file

@ -10,6 +10,7 @@ module Command.Sync (
cmd,
CurrBranch,
getCurrBranch,
merge,
prepMerge,
mergeLocal,
mergeRemote,
@ -165,6 +166,12 @@ getCurrBranch = do
prepMerge :: Annex ()
prepMerge = Annex.changeDirectory =<< fromRepo Git.repoPath
merge :: CurrBranch -> Git.Branch.CommitMode -> Git.Branch -> Annex Bool
merge (Just b, Just adj) commitmode tomerge =
updateAdjustedBranch tomerge (b, adj) commitmode
merge (b, _) commitmode tomerge =
autoMergeFrom tomerge b commitmode
syncBranch :: Git.Ref -> Git.Ref
syncBranch = Git.Ref.under "refs/heads/synced" . fromDirectBranch
@ -236,8 +243,7 @@ commitStaged commitmode commitmessage = do
return True
mergeLocal :: CurrBranch -> CommandStart
mergeLocal (Nothing, _) = stop
mergeLocal (Just branch, madj) = go =<< needmerge
mergeLocal currbranch@(Just branch, _) = go =<< needmerge
where
syncbranch = syncBranch branch
needmerge = ifM isBareRepo
@ -250,9 +256,9 @@ mergeLocal (Just branch, madj) = go =<< needmerge
go False = stop
go True = do
showStart "merge" $ Git.Ref.describe syncbranch
next $ next $ case madj of
Nothing -> autoMergeFrom syncbranch (Just branch) Git.Branch.ManualCommit
Just adj -> updateAdjustedBranch adj branch syncbranch
next $ next $
merge currbranch Git.Branch.ManualCommit syncbranch
mergeLocal (Nothing, _) = stop
pushLocal :: CurrBranch -> CommandStart
pushLocal b = do
@ -298,19 +304,19 @@ pullRemote o remote branch = stopUnless (pure $ pullOption o) $ do
- while the synced/master may have changes that some
- other remote synced to this remote. So, merge them both. -}
mergeRemote :: Remote -> CurrBranch -> CommandCleanup
mergeRemote remote b = ifM isBareRepo
mergeRemote remote currbranch = ifM isBareRepo
( return True
, case b of
, case currbranch of
(Nothing, _) -> do
branch <- inRepo Git.Branch.currentUnsafe
and <$> mapM (merge Nothing Nothing) (branchlist branch)
(Just currbranch, madj) -> do
inRepo $ updateBranch $ syncBranch currbranch
and <$> (mapM (merge (Just currbranch) madj) =<< tomerge (branchlist (Just currbranch)))
mergelisted (pure (branchlist branch))
(Just branch, _) -> do
inRepo $ updateBranch $ syncBranch branch
mergelisted (tomerge (branchlist (Just branch)))
)
where
merge (Just origbranch) (Just adj) br = updateAdjustedBranch adj origbranch br
merge currbranch _ br = autoMergeFrom (remoteBranch remote br) currbranch Git.Branch.ManualCommit
mergelisted getlist = and <$>
(mapM (merge currbranch Git.Branch.ManualCommit) =<< getlist)
tomerge = filterM (changed remote)
branchlist Nothing = []
branchlist (Just branch) = [branch, syncBranch branch]