From 11025aaa449495db399cd02cafc15cec5923281c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 20 Mar 2017 16:00:06 -0400 Subject: sync --content-of=path For when you want to sync only some files' contents, not the whole working tree. This commit was sponsored by Anthony DeRobertis on Patreon. --- Command/Sync.hs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'Command') diff --git a/Command/Sync.hs b/Command/Sync.hs index d4d45e2e4..f2c1945a7 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -63,7 +63,7 @@ cmd :: Command cmd = withGlobalOptions [jobsOption] $ command "sync" SectionCommon "synchronize local repository with remotes" - (paramRepeating paramRemote) (seek <$$> optParser) + (paramRepeating paramRemote) (seek <--< optParser) data SyncOptions = SyncOptions { syncWith :: CmdParams @@ -74,6 +74,7 @@ data SyncOptions = SyncOptions , pushOption :: Bool , contentOption :: Bool , noContentOption :: Bool + , contentOfOption :: [FilePath] , keyOptions :: Maybe KeyOptions } @@ -109,8 +110,29 @@ optParser desc = SyncOptions ( long "no-content" <> help "do not transfer file contents" ) + <*> many (strOption + ( long "content-of" + <> short 'C' + <> help "transfer file contents of files in a given location" + <> metavar paramPath + )) <*> optional parseAllOption +-- Since prepMerge changes the working directory, FilePath options +-- have to be adjusted. +instance DeferredParseClass SyncOptions where + finishParse v = SyncOptions + <$> pure (syncWith v) + <*> pure (commitOption v) + <*> pure (noCommitOption v) + <*> pure (messageOption v) + <*> pure (pullOption v) + <*> pure (pushOption v) + <*> pure (contentOption v) + <*> pure (noContentOption v) + <*> liftIO (mapM absPath (contentOfOption v)) + <*> pure (keyOptions v) + seek :: SyncOptions -> CommandSeek seek o = allowConcurrentOutput $ do prepMerge @@ -148,6 +170,7 @@ seek o = allowConcurrentOutput $ do mapM_ (commandAction . withbranch . pushRemote o) gitremotes where shouldsynccontent = pure (contentOption o) + <||> pure (not (null (contentOfOption o))) <||> (pure (not (noContentOption o)) <&&> getGitConfigVal annexSyncContent) type CurrBranch = (Maybe Git.Branch, Maybe Adjustment) @@ -510,7 +533,7 @@ seekSyncContent o rs = do mvar <- liftIO newEmptyMVar bloom <- case keyOptions o of Just WantAllKeys -> Just <$> genBloomFilter (seekworktree mvar []) - _ -> seekworktree mvar [] (const noop) >> pure Nothing + _ -> seekworktree mvar (contentOfOption o) (const noop) >> pure Nothing withKeyOptions' (keyOptions o) False (return (seekkeys mvar bloom)) (const noop) -- cgit v1.2.3