make the merger merge any equivilant sync branch into the current branch

Not just synced/master, but synced/UUID/master, for example
This commit is contained in:
Joey Hess 2012-09-16 18:53:13 -04:00
parent 601ee470af
commit 6cddda4143
2 changed files with 30 additions and 14 deletions

View file

@ -11,10 +11,10 @@ import Assistant.Common
import Assistant.ThreadedMonad import Assistant.ThreadedMonad
import Utility.DirWatcher import Utility.DirWatcher
import Utility.Types.DirWatcher import Utility.Types.DirWatcher
import qualified Annex.Branch
import qualified Git import qualified Git
import qualified Git.Merge import qualified Git.Merge
import qualified Git.Branch import qualified Git.Branch
import qualified Command.Sync
thisThread :: ThreadName thisThread :: ThreadName
thisThread = "Merger" thisThread = "Merger"
@ -67,16 +67,33 @@ onErr _ msg _ = error msg
onAdd :: Handler onAdd :: Handler
onAdd g file _ onAdd g file _
| ".lock" `isSuffixOf` file = noop | ".lock" `isSuffixOf` file = noop
| otherwise = do | isAnnexBranch file = noop
let changedbranch = Git.Ref $ | "/synced/" `isInfixOf` file = go =<< Git.Branch.current g
"refs" </> "heads" </> takeFileName file | otherwise = noop
current <- Git.Branch.current g where
when (Just changedbranch == current) $ do changedbranch = fileToBranch file
liftIO $ debug thisThread go (Just current)
[ "merging changes into" | equivBranches changedbranch current = do
, show current liftIO $ debug thisThread
] [ "merging"
void $ mergeBranch changedbranch g , show changedbranch
, "into"
, show current
]
void $ Git.Merge.mergeNonInteractive changedbranch g
go _ = noop
mergeBranch :: Git.Ref -> Git.Repo -> IO Bool equivBranches :: Git.Ref -> Git.Ref -> Bool
mergeBranch = Git.Merge.mergeNonInteractive . Command.Sync.syncBranch equivBranches x y = base x == base y
where
base = takeFileName . show
isAnnexBranch :: FilePath -> Bool
isAnnexBranch f = n `isSuffixOf` f
where
n = "/" ++ show Annex.Branch.name
fileToBranch :: FilePath -> Git.Ref
fileToBranch f = Git.Ref $ "refs" </> "heads" </> base
where
base = Prelude.last $ split "/refs/heads/" f

View file

@ -26,7 +26,6 @@ base = Ref . remove "refs/heads/" . remove "refs/remotes/" . show
| prefix `isPrefixOf` s = drop (length prefix) s | prefix `isPrefixOf` s = drop (length prefix) s
| otherwise = s | otherwise = s
{- Given a directory such as "refs/remotes/origin", and a ref such as {- Given a directory such as "refs/remotes/origin", and a ref such as
- refs/heads/master, yields a version of that ref under the directory, - refs/heads/master, yields a version of that ref under the directory,
- such as refs/remotes/origin/master. -} - such as refs/remotes/origin/master. -}