2011-12-10 00:27:22 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2011-12-30 20:24:30 +00:00
|
|
|
- Copyright 2011 Joachim Breitner <mail@joachim-breitner.de>
|
2017-02-17 19:21:39 +00:00
|
|
|
- Copyright 2011-2017 Joey Hess <id@joeyh.name>
|
2011-12-10 00:27:22 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2014-12-29 17:41:03 +00:00
|
|
|
module Command.Sync (
|
|
|
|
cmd,
|
2016-02-29 19:23:08 +00:00
|
|
|
CurrBranch,
|
|
|
|
getCurrBranch,
|
2016-04-22 18:35:48 +00:00
|
|
|
mergeConfig,
|
2016-02-29 19:57:47 +00:00
|
|
|
merge,
|
2014-12-29 17:41:03 +00:00
|
|
|
prepMerge,
|
|
|
|
mergeLocal,
|
|
|
|
mergeRemote,
|
|
|
|
commitStaged,
|
2015-02-11 17:33:55 +00:00
|
|
|
commitMsg,
|
2014-12-29 17:41:03 +00:00
|
|
|
pushBranch,
|
|
|
|
updateBranch,
|
|
|
|
syncBranch,
|
|
|
|
updateSyncBranch,
|
|
|
|
) where
|
2011-12-10 00:27:22 +00:00
|
|
|
|
|
|
|
import Command
|
2011-12-31 01:17:36 +00:00
|
|
|
import qualified Annex
|
2011-12-10 00:27:22 +00:00
|
|
|
import qualified Annex.Branch
|
2014-01-19 21:35:36 +00:00
|
|
|
import qualified Remote
|
|
|
|
import qualified Types.Remote as Remote
|
2012-12-12 23:20:38 +00:00
|
|
|
import Annex.Direct
|
2014-03-02 22:01:07 +00:00
|
|
|
import Annex.Hook
|
2011-12-14 19:56:11 +00:00
|
|
|
import qualified Git.Command
|
2012-06-27 17:08:32 +00:00
|
|
|
import qualified Git.LsFiles as LsFiles
|
2011-12-30 22:04:01 +00:00
|
|
|
import qualified Git.Branch
|
2016-04-22 18:26:44 +00:00
|
|
|
import qualified Git.Merge
|
2015-01-07 02:23:04 +00:00
|
|
|
import qualified Git.Types as Git
|
2011-12-15 22:11:42 +00:00
|
|
|
import qualified Git.Ref
|
|
|
|
import qualified Git
|
2011-12-31 07:27:37 +00:00
|
|
|
import qualified Remote.Git
|
2012-10-11 22:39:21 +00:00
|
|
|
import Config
|
2017-02-03 17:40:14 +00:00
|
|
|
import Config.GitConfig
|
2017-02-17 19:21:39 +00:00
|
|
|
import Config.Files
|
2014-01-19 21:35:36 +00:00
|
|
|
import Annex.Wanted
|
|
|
|
import Annex.Content
|
Do verification of checksums of annex objects downloaded from remotes.
* When annex objects are received into git repositories, their checksums are
verified then too.
* To get the old, faster, behavior of not verifying checksums, set
annex.verify=false, or remote.<name>.annex-verify=false.
* setkey, rekey: These commands also now verify that the provided file
matches the key, unless annex.verify=false.
* reinject: Already verified content; this can now be disabled by
setting annex.verify=false.
recvkey and reinject already did verification, so removed now duplicate
code from them. fsck still does its own verification, which is ok since it
does not use getViaTmp, so verification doesn't happen twice when using fsck
--from.
2015-10-01 19:54:37 +00:00
|
|
|
import Command.Get (getKey')
|
2014-02-02 23:57:22 +00:00
|
|
|
import qualified Command.Move
|
2014-01-19 21:35:36 +00:00
|
|
|
import Annex.Drop
|
2014-02-03 02:46:55 +00:00
|
|
|
import Annex.UUID
|
2015-02-11 17:33:55 +00:00
|
|
|
import Logs.UUID
|
2014-03-04 20:26:15 +00:00
|
|
|
import Annex.AutoMerge
|
2016-02-29 19:23:08 +00:00
|
|
|
import Annex.AdjustedBranch
|
2014-04-12 19:59:34 +00:00
|
|
|
import Annex.Ssh
|
2015-06-16 22:38:12 +00:00
|
|
|
import Annex.BloomFilter
|
2017-02-17 19:21:39 +00:00
|
|
|
import Annex.UpdateInstead
|
2015-06-16 21:58:15 +00:00
|
|
|
import Utility.Bloom
|
2015-08-20 21:18:21 +00:00
|
|
|
import Utility.OptParse
|
2011-12-10 00:27:22 +00:00
|
|
|
|
2013-10-17 17:34:27 +00:00
|
|
|
import Control.Concurrent.MVar
|
2015-02-11 17:33:55 +00:00
|
|
|
import qualified Data.Map as M
|
2011-12-10 00:27:22 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-08-14 17:49:55 +00:00
|
|
|
cmd = withGlobalOptions [jobsOption] $
|
|
|
|
command "sync" SectionCommon
|
|
|
|
"synchronize local repository with remotes"
|
2017-03-20 20:00:06 +00:00
|
|
|
(paramRepeating paramRemote) (seek <--< optParser)
|
2015-07-09 23:03:21 +00:00
|
|
|
|
|
|
|
data SyncOptions = SyncOptions
|
|
|
|
{ syncWith :: CmdParams
|
2015-09-13 17:15:35 +00:00
|
|
|
, commitOption :: Bool
|
2017-02-03 18:36:14 +00:00
|
|
|
, noCommitOption :: Bool
|
2015-07-09 23:03:21 +00:00
|
|
|
, messageOption :: Maybe String
|
2015-09-13 17:15:35 +00:00
|
|
|
, pullOption :: Bool
|
|
|
|
, pushOption :: Bool
|
|
|
|
, contentOption :: Bool
|
2017-02-03 18:31:17 +00:00
|
|
|
, noContentOption :: Bool
|
2017-03-20 20:00:06 +00:00
|
|
|
, contentOfOption :: [FilePath]
|
2015-07-09 23:03:21 +00:00
|
|
|
, keyOptions :: Maybe KeyOptions
|
2017-06-01 16:46:36 +00:00
|
|
|
, resolveMergeOverride :: ResolveMergeOverride
|
2015-07-09 23:03:21 +00:00
|
|
|
}
|
|
|
|
|
2017-06-01 16:46:36 +00:00
|
|
|
newtype ResolveMergeOverride = ResolveMergeOverride Bool
|
|
|
|
|
|
|
|
instance Default ResolveMergeOverride where
|
|
|
|
def = ResolveMergeOverride False
|
|
|
|
|
2015-07-09 23:03:21 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser SyncOptions
|
|
|
|
optParser desc = SyncOptions
|
2015-09-14 17:19:04 +00:00
|
|
|
<$> (many $ argument str
|
|
|
|
( metavar desc
|
|
|
|
<> completeRemotes
|
|
|
|
))
|
2017-02-03 18:36:14 +00:00
|
|
|
<*> switch
|
|
|
|
( long "commit"
|
|
|
|
<> help "commit changes to git"
|
|
|
|
)
|
|
|
|
<*> switch
|
|
|
|
( long "no-commit"
|
|
|
|
<> help "avoid git commit"
|
2015-07-09 23:03:21 +00:00
|
|
|
)
|
|
|
|
<*> optional (strOption
|
|
|
|
( long "message" <> short 'm' <> metavar "MSG"
|
|
|
|
<> help "commit message"
|
|
|
|
))
|
2015-09-13 17:15:35 +00:00
|
|
|
<*> invertableSwitch "pull" True
|
|
|
|
( help "avoid git pulls from remotes"
|
|
|
|
)
|
|
|
|
<*> invertableSwitch "push" True
|
|
|
|
( help "avoid git pushes to remotes"
|
|
|
|
)
|
2017-02-03 18:31:17 +00:00
|
|
|
<*> switch
|
|
|
|
( long "content"
|
|
|
|
<> help "transfer file contents"
|
|
|
|
)
|
|
|
|
<*> switch
|
|
|
|
( long "no-content"
|
|
|
|
<> help "do not transfer file contents"
|
2015-09-13 17:15:35 +00:00
|
|
|
)
|
2017-03-20 20:00:06 +00:00
|
|
|
<*> many (strOption
|
|
|
|
( long "content-of"
|
|
|
|
<> short 'C'
|
|
|
|
<> help "transfer file contents of files in a given location"
|
|
|
|
<> metavar paramPath
|
|
|
|
))
|
2015-07-09 23:03:21 +00:00
|
|
|
<*> optional parseAllOption
|
2017-06-01 16:46:36 +00:00
|
|
|
<*> (ResolveMergeOverride <$> invertableSwitch "resolvemerge" True
|
|
|
|
( help "do not automatically resolve merge conflicts"
|
|
|
|
))
|
2015-07-09 23:03:21 +00:00
|
|
|
|
2017-03-20 20:00:06 +00:00
|
|
|
-- 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)
|
2017-06-01 16:46:36 +00:00
|
|
|
<*> pure (resolveMergeOverride v)
|
2017-03-20 20:00:06 +00:00
|
|
|
|
2015-07-09 23:03:21 +00:00
|
|
|
seek :: SyncOptions -> CommandSeek
|
2015-11-04 20:19:00 +00:00
|
|
|
seek o = allowConcurrentOutput $ do
|
2013-09-13 18:55:55 +00:00
|
|
|
prepMerge
|
2013-10-17 17:34:27 +00:00
|
|
|
|
2016-02-29 19:23:08 +00:00
|
|
|
getbranch <- getCurrBranch
|
2013-10-17 17:34:27 +00:00
|
|
|
let withbranch a = a =<< getbranch
|
|
|
|
|
2015-07-09 23:03:21 +00:00
|
|
|
remotes <- syncRemotes (syncWith o)
|
2014-01-19 21:35:36 +00:00
|
|
|
let gitremotes = filter Remote.gitSyncableRemote remotes
|
2016-06-02 17:50:05 +00:00
|
|
|
let dataremotes = filter (\r -> Remote.uuid r /= NoUUID) $
|
|
|
|
filter (not . remoteAnnexIgnore . Remote.gitconfig) remotes
|
2014-01-19 21:35:36 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
-- Syncing involves many actions, any of which can independently
|
|
|
|
-- fail, without preventing the others from running.
|
2015-08-14 17:49:55 +00:00
|
|
|
-- These actions cannot be run concurrently.
|
|
|
|
mapM_ includeCommandAction $ concat
|
2015-07-09 23:03:21 +00:00
|
|
|
[ [ commit o ]
|
2017-06-01 16:46:36 +00:00
|
|
|
, [ withbranch (mergeLocal mergeConfig (resolveMergeOverride o)) ]
|
2016-04-22 18:35:48 +00:00
|
|
|
, map (withbranch . pullRemote o mergeConfig) gitremotes
|
2014-01-20 17:31:03 +00:00
|
|
|
, [ mergeAnnex ]
|
|
|
|
]
|
2017-02-03 18:31:17 +00:00
|
|
|
whenM (shouldsynccontent <&&> seekSyncContent o dataremotes) $
|
|
|
|
-- Transferring content can take a while,
|
|
|
|
-- and other changes can be pushed to the git-annex
|
|
|
|
-- branch on the remotes in the meantime, so pull
|
|
|
|
-- and merge again to avoid our push overwriting
|
|
|
|
-- those changes.
|
|
|
|
mapM_ includeCommandAction $ concat
|
|
|
|
[ map (withbranch . pullRemote o mergeConfig) gitremotes
|
|
|
|
, [ commitAnnex, mergeAnnex ]
|
|
|
|
]
|
2015-08-14 17:49:55 +00:00
|
|
|
|
|
|
|
void $ includeCommandAction $ withbranch pushLocal
|
|
|
|
-- Pushes to remotes can run concurrently.
|
2015-09-13 17:15:35 +00:00
|
|
|
mapM_ (commandAction . withbranch . pushRemote o) gitremotes
|
2017-02-03 18:31:17 +00:00
|
|
|
where
|
|
|
|
shouldsynccontent = pure (contentOption o)
|
2017-03-20 20:00:06 +00:00
|
|
|
<||> pure (not (null (contentOfOption o)))
|
2017-02-03 18:31:17 +00:00
|
|
|
<||> (pure (not (noContentOption o)) <&&> getGitConfigVal annexSyncContent)
|
|
|
|
|
2016-02-29 19:23:08 +00:00
|
|
|
type CurrBranch = (Maybe Git.Branch, Maybe Adjustment)
|
|
|
|
|
|
|
|
{- There may not be a branch checked out until after the commit,
|
|
|
|
- or perhaps after it gets merged from the remote, or perhaps
|
|
|
|
- never.
|
|
|
|
-
|
|
|
|
- So only look it up once it's needed, and once there is a
|
|
|
|
- branch, cache it.
|
|
|
|
-
|
|
|
|
- When on an adjusted branch, gets the original branch, and the adjustment.
|
|
|
|
-}
|
|
|
|
getCurrBranch :: Annex (Annex CurrBranch)
|
|
|
|
getCurrBranch = do
|
|
|
|
mvar <- liftIO newEmptyMVar
|
|
|
|
return $ ifM (liftIO $ isEmptyMVar mvar)
|
|
|
|
( do
|
|
|
|
currbranch <- inRepo Git.Branch.current
|
|
|
|
case currbranch of
|
|
|
|
Nothing -> return (Nothing, Nothing)
|
|
|
|
Just b -> do
|
|
|
|
let v = case adjustedToOriginal b of
|
|
|
|
Nothing -> (Just b, Nothing)
|
|
|
|
Just (adj, origbranch) ->
|
|
|
|
(Just origbranch, Just adj)
|
|
|
|
liftIO $ putMVar mvar v
|
|
|
|
return v
|
|
|
|
, liftIO $ readMVar mvar
|
|
|
|
)
|
|
|
|
|
2013-09-13 18:55:55 +00:00
|
|
|
{- Merging may delete the current directory, so go to the top
|
2014-01-19 21:35:36 +00:00
|
|
|
- of the repo. This also means that sync always acts on all files in the
|
|
|
|
- repository, not just on a subdirectory. -}
|
2013-09-13 18:55:55 +00:00
|
|
|
prepMerge :: Annex ()
|
2015-01-07 02:23:04 +00:00
|
|
|
prepMerge = Annex.changeDirectory =<< fromRepo Git.repoPath
|
2013-09-13 18:55:55 +00:00
|
|
|
|
2016-04-22 18:35:48 +00:00
|
|
|
mergeConfig :: [Git.Merge.MergeConfig]
|
2016-11-15 22:26:17 +00:00
|
|
|
mergeConfig =
|
|
|
|
[ Git.Merge.MergeNonInteractive
|
|
|
|
-- In several situations, unrelated histories should be merged
|
2016-11-16 20:03:23 +00:00
|
|
|
-- together. This includes pairing in the assistant, and merging
|
|
|
|
-- from a remote into a newly created direct mode repo.
|
|
|
|
-- (Once direct mode is removed, this could be changed, so only
|
|
|
|
-- the assistant uses it.)
|
2016-11-15 22:26:17 +00:00
|
|
|
, Git.Merge.MergeUnrelatedHistories
|
|
|
|
]
|
2016-04-22 18:35:48 +00:00
|
|
|
|
2017-06-01 16:46:36 +00:00
|
|
|
merge :: CurrBranch -> [Git.Merge.MergeConfig] -> ResolveMergeOverride -> Git.Branch.CommitMode -> Git.Branch -> Annex Bool
|
|
|
|
merge currbranch mergeconfig resolvemergeoverride commitmode tomerge = case currbranch of
|
|
|
|
(Just b, Just adj) -> updateAdjustedBranch tomerge (b, adj) mergeconfig canresolvemerge commitmode
|
|
|
|
(b, _) -> autoMergeFrom tomerge b mergeconfig canresolvemerge commitmode
|
|
|
|
where
|
|
|
|
canresolvemerge = case resolvemergeoverride of
|
|
|
|
ResolveMergeOverride True -> getGitConfigVal annexResolveMerge
|
|
|
|
ResolveMergeOverride False -> return False
|
2016-02-29 19:57:47 +00:00
|
|
|
|
2016-03-03 18:13:54 +00:00
|
|
|
syncBranch :: Git.Branch -> Git.Branch
|
fix bugs in handing of deep branches with sync and adjusted branches
* sync: Previously, when run in a branch with a slash in its name,
such as "foo/bar", the sync branch was "synced/bar". That conflicted
with the sync branch used for branch "bar", so has been changed to
"synced/foo/bar".
* adjust: Previously, when adjusting a branch with a slash in its name,
such as "foo/bar", the adjusted branch was "adjusted/bar(unlocked)".
That conflicted with the adjusted branch used for branch "bar",
so has been changed to "adjusted/foo/bar(unlocked)"
* Also, running sync in an adjusted branch did not correctly sync
changes back to the parent branch when it had a slash in its name.
This bug has been fixed.
Eliminate use of Git.Ref.under and Git.Ref.basename; using
Git.Ref.underBase and Git.Ref.base make everything handle deep branches
correctly.
Probably noone was adjusting deep branches, and v6 is still experimental
anyway, so I'm not going to worry about the mess that was left by that bug.
In the case of git-annex sync, using a fixed git-annex with an old unfixed
one will mean they use different sync branches for a deep branch, and so
they may stop syncing until the old one is upgraded. However, that's only
a problem when syncing between repositories without going via a central
bare repository. Added a warning about this to the CHANGELOG, but it's
probably not going to affect many people at all.
This commit was sponsored by Riku Voipio.
2016-09-21 19:18:51 +00:00
|
|
|
syncBranch = Git.Ref.underBase "refs/heads/synced" . fromDirectBranch . fromAdjustedBranch
|
2011-12-29 17:37:30 +00:00
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
remoteBranch :: Remote -> Git.Ref -> Git.Ref
|
work around lack of receive.denyCurrentBranch in direct mode
Now that direct mode sets core.bare=true, git's normal prohibition about
pushing into the currently checked out branch doesn't work.
A simple fix for this would be an update hook which blocks the pushes..
but git hooks must be executable, and git-annex needs to be usable on eg,
FAT, which lacks x bits.
Instead, enabling direct mode switches the branch (eg master) to a special
purpose branch (eg annex/direct/master). This branch is not pushed when
syncing; instead any changes that git annex sync commits get written to
master, and it's pushed (along with synced/master) to the remote.
Note that initialization has been changed to always call setDirect,
even if it's just setDirect False for indirect mode. This is needed because
if the user has just cloned a direct mode repo, that nothing has synced
with before, it may have no master branch, and only a annex/direct/master.
Resulting in that branch being checked out locally too. Calling setDirect False
for indirect mode moves back out of this branch, to a new master branch,
and ensures that a manual "git push" doesn't push changes directly to
the annex/direct/master of the remote. (It's possible that the user
makes a commit w/o using git-annex and pushes it, but nothing I can do
about that really.)
This commit was sponsored by Jonathan Harrington.
2013-11-06 01:08:31 +00:00
|
|
|
remoteBranch remote = Git.Ref.underBase $ "refs/remotes/" ++ Remote.name remote
|
2011-12-31 07:01:18 +00:00
|
|
|
|
2015-10-15 19:10:14 +00:00
|
|
|
-- Do automatic initialization of remotes when possible when getting remote
|
|
|
|
-- list.
|
2011-12-31 08:11:39 +00:00
|
|
|
syncRemotes :: [String] -> Annex [Remote]
|
2015-10-15 19:10:14 +00:00
|
|
|
syncRemotes ps = syncRemotes' ps =<< Remote.remoteList' True
|
2015-08-05 17:49:54 +00:00
|
|
|
|
|
|
|
syncRemotes' :: [String] -> [Remote] -> Annex [Remote]
|
|
|
|
syncRemotes' ps remotelist = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2015-08-05 17:49:54 +00:00
|
|
|
pickfast = (++) <$> listed <*> (filterM good (fastest available))
|
2014-12-29 17:41:03 +00:00
|
|
|
|
2012-11-12 05:05:04 +00:00
|
|
|
wanted
|
2015-08-05 17:49:54 +00:00
|
|
|
| null ps = filterM good (concat $ Remote.byCost available)
|
2012-11-12 05:05:04 +00:00
|
|
|
| otherwise = listed
|
2014-12-29 17:41:03 +00:00
|
|
|
|
2015-08-05 17:49:54 +00:00
|
|
|
listed = concat <$> mapM Remote.byNameOrGroup ps
|
2014-12-29 17:41:03 +00:00
|
|
|
|
2014-04-12 19:59:34 +00:00
|
|
|
available = filter (remoteAnnexSync . Remote.gitconfig)
|
2015-08-05 17:49:54 +00:00
|
|
|
$ filter (not . Remote.isXMPPRemote) remotelist
|
2014-12-29 17:41:03 +00:00
|
|
|
|
2014-01-19 21:35:36 +00:00
|
|
|
good r
|
2014-04-12 19:59:34 +00:00
|
|
|
| Remote.gitSyncableRemote r = Remote.Git.repoAvail $ Remote.repo r
|
2014-01-19 21:35:36 +00:00
|
|
|
| otherwise = return True
|
2014-12-29 17:41:03 +00:00
|
|
|
|
2012-11-12 05:05:04 +00:00
|
|
|
fastest = fromMaybe [] . headMaybe . Remote.byCost
|
2011-12-10 00:27:22 +00:00
|
|
|
|
2015-07-09 23:03:21 +00:00
|
|
|
commit :: SyncOptions -> CommandStart
|
2015-09-13 17:15:35 +00:00
|
|
|
commit o = stopUnless shouldcommit $ next $ next $ do
|
|
|
|
commitmessage <- maybe commitMsg return (messageOption o)
|
|
|
|
showStart "commit" ""
|
|
|
|
Annex.Branch.commit "update"
|
|
|
|
ifM isDirect
|
|
|
|
( do
|
|
|
|
void stageDirect
|
|
|
|
void preCommitDirect
|
|
|
|
commitStaged Git.Branch.ManualCommit commitmessage
|
|
|
|
, do
|
2016-04-05 20:22:21 +00:00
|
|
|
showOutput
|
|
|
|
void $ inRepo $ Git.Branch.commitCommand Git.Branch.ManualCommit
|
2015-09-13 17:15:35 +00:00
|
|
|
[ Param "-a"
|
|
|
|
, Param "-m"
|
|
|
|
, Param commitmessage
|
|
|
|
]
|
|
|
|
return True
|
|
|
|
)
|
2015-07-07 20:36:11 +00:00
|
|
|
where
|
2015-09-13 17:15:35 +00:00
|
|
|
shouldcommit = pure (commitOption o)
|
2017-02-03 18:36:14 +00:00
|
|
|
<||> (pure (not (noCommitOption o)) <&&> getGitConfigVal annexAutoCommit)
|
2013-12-01 17:59:39 +00:00
|
|
|
|
2015-02-11 17:33:55 +00:00
|
|
|
commitMsg :: Annex String
|
|
|
|
commitMsg = do
|
|
|
|
u <- getUUID
|
|
|
|
m <- uuidMap
|
|
|
|
return $ "git-annex in " ++ fromMaybe "unknown" (M.lookup u m)
|
|
|
|
|
2014-07-04 15:36:59 +00:00
|
|
|
commitStaged :: Git.Branch.CommitMode -> String -> Annex Bool
|
2015-03-04 19:25:13 +00:00
|
|
|
commitStaged commitmode commitmessage = do
|
|
|
|
runAnnexHook preCommitAnnexHook
|
|
|
|
mb <- inRepo Git.Branch.currentUnsafe
|
|
|
|
let (getparent, branch) = case mb of
|
|
|
|
Just b -> (Git.Ref.sha b, b)
|
|
|
|
Nothing -> (Git.Ref.headSha, Git.Ref.headRef)
|
|
|
|
parents <- maybeToList <$> inRepo getparent
|
|
|
|
void $ inRepo $ Git.Branch.commit commitmode False commitmessage branch parents
|
|
|
|
return True
|
2011-12-10 16:21:22 +00:00
|
|
|
|
2017-06-01 16:46:36 +00:00
|
|
|
mergeLocal :: [Git.Merge.MergeConfig] -> ResolveMergeOverride -> CurrBranch -> CommandStart
|
|
|
|
mergeLocal mergeconfig resolvemergeoverride currbranch@(Just _, _) =
|
2017-02-14 19:58:05 +00:00
|
|
|
go =<< needMerge currbranch
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2017-02-14 19:58:05 +00:00
|
|
|
go Nothing = stop
|
|
|
|
go (Just syncbranch) = do
|
2012-11-12 05:05:04 +00:00
|
|
|
showStart "merge" $ Git.Ref.describe syncbranch
|
2017-06-01 16:46:36 +00:00
|
|
|
next $ next $ merge currbranch mergeconfig resolvemergeoverride Git.Branch.ManualCommit syncbranch
|
|
|
|
mergeLocal _ _ (Nothing, madj) = do
|
2017-02-14 19:58:05 +00:00
|
|
|
b <- inRepo Git.Branch.currentUnsafe
|
2017-02-15 17:55:06 +00:00
|
|
|
ifM (isJust <$> needMerge (b, madj))
|
2017-02-14 19:58:05 +00:00
|
|
|
( do
|
|
|
|
warning $ "There are no commits yet in the currently checked out branch, so cannot merge any remote changes into it."
|
|
|
|
next $ next $ return False
|
|
|
|
, stop
|
|
|
|
)
|
|
|
|
|
|
|
|
-- Returns the branch that should be merged, if any.
|
|
|
|
needMerge :: CurrBranch -> Annex (Maybe Git.Branch)
|
|
|
|
needMerge (Nothing, _) = return Nothing
|
2017-02-15 17:55:06 +00:00
|
|
|
needMerge (Just branch, madj) = ifM (allM id checks)
|
2017-02-14 19:58:05 +00:00
|
|
|
( return (Just syncbranch)
|
|
|
|
, return Nothing
|
|
|
|
)
|
|
|
|
where
|
|
|
|
checks =
|
|
|
|
[ not <$> isBareRepo
|
|
|
|
, inRepo (Git.Ref.exists syncbranch)
|
|
|
|
, inRepo (Git.Branch.changed branch' syncbranch)
|
|
|
|
]
|
|
|
|
syncbranch = syncBranch branch
|
2016-04-09 19:10:26 +00:00
|
|
|
branch' = maybe branch (adjBranch . originalToAdjusted branch) madj
|
2011-12-29 17:37:30 +00:00
|
|
|
|
2016-02-29 19:23:08 +00:00
|
|
|
pushLocal :: CurrBranch -> CommandStart
|
2014-06-16 15:32:13 +00:00
|
|
|
pushLocal b = do
|
|
|
|
updateSyncBranch b
|
|
|
|
stop
|
|
|
|
|
2016-02-29 19:23:08 +00:00
|
|
|
updateSyncBranch :: CurrBranch -> Annex ()
|
|
|
|
updateSyncBranch (Nothing, _) = noop
|
2016-03-31 22:54:35 +00:00
|
|
|
updateSyncBranch (Just branch, madj) = do
|
|
|
|
-- When in an adjusted branch, propigate any changes made to it
|
|
|
|
-- back to the original branch.
|
2016-04-09 19:10:26 +00:00
|
|
|
maybe noop (propigateAdjustedCommits branch) madj
|
work around lack of receive.denyCurrentBranch in direct mode
Now that direct mode sets core.bare=true, git's normal prohibition about
pushing into the currently checked out branch doesn't work.
A simple fix for this would be an update hook which blocks the pushes..
but git hooks must be executable, and git-annex needs to be usable on eg,
FAT, which lacks x bits.
Instead, enabling direct mode switches the branch (eg master) to a special
purpose branch (eg annex/direct/master). This branch is not pushed when
syncing; instead any changes that git annex sync commits get written to
master, and it's pushed (along with synced/master) to the remote.
Note that initialization has been changed to always call setDirect,
even if it's just setDirect False for indirect mode. This is needed because
if the user has just cloned a direct mode repo, that nothing has synced
with before, it may have no master branch, and only a annex/direct/master.
Resulting in that branch being checked out locally too. Calling setDirect False
for indirect mode moves back out of this branch, to a new master branch,
and ensures that a manual "git push" doesn't push changes directly to
the annex/direct/master of the remote. (It's possible that the user
makes a commit w/o using git-annex and pushes it, but nothing I can do
about that really.)
This commit was sponsored by Jonathan Harrington.
2013-11-06 01:08:31 +00:00
|
|
|
-- Update the sync branch to match the new state of the branch
|
2016-03-03 20:19:09 +00:00
|
|
|
inRepo $ updateBranch (syncBranch branch) branch
|
work around lack of receive.denyCurrentBranch in direct mode
Now that direct mode sets core.bare=true, git's normal prohibition about
pushing into the currently checked out branch doesn't work.
A simple fix for this would be an update hook which blocks the pushes..
but git hooks must be executable, and git-annex needs to be usable on eg,
FAT, which lacks x bits.
Instead, enabling direct mode switches the branch (eg master) to a special
purpose branch (eg annex/direct/master). This branch is not pushed when
syncing; instead any changes that git annex sync commits get written to
master, and it's pushed (along with synced/master) to the remote.
Note that initialization has been changed to always call setDirect,
even if it's just setDirect False for indirect mode. This is needed because
if the user has just cloned a direct mode repo, that nothing has synced
with before, it may have no master branch, and only a annex/direct/master.
Resulting in that branch being checked out locally too. Calling setDirect False
for indirect mode moves back out of this branch, to a new master branch,
and ensures that a manual "git push" doesn't push changes directly to
the annex/direct/master of the remote. (It's possible that the user
makes a commit w/o using git-annex and pushes it, but nothing I can do
about that really.)
This commit was sponsored by Jonathan Harrington.
2013-11-06 01:08:31 +00:00
|
|
|
-- In direct mode, we're operating on some special direct mode
|
2016-02-29 20:57:42 +00:00
|
|
|
-- branch, rather than the intended branch, so update the intended
|
work around lack of receive.denyCurrentBranch in direct mode
Now that direct mode sets core.bare=true, git's normal prohibition about
pushing into the currently checked out branch doesn't work.
A simple fix for this would be an update hook which blocks the pushes..
but git hooks must be executable, and git-annex needs to be usable on eg,
FAT, which lacks x bits.
Instead, enabling direct mode switches the branch (eg master) to a special
purpose branch (eg annex/direct/master). This branch is not pushed when
syncing; instead any changes that git annex sync commits get written to
master, and it's pushed (along with synced/master) to the remote.
Note that initialization has been changed to always call setDirect,
even if it's just setDirect False for indirect mode. This is needed because
if the user has just cloned a direct mode repo, that nothing has synced
with before, it may have no master branch, and only a annex/direct/master.
Resulting in that branch being checked out locally too. Calling setDirect False
for indirect mode moves back out of this branch, to a new master branch,
and ensures that a manual "git push" doesn't push changes directly to
the annex/direct/master of the remote. (It's possible that the user
makes a commit w/o using git-annex and pushes it, but nothing I can do
about that really.)
This commit was sponsored by Jonathan Harrington.
2013-11-06 01:08:31 +00:00
|
|
|
-- branch.
|
|
|
|
whenM isDirect $
|
2016-03-03 20:19:09 +00:00
|
|
|
inRepo $ updateBranch (fromDirectBranch branch) branch
|
2011-12-30 22:52:24 +00:00
|
|
|
|
2016-02-29 20:57:42 +00:00
|
|
|
updateBranch :: Git.Branch -> Git.Branch -> Git.Repo -> IO ()
|
|
|
|
updateBranch syncbranch updateto g =
|
2016-11-16 01:29:54 +00:00
|
|
|
unlessM go $ giveup $ "failed to update " ++ Git.fromRef syncbranch
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2013-03-03 17:39:07 +00:00
|
|
|
go = Git.Command.runBool
|
|
|
|
[ Param "branch"
|
|
|
|
, Param "-f"
|
2014-02-19 05:09:17 +00:00
|
|
|
, Param $ Git.fromRef $ Git.Ref.base syncbranch
|
2016-02-29 20:57:42 +00:00
|
|
|
, Param $ Git.fromRef $ updateto
|
2012-11-12 05:05:04 +00:00
|
|
|
] g
|
2011-12-30 21:38:38 +00:00
|
|
|
|
2016-04-22 18:26:44 +00:00
|
|
|
pullRemote :: SyncOptions -> [Git.Merge.MergeConfig] -> Remote -> CurrBranch -> CommandStart
|
Added remote.<name>.annex-push and remote.<name>.annex-pull
The former can be useful to make remotes that don't get fully synced with
local changes, which comes up in a lot of situations.
The latter was mostly added for symmetry, but could be useful (though less
likely to be).
Implementing `remote.<name>.annex-pull` was a bit tricky, as there's no one
place where git-annex pulls/fetches from remotes. I audited all
instances of "fetch" and "pull". A few cases were left not checking this
config:
* Git.Repair can try to pull missing refs from a remote, and if the local
repo is corrupted, that seems a reasonable thing to do even though
the config would normally prevent it.
* Assistant.WebApp.Gpg and Remote.Gcrypt and Remote.Git do fetches
as part of the setup process of a remote. The config would probably not
be set then, and having the setup fail seems worse than honoring it if it
is already set.
I have not prevented all the code that does a "merge" from merging branches
from remotes with remote.<name>.annex-pull=false. That could perhaps
be done, but it would need a way to map from branch name to remote name,
and the way refspecs work makes that hard to get really correct. So if the
user fetches manually, the git-annex branch will get merged, for example.
Anther way of looking at/justifying this is that the setting is called
"annex-pull", not "annex-merge".
This commit was supported by the NSF-funded DataLad project.
2017-04-05 17:04:02 +00:00
|
|
|
pullRemote o mergeconfig remote branch = stopUnless (pure $ pullOption o && wantpull) $ do
|
2011-12-30 22:04:01 +00:00
|
|
|
showStart "pull" (Remote.name remote)
|
2011-12-30 21:38:38 +00:00
|
|
|
next $ do
|
|
|
|
showOutput
|
2012-03-14 21:43:34 +00:00
|
|
|
stopUnless fetch $
|
2017-06-01 16:46:36 +00:00
|
|
|
next $ mergeRemote remote branch mergeconfig (resolveMergeOverride o)
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2015-02-12 20:12:32 +00:00
|
|
|
fetch = inRepoWithSshOptionsTo (Remote.repo remote) (Remote.gitconfig remote) $
|
|
|
|
Git.Command.runBool
|
|
|
|
[Param "fetch", Param $ Remote.name remote]
|
Added remote.<name>.annex-push and remote.<name>.annex-pull
The former can be useful to make remotes that don't get fully synced with
local changes, which comes up in a lot of situations.
The latter was mostly added for symmetry, but could be useful (though less
likely to be).
Implementing `remote.<name>.annex-pull` was a bit tricky, as there's no one
place where git-annex pulls/fetches from remotes. I audited all
instances of "fetch" and "pull". A few cases were left not checking this
config:
* Git.Repair can try to pull missing refs from a remote, and if the local
repo is corrupted, that seems a reasonable thing to do even though
the config would normally prevent it.
* Assistant.WebApp.Gpg and Remote.Gcrypt and Remote.Git do fetches
as part of the setup process of a remote. The config would probably not
be set then, and having the setup fail seems worse than honoring it if it
is already set.
I have not prevented all the code that does a "merge" from merging branches
from remotes with remote.<name>.annex-pull=false. That could perhaps
be done, but it would need a way to map from branch name to remote name,
and the way refspecs work makes that hard to get really correct. So if the
user fetches manually, the git-annex branch will get merged, for example.
Anther way of looking at/justifying this is that the setting is called
"annex-pull", not "annex-merge".
This commit was supported by the NSF-funded DataLad project.
2017-04-05 17:04:02 +00:00
|
|
|
wantpull = remoteAnnexPull (Remote.gitconfig remote)
|
2011-12-10 00:27:22 +00:00
|
|
|
|
2011-12-30 23:11:22 +00:00
|
|
|
{- The remote probably has both a master and a synced/master branch.
|
|
|
|
- Which to merge from? Well, the master has whatever latest changes
|
2013-06-12 18:54:23 +00:00
|
|
|
- were committed (or pushed changes, if this is a bare remote),
|
|
|
|
- while the synced/master may have changes that some
|
2012-12-12 17:06:03 +00:00
|
|
|
- other remote synced to this remote. So, merge them both. -}
|
2017-06-01 16:46:36 +00:00
|
|
|
mergeRemote :: Remote -> CurrBranch -> [Git.Merge.MergeConfig] -> ResolveMergeOverride -> CommandCleanup
|
|
|
|
mergeRemote remote currbranch mergeconfig resolvemergeoverride = ifM isBareRepo
|
2015-01-05 17:40:49 +00:00
|
|
|
( return True
|
2016-02-29 19:57:47 +00:00
|
|
|
, case currbranch of
|
2016-02-29 19:23:08 +00:00
|
|
|
(Nothing, _) -> do
|
2015-01-05 17:40:49 +00:00
|
|
|
branch <- inRepo Git.Branch.currentUnsafe
|
2016-02-29 19:57:47 +00:00
|
|
|
mergelisted (pure (branchlist branch))
|
|
|
|
(Just branch, _) -> do
|
2016-02-29 20:57:42 +00:00
|
|
|
inRepo $ updateBranch (syncBranch branch) branch
|
2016-02-29 19:57:47 +00:00
|
|
|
mergelisted (tomerge (branchlist (Just branch)))
|
2015-01-05 17:40:49 +00:00
|
|
|
)
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2016-02-29 19:57:47 +00:00
|
|
|
mergelisted getlist = and <$>
|
2017-06-01 16:46:36 +00:00
|
|
|
(mapM (merge currbranch mergeconfig resolvemergeoverride Git.Branch.ManualCommit . remoteBranch remote) =<< getlist)
|
2014-02-11 17:11:49 +00:00
|
|
|
tomerge = filterM (changed remote)
|
2012-11-12 05:05:04 +00:00
|
|
|
branchlist Nothing = []
|
|
|
|
branchlist (Just branch) = [branch, syncBranch branch]
|
2011-12-30 23:11:22 +00:00
|
|
|
|
2016-02-29 19:23:08 +00:00
|
|
|
pushRemote :: SyncOptions -> Remote -> CurrBranch -> CommandStart
|
|
|
|
pushRemote _o _remote (Nothing, _) = stop
|
|
|
|
pushRemote o remote (Just branch, _) = stopUnless (pure (pushOption o) <&&> needpush) $ do
|
2015-09-13 17:15:35 +00:00
|
|
|
showStart "push" (Remote.name remote)
|
|
|
|
next $ next $ do
|
|
|
|
showOutput
|
Added remote.<name>.annex-push and remote.<name>.annex-pull
The former can be useful to make remotes that don't get fully synced with
local changes, which comes up in a lot of situations.
The latter was mostly added for symmetry, but could be useful (though less
likely to be).
Implementing `remote.<name>.annex-pull` was a bit tricky, as there's no one
place where git-annex pulls/fetches from remotes. I audited all
instances of "fetch" and "pull". A few cases were left not checking this
config:
* Git.Repair can try to pull missing refs from a remote, and if the local
repo is corrupted, that seems a reasonable thing to do even though
the config would normally prevent it.
* Assistant.WebApp.Gpg and Remote.Gcrypt and Remote.Git do fetches
as part of the setup process of a remote. The config would probably not
be set then, and having the setup fail seems worse than honoring it if it
is already set.
I have not prevented all the code that does a "merge" from merging branches
from remotes with remote.<name>.annex-pull=false. That could perhaps
be done, but it would need a way to map from branch name to remote name,
and the way refspecs work makes that hard to get really correct. So if the
user fetches manually, the git-annex branch will get merged, for example.
Anther way of looking at/justifying this is that the setting is called
"annex-pull", not "annex-merge".
This commit was supported by the NSF-funded DataLad project.
2017-04-05 17:04:02 +00:00
|
|
|
ok <- inRepoWithSshOptionsTo (Remote.repo remote) gc $
|
2015-09-13 17:15:35 +00:00
|
|
|
pushBranch remote branch
|
2017-02-17 19:21:39 +00:00
|
|
|
if ok
|
|
|
|
then postpushupdate
|
|
|
|
else do
|
|
|
|
warning $ unwords [ "Pushing to " ++ Remote.name remote ++ " failed." ]
|
|
|
|
showLongNote "(non-fast-forward problems can be solved by setting receive.denyNonFastforwards to false in the remote's git config)"
|
|
|
|
return ok
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2014-01-02 17:12:32 +00:00
|
|
|
needpush
|
Added remote.<name>.annex-push and remote.<name>.annex-pull
The former can be useful to make remotes that don't get fully synced with
local changes, which comes up in a lot of situations.
The latter was mostly added for symmetry, but could be useful (though less
likely to be).
Implementing `remote.<name>.annex-pull` was a bit tricky, as there's no one
place where git-annex pulls/fetches from remotes. I audited all
instances of "fetch" and "pull". A few cases were left not checking this
config:
* Git.Repair can try to pull missing refs from a remote, and if the local
repo is corrupted, that seems a reasonable thing to do even though
the config would normally prevent it.
* Assistant.WebApp.Gpg and Remote.Gcrypt and Remote.Git do fetches
as part of the setup process of a remote. The config would probably not
be set then, and having the setup fail seems worse than honoring it if it
is already set.
I have not prevented all the code that does a "merge" from merging branches
from remotes with remote.<name>.annex-pull=false. That could perhaps
be done, but it would need a way to map from branch name to remote name,
and the way refspecs work makes that hard to get really correct. So if the
user fetches manually, the git-annex branch will get merged, for example.
Anther way of looking at/justifying this is that the setting is called
"annex-pull", not "annex-merge".
This commit was supported by the NSF-funded DataLad project.
2017-04-05 17:04:02 +00:00
|
|
|
| remoteAnnexReadOnly gc = return False
|
|
|
|
| not (remoteAnnexPush gc) = return False
|
2014-01-02 17:12:32 +00:00
|
|
|
| otherwise = anyM (newer remote) [syncBranch branch, Annex.Branch.name]
|
2017-02-17 19:21:39 +00:00
|
|
|
-- Do updateInstead emulation for remotes on eg removable drives
|
|
|
|
-- formatted FAT, where the post-update hook won't run.
|
|
|
|
postpushupdate
|
2017-05-11 20:03:50 +00:00
|
|
|
| annexCrippledFileSystem (remoteGitConfig (Remote.gitconfig remote)) =
|
2017-02-17 19:21:39 +00:00
|
|
|
case Git.repoWorkTree (Remote.repo remote) of
|
|
|
|
Nothing -> return True
|
|
|
|
Just wt -> ifM (Remote.Git.onLocal remote needUpdateInsteadEmulation)
|
|
|
|
( liftIO $ do
|
|
|
|
p <- readProgramFile
|
|
|
|
boolSystem' p [Param "post-receive"]
|
|
|
|
(\cp -> cp { cwd = Just wt })
|
|
|
|
, return True
|
|
|
|
)
|
|
|
|
| otherwise = return True
|
Added remote.<name>.annex-push and remote.<name>.annex-pull
The former can be useful to make remotes that don't get fully synced with
local changes, which comes up in a lot of situations.
The latter was mostly added for symmetry, but could be useful (though less
likely to be).
Implementing `remote.<name>.annex-pull` was a bit tricky, as there's no one
place where git-annex pulls/fetches from remotes. I audited all
instances of "fetch" and "pull". A few cases were left not checking this
config:
* Git.Repair can try to pull missing refs from a remote, and if the local
repo is corrupted, that seems a reasonable thing to do even though
the config would normally prevent it.
* Assistant.WebApp.Gpg and Remote.Gcrypt and Remote.Git do fetches
as part of the setup process of a remote. The config would probably not
be set then, and having the setup fail seems worse than honoring it if it
is already set.
I have not prevented all the code that does a "merge" from merging branches
from remotes with remote.<name>.annex-pull=false. That could perhaps
be done, but it would need a way to map from branch name to remote name,
and the way refspecs work makes that hard to get really correct. So if the
user fetches manually, the git-annex branch will get merged, for example.
Anther way of looking at/justifying this is that the setting is called
"annex-pull", not "annex-merge".
This commit was supported by the NSF-funded DataLad project.
2017-04-05 17:04:02 +00:00
|
|
|
gc = Remote.gitconfig remote
|
2012-06-22 19:46:21 +00:00
|
|
|
|
2013-08-29 18:15:32 +00:00
|
|
|
{- Pushes a regular branch like master to a remote. Also pushes the git-annex
|
|
|
|
- branch.
|
|
|
|
-
|
2017-02-15 20:13:30 +00:00
|
|
|
- If the remote is a bare git repository, it's best to push the regular
|
2013-08-29 18:15:32 +00:00
|
|
|
- branch directly to it, so that cloning/pulling will get it.
|
|
|
|
- On the other hand, if it's not bare, pushing to the checked out branch
|
2017-02-15 20:13:30 +00:00
|
|
|
- will generally fail (except with receive.denyCurrentBranch=updateInstead),
|
|
|
|
- and this is why we push to its syncBranch.
|
2013-06-12 18:54:23 +00:00
|
|
|
-
|
|
|
|
- Git offers no way to tell if a remote is bare or not, so both methods
|
|
|
|
- are tried.
|
|
|
|
-
|
2017-02-15 20:13:30 +00:00
|
|
|
- The direct push is likely to spew an ugly error message, so its stderr is
|
|
|
|
- often elided. Since git progress display goes to stderr too, the
|
|
|
|
- sync push is done first, and actually sends the data. Then the
|
|
|
|
- direct push is tried, with stderr discarded, to update the branch ref
|
|
|
|
- on the remote.
|
2013-08-29 18:15:32 +00:00
|
|
|
-
|
|
|
|
- The sync push forces the update of the remote synced/git-annex branch.
|
|
|
|
- This is necessary if a transition has rewritten the git-annex branch.
|
|
|
|
- Normally any changes to the git-annex branch get pulled and merged before
|
|
|
|
- this push, so this forcing is unlikely to overwrite new data pushed
|
|
|
|
- in from another repository that is also syncing.
|
|
|
|
-
|
|
|
|
- But overwriting of data on synced/git-annex can happen, in a race.
|
|
|
|
- The only difference caused by using a forced push in that case is that
|
|
|
|
- the last repository to push wins the race, rather than the first to push.
|
2013-10-26 19:53:05 +00:00
|
|
|
-
|
|
|
|
- The sync push will fail to overwrite if receive.denyNonFastforwards is
|
|
|
|
- set on the remote.
|
2013-06-12 18:54:23 +00:00
|
|
|
-}
|
2016-03-03 18:13:54 +00:00
|
|
|
pushBranch :: Remote -> Git.Branch -> Git.Repo -> IO Bool
|
2017-02-17 18:00:01 +00:00
|
|
|
pushBranch remote branch g = directpush `after` annexpush `after` syncpush
|
2013-06-12 18:54:23 +00:00
|
|
|
where
|
2017-02-15 20:13:30 +00:00
|
|
|
syncpush = flip Git.Command.runBool g $ pushparams
|
2013-08-29 18:15:32 +00:00
|
|
|
[ Git.Branch.forcePush $ refspec Annex.Branch.name
|
2016-03-03 18:13:54 +00:00
|
|
|
, refspec $ fromAdjustedBranch branch
|
2013-08-29 18:15:32 +00:00
|
|
|
]
|
2017-02-17 18:00:01 +00:00
|
|
|
annexpush = void $ tryIO $ flip Git.Command.runQuiet g $ pushparams
|
|
|
|
[ Git.fromRef $ Git.Ref.base $ Annex.Branch.name ]
|
2017-02-15 20:13:30 +00:00
|
|
|
directpush = do
|
|
|
|
-- Git prints out an error message when this fails.
|
|
|
|
-- In the default configuration of receive.denyCurrentBranch,
|
|
|
|
-- the error message mentions that config setting
|
|
|
|
-- (and should even if it is localized), and is quite long,
|
|
|
|
-- and the user was not intending to update the checked out
|
|
|
|
-- branch, so in that case, avoid displaying the error
|
|
|
|
-- message. Do display other error messages though,
|
|
|
|
-- including the error displayed when
|
|
|
|
-- receive.denyCurrentBranch=updateInstead -- the user
|
|
|
|
-- will want to see that one.
|
|
|
|
let p = flip Git.Command.gitCreateProcess g $ pushparams
|
2017-02-17 18:00:01 +00:00
|
|
|
[ Git.fromRef $ Git.Ref.base $ fromDirectBranch $ fromAdjustedBranch branch ]
|
2017-02-15 20:13:30 +00:00
|
|
|
(transcript, ok) <- processTranscript' p Nothing
|
|
|
|
when (not ok && not ("denyCurrentBranch" `isInfixOf` transcript)) $
|
|
|
|
hPutStr stderr transcript
|
2013-08-29 18:15:32 +00:00
|
|
|
pushparams branches =
|
2013-03-03 17:39:07 +00:00
|
|
|
[ Param "push"
|
|
|
|
, Param $ Remote.name remote
|
2013-08-29 18:15:32 +00:00
|
|
|
] ++ map Param branches
|
2012-11-12 05:05:04 +00:00
|
|
|
refspec b = concat
|
2014-02-19 05:09:17 +00:00
|
|
|
[ Git.fromRef $ Git.Ref.base b
|
2012-11-12 05:05:04 +00:00
|
|
|
, ":"
|
2014-02-19 05:09:17 +00:00
|
|
|
, Git.fromRef $ Git.Ref.base $ syncBranch b
|
2012-11-12 05:05:04 +00:00
|
|
|
]
|
2011-12-29 17:37:30 +00:00
|
|
|
|
2014-02-01 14:49:50 +00:00
|
|
|
commitAnnex :: CommandStart
|
|
|
|
commitAnnex = do
|
|
|
|
Annex.Branch.commit "update"
|
|
|
|
stop
|
|
|
|
|
2011-12-30 20:03:41 +00:00
|
|
|
mergeAnnex :: CommandStart
|
2011-12-30 21:38:38 +00:00
|
|
|
mergeAnnex = do
|
2013-09-25 07:09:06 +00:00
|
|
|
void Annex.Branch.forceUpdate
|
2011-12-30 21:38:38 +00:00
|
|
|
stop
|
2011-12-31 06:18:16 +00:00
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
changed :: Remote -> Git.Ref -> Annex Bool
|
2011-12-31 07:01:18 +00:00
|
|
|
changed remote b = do
|
|
|
|
let r = remoteBranch remote b
|
2012-03-14 21:43:34 +00:00
|
|
|
ifM (inRepo $ Git.Ref.exists r)
|
|
|
|
( inRepo $ Git.Branch.changed b r
|
|
|
|
, return False
|
|
|
|
)
|
2011-12-31 07:01:18 +00:00
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
newer :: Remote -> Git.Ref -> Annex Bool
|
2011-12-31 07:01:18 +00:00
|
|
|
newer remote b = do
|
|
|
|
let r = remoteBranch remote b
|
2012-03-14 21:43:34 +00:00
|
|
|
ifM (inRepo $ Git.Ref.exists r)
|
|
|
|
( inRepo $ Git.Branch.changed r b
|
|
|
|
, return True
|
|
|
|
)
|
2014-01-19 21:35:36 +00:00
|
|
|
|
2015-06-16 22:38:12 +00:00
|
|
|
{- Without --all, only looks at files in the work tree. With --all,
|
|
|
|
- makes 2 passes, first looking at the work tree and then all keys.
|
|
|
|
- This ensures that preferred content expressions that match on
|
|
|
|
- filenames work, even when in --all mode.
|
|
|
|
-
|
2015-08-14 17:49:55 +00:00
|
|
|
- Returns true if any file transfers were made.
|
|
|
|
-
|
|
|
|
- When concurrency is enabled, files are processed concurrently.
|
2014-01-19 21:35:36 +00:00
|
|
|
-}
|
2015-07-09 23:03:21 +00:00
|
|
|
seekSyncContent :: SyncOptions -> [Remote] -> Annex Bool
|
|
|
|
seekSyncContent o rs = do
|
2014-02-11 17:11:49 +00:00
|
|
|
mvar <- liftIO newEmptyMVar
|
2015-07-09 23:03:21 +00:00
|
|
|
bloom <- case keyOptions o of
|
|
|
|
Just WantAllKeys -> Just <$> genBloomFilter (seekworktree mvar [])
|
2017-03-20 20:00:06 +00:00
|
|
|
_ -> seekworktree mvar (contentOfOption o) (const noop) >> pure Nothing
|
2015-07-09 23:03:21 +00:00
|
|
|
withKeyOptions' (keyOptions o) False
|
--branch, stage 1
Added --branch option to copy, drop, fsck, get, metadata, mirror, move, and
whereis commands. This option makes git-annex operate on files that are
included in a specified branch (or other treeish).
The names of the files from the branch that are being operated on are not
displayed yet; only the keys. Displaying the filenames will need changes
to every affected command.
Also, note that --branch can be specified repeatedly. This is not really
documented, but seemed worth supporting, especially since we may later want
the ability to operate on all branches matching a refspec. However, when
operating on two branches that contain the same key, that key will be
operated on twice.
2016-07-20 16:05:22 +00:00
|
|
|
(return (seekkeys mvar bloom))
|
2015-07-09 23:03:21 +00:00
|
|
|
(const noop)
|
|
|
|
[]
|
2015-08-14 17:49:55 +00:00
|
|
|
finishCommandActions
|
2014-02-01 14:49:50 +00:00
|
|
|
liftIO $ not <$> isEmptyMVar mvar
|
2014-01-20 17:31:03 +00:00
|
|
|
where
|
2015-06-16 22:38:12 +00:00
|
|
|
seekworktree mvar l bloomfeeder = seekHelper LsFiles.inRepo l >>=
|
2017-03-10 17:12:24 +00:00
|
|
|
mapM_ (\f -> ifAnnexed f (go (Right bloomfeeder) mvar (AssociatedFile (Just f))) noop)
|
|
|
|
seekkeys mvar bloom k _ = go (Left bloom) mvar (AssociatedFile Nothing) k
|
2015-08-14 17:49:55 +00:00
|
|
|
go ebloom mvar af k = commandAction $ do
|
|
|
|
whenM (syncFile ebloom rs af k) $
|
|
|
|
void $ liftIO $ tryPutMVar mvar ()
|
|
|
|
return Nothing
|
2014-01-20 17:31:03 +00:00
|
|
|
|
2015-06-16 23:07:14 +00:00
|
|
|
{- If it's preferred content, and we don't have it, get it from one of the
|
|
|
|
- listed remotes (preferring the cheaper earlier ones).
|
|
|
|
-
|
|
|
|
- Send it to each remote that doesn't have it, and for which it's
|
|
|
|
- preferred content.
|
|
|
|
-
|
|
|
|
- Drop it locally if it's not preferred content (honoring numcopies).
|
|
|
|
-
|
|
|
|
- Drop it from each remote that has it, where it's not preferred content
|
|
|
|
- (honoring numcopies).
|
2015-08-14 17:49:55 +00:00
|
|
|
-
|
|
|
|
- Returns True if any file transfers were made.
|
2015-06-16 23:07:14 +00:00
|
|
|
-}
|
2015-08-14 17:49:55 +00:00
|
|
|
syncFile :: Either (Maybe (Bloom Key)) (Key -> Annex ()) -> [Remote] -> AssociatedFile -> Key -> Annex Bool
|
2015-06-16 22:38:12 +00:00
|
|
|
syncFile ebloom rs af k = do
|
2016-09-06 15:21:59 +00:00
|
|
|
locs <- Remote.keyLocations k
|
2014-01-19 21:35:36 +00:00
|
|
|
let (have, lack) = partition (\r -> Remote.uuid r `elem` locs) rs
|
|
|
|
|
2014-02-03 02:46:55 +00:00
|
|
|
got <- anyM id =<< handleget have
|
2015-07-20 18:24:13 +00:00
|
|
|
putrs <- handleput lack
|
2014-01-20 17:31:03 +00:00
|
|
|
|
2014-02-03 02:46:55 +00:00
|
|
|
u <- getUUID
|
2014-02-11 17:11:49 +00:00
|
|
|
let locs' = concat [[u | got], putrs, locs]
|
2014-02-03 02:46:55 +00:00
|
|
|
|
2015-06-16 22:38:12 +00:00
|
|
|
-- A bloom filter is populated with all the keys in the first pass.
|
|
|
|
-- On the second pass, avoid dropping keys that were seen in the
|
|
|
|
-- first pass, which would happen otherwise when preferred content
|
|
|
|
-- matches on the filename, which is not available in the second
|
|
|
|
-- pass.
|
|
|
|
--
|
|
|
|
-- When there's a false positive in the bloom filter, the result
|
|
|
|
-- is keeping a key that preferred content doesn't really want.
|
|
|
|
seenbloom <- case ebloom of
|
2015-06-16 23:04:20 +00:00
|
|
|
Left Nothing -> pure False
|
|
|
|
Left (Just bloom) -> pure (elemB k bloom)
|
2015-06-16 22:38:12 +00:00
|
|
|
Right bloomfeeder -> bloomfeeder k >> return False
|
|
|
|
unless seenbloom $
|
|
|
|
-- Using callCommandAction rather than
|
|
|
|
-- includeCommandAction for drops,
|
|
|
|
-- because a failure to drop does not mean
|
|
|
|
-- the sync failed.
|
2015-10-08 20:55:11 +00:00
|
|
|
handleDropsFrom locs' rs "unwanted" True k af []
|
|
|
|
callCommandAction
|
2015-08-14 17:49:55 +00:00
|
|
|
|
|
|
|
return (got || not (null putrs))
|
2014-01-20 17:31:03 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
wantget have = allM id
|
2014-01-19 21:35:36 +00:00
|
|
|
[ pure (not $ null have)
|
|
|
|
, not <$> inAnnex k
|
2015-06-16 19:07:03 +00:00
|
|
|
, wantGet True (Just k) af
|
2014-01-19 21:35:36 +00:00
|
|
|
]
|
|
|
|
handleget have = ifM (wantget have)
|
|
|
|
( return [ get have ]
|
|
|
|
, return []
|
|
|
|
)
|
2015-04-10 21:08:07 +00:00
|
|
|
get have = includeCommandAction $ do
|
2016-07-20 19:22:55 +00:00
|
|
|
showStart' "get" k (mkActionItem af)
|
Do verification of checksums of annex objects downloaded from remotes.
* When annex objects are received into git repositories, their checksums are
verified then too.
* To get the old, faster, behavior of not verifying checksums, set
annex.verify=false, or remote.<name>.annex-verify=false.
* setkey, rekey: These commands also now verify that the provided file
matches the key, unless annex.verify=false.
* reinject: Already verified content; this can now be disabled by
setting annex.verify=false.
recvkey and reinject already did verification, so removed now duplicate
code from them. fsck still does its own verification, which is ok since it
does not use getViaTmp, so verification doesn't happen twice when using fsck
--from.
2015-10-01 19:54:37 +00:00
|
|
|
next $ next $ getKey' k af have
|
2014-01-19 21:35:36 +00:00
|
|
|
|
|
|
|
wantput r
|
2014-04-12 19:59:34 +00:00
|
|
|
| Remote.readonly r || remoteAnnexReadOnly (Remote.gitconfig r) = return False
|
2015-06-16 19:07:03 +00:00
|
|
|
| otherwise = wantSend True (Just k) af (Remote.uuid r)
|
2015-07-20 18:24:13 +00:00
|
|
|
handleput lack = catMaybes <$> ifM (inAnnex k)
|
|
|
|
( forM lack $ \r ->
|
|
|
|
ifM (wantput r <&&> put r)
|
|
|
|
( return (Just (Remote.uuid r))
|
|
|
|
, return Nothing
|
|
|
|
)
|
2014-01-19 21:35:36 +00:00
|
|
|
, return []
|
|
|
|
)
|
2016-03-09 19:04:00 +00:00
|
|
|
put dest = includeCommandAction $
|
2016-07-20 19:22:55 +00:00
|
|
|
Command.Move.toStart' dest False af k (mkActionItem af)
|