diff options
-rw-r--r-- | Assistant/Threads/Merger.hs | 43 | ||||
-rw-r--r-- | Git/Ref.hs | 1 |
2 files changed, 30 insertions, 14 deletions
diff --git a/Assistant/Threads/Merger.hs b/Assistant/Threads/Merger.hs index 9ed744808..56b0abb80 100644 --- a/Assistant/Threads/Merger.hs +++ b/Assistant/Threads/Merger.hs @@ -11,10 +11,10 @@ import Assistant.Common import Assistant.ThreadedMonad import Utility.DirWatcher import Utility.Types.DirWatcher +import qualified Annex.Branch import qualified Git import qualified Git.Merge import qualified Git.Branch -import qualified Command.Sync thisThread :: ThreadName thisThread = "Merger" @@ -67,16 +67,33 @@ onErr _ msg _ = error msg onAdd :: Handler onAdd g file _ | ".lock" `isSuffixOf` file = noop - | otherwise = do - let changedbranch = Git.Ref $ - "refs" </> "heads" </> takeFileName file - current <- Git.Branch.current g - when (Just changedbranch == current) $ do - liftIO $ debug thisThread - [ "merging changes into" - , show current - ] - void $ mergeBranch changedbranch g + | isAnnexBranch file = noop + | "/synced/" `isInfixOf` file = go =<< Git.Branch.current g + | otherwise = noop + where + changedbranch = fileToBranch file + go (Just current) + | equivBranches changedbranch current = do + liftIO $ debug thisThread + [ "merging" + , show changedbranch + , "into" + , show current + ] + void $ Git.Merge.mergeNonInteractive changedbranch g + go _ = noop + +equivBranches :: Git.Ref -> Git.Ref -> Bool +equivBranches x y = base x == base y + where + base = takeFileName . show -mergeBranch :: Git.Ref -> Git.Repo -> IO Bool -mergeBranch = Git.Merge.mergeNonInteractive . Command.Sync.syncBranch +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 diff --git a/Git/Ref.hs b/Git/Ref.hs index ee2f02187..021dbe6cc 100644 --- a/Git/Ref.hs +++ b/Git/Ref.hs @@ -26,7 +26,6 @@ base = Ref . remove "refs/heads/" . remove "refs/remotes/" . show | prefix `isPrefixOf` s = drop (length prefix) s | otherwise = s - {- 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, - such as refs/remotes/origin/master. -} |