sync: Add --no-commit, --no-pull, --no-push options to turn off parts of the sync process, as well as supporting --commit, --pull, --push, and --no-content options to specify the (current) default behavior.

This commit is contained in:
Joey Hess 2015-09-13 13:15:35 -04:00
parent 5aa5e92da7
commit 1cc1f9f4e5
3 changed files with 73 additions and 50 deletions

View file

@ -60,21 +60,33 @@ cmd = withGlobalOptions [jobsOption] $
data SyncOptions = SyncOptions data SyncOptions = SyncOptions
{ syncWith :: CmdParams { syncWith :: CmdParams
, contentOption :: Bool , commitOption :: Bool
, messageOption :: Maybe String , messageOption :: Maybe String
, pullOption :: Bool
, pushOption :: Bool
, contentOption :: Bool
, keyOptions :: Maybe KeyOptions , keyOptions :: Maybe KeyOptions
} }
optParser :: CmdParamsDesc -> Parser SyncOptions optParser :: CmdParamsDesc -> Parser SyncOptions
optParser desc = SyncOptions optParser desc = SyncOptions
<$> cmdParams desc <$> cmdParams desc
<*> invertableSwitch "content" False <*> invertableSwitch "commit" True
( help "also transfer file contents" ( help "avoid git commit"
) )
<*> optional (strOption <*> optional (strOption
( long "message" <> short 'm' <> metavar "MSG" ( long "message" <> short 'm' <> metavar "MSG"
<> help "commit message" <> help "commit message"
)) ))
<*> invertableSwitch "pull" True
( help "avoid git pulls from remotes"
)
<*> invertableSwitch "push" True
( help "avoid git pushes to remotes"
)
<*> invertableSwitch "content" False
( help "also transfer file contents"
)
<*> optional parseAllOption <*> optional parseAllOption
seek :: SyncOptions -> CommandSeek seek :: SyncOptions -> CommandSeek
@ -107,7 +119,7 @@ seek o = do
mapM_ includeCommandAction $ concat mapM_ includeCommandAction $ concat
[ [ commit o ] [ [ commit o ]
, [ withbranch mergeLocal ] , [ withbranch mergeLocal ]
, map (withbranch . pullRemote) gitremotes , map (withbranch . pullRemote o) gitremotes
, [ mergeAnnex ] , [ mergeAnnex ]
] ]
when (contentOption o) $ when (contentOption o) $
@ -118,13 +130,13 @@ seek o = do
-- and merge again to avoid our push overwriting -- and merge again to avoid our push overwriting
-- those changes. -- those changes.
mapM_ includeCommandAction $ concat mapM_ includeCommandAction $ concat
[ map (withbranch . pullRemote) gitremotes [ map (withbranch . pullRemote o) gitremotes
, [ commitAnnex, mergeAnnex ] , [ commitAnnex, mergeAnnex ]
] ]
void $ includeCommandAction $ withbranch pushLocal void $ includeCommandAction $ withbranch pushLocal
-- Pushes to remotes can run concurrently. -- Pushes to remotes can run concurrently.
mapM_ (commandAction . withbranch . pushRemote) gitremotes mapM_ (commandAction . withbranch . pushRemote o) gitremotes
{- Merging may delete the current directory, so go to the top {- Merging may delete the current directory, so go to the top
- of the repo. This also means that sync always acts on all files in the - of the repo. This also means that sync always acts on all files in the
@ -165,28 +177,26 @@ syncRemotes' ps remotelist = ifM (Annex.getState Annex.fast) ( nub <$> pickfast
fastest = fromMaybe [] . headMaybe . Remote.byCost fastest = fromMaybe [] . headMaybe . Remote.byCost
commit :: SyncOptions -> CommandStart commit :: SyncOptions -> CommandStart
commit o = ifM (annexAutoCommit <$> Annex.getGitConfig) commit o = stopUnless shouldcommit $ next $ next $ do
( go commitmessage <- maybe commitMsg return (messageOption o)
, stop showStart "commit" ""
) Annex.Branch.commit "update"
ifM isDirect
( do
void stageDirect
void preCommitDirect
commitStaged Git.Branch.ManualCommit commitmessage
, do
inRepo $ Git.Branch.commitQuiet Git.Branch.ManualCommit
[ Param "-a"
, Param "-m"
, Param commitmessage
]
return True
)
where where
go = next $ next $ do shouldcommit = pure (commitOption o)
commitmessage <- maybe commitMsg return (messageOption o) <&&> (annexAutoCommit <$> Annex.getGitConfig)
showStart "commit" ""
Annex.Branch.commit "update"
ifM isDirect
( do
void stageDirect
void preCommitDirect
commitStaged Git.Branch.ManualCommit commitmessage
, do
inRepo $ Git.Branch.commitQuiet Git.Branch.ManualCommit
[ Param "-a"
, Param "-m"
, Param commitmessage
]
return True
)
commitMsg :: Annex String commitMsg :: Annex String
commitMsg = do commitMsg = do
@ -248,8 +258,8 @@ updateBranch syncbranch g =
, Param $ Git.fromRef $ Git.Ref.base syncbranch , Param $ Git.fromRef $ Git.Ref.base syncbranch
] g ] g
pullRemote :: Remote -> Maybe Git.Ref -> CommandStart pullRemote :: SyncOptions -> Remote -> Maybe Git.Ref -> CommandStart
pullRemote remote branch = do pullRemote o remote branch = stopUnless (pure $ pullOption o) $ do
showStart "pull" (Remote.name remote) showStart "pull" (Remote.name remote)
next $ do next $ do
showOutput showOutput
@ -282,24 +292,22 @@ mergeRemote remote b = ifM isBareRepo
branchlist Nothing = [] branchlist Nothing = []
branchlist (Just branch) = [branch, syncBranch branch] branchlist (Just branch) = [branch, syncBranch branch]
pushRemote :: Remote -> Maybe Git.Ref -> CommandStart pushRemote :: SyncOptions -> Remote -> Maybe Git.Ref -> CommandStart
pushRemote _remote Nothing = stop pushRemote _o _remote Nothing = stop
pushRemote remote (Just branch) = go =<< needpush pushRemote o remote (Just branch) = stopUnless (pure (pushOption o) <&&> needpush) $ do
showStart "push" (Remote.name remote)
next $ next $ do
showOutput
ok <- inRepoWithSshOptionsTo (Remote.repo remote) (Remote.gitconfig remote) $
pushBranch remote branch
unless ok $ 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
where where
needpush needpush
| remoteAnnexReadOnly (Remote.gitconfig remote) = return False | remoteAnnexReadOnly (Remote.gitconfig remote) = return False
| otherwise = anyM (newer remote) [syncBranch branch, Annex.Branch.name] | otherwise = anyM (newer remote) [syncBranch branch, Annex.Branch.name]
go False = stop
go True = do
showStart "push" (Remote.name remote)
next $ next $ do
showOutput
ok <- inRepoWithSshOptionsTo (Remote.repo remote) (Remote.gitconfig remote) $
pushBranch remote branch
unless ok $ 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
{- Pushes a regular branch like master to a remote. Also pushes the git-annex {- Pushes a regular branch like master to a remote. Also pushes the git-annex
- branch. - branch.

3
debian/changelog vendored
View file

@ -17,6 +17,9 @@ git-annex (5.20150825) UNRELEASED; urgency=medium
* Windows: Even when the user neglects to tell the git installer to * Windows: Even when the user neglects to tell the git installer to
add git to PATH, git-annex will still work from within the git bash add git to PATH, git-annex will still work from within the git bash
shell, and the webapp can be used too. shell, and the webapp can be used too.
* sync: Add --no-commit, --no-pull, --no-push options to turn off parts of
the sync process, as well as supporting --commit, --pull, --push, and
--no-content options to specify the (current) default behavior.
-- Joey Hess <id@joeyh.name> Tue, 01 Sep 2015 14:46:18 -0700 -- Joey Hess <id@joeyh.name> Tue, 01 Sep 2015 14:46:18 -0700

View file

@ -36,21 +36,33 @@ by running "git annex sync" on the remote.
# OPTIONS # OPTIONS
* `--message=msg`
Use this option to specify a commit message.
* `--fast` * `--fast`
Only sync with the remotes with the lowest annex-cost value configured. Only sync with the remotes with the lowest annex-cost value configured.
* `--content` * `--commit`, `--no-commit`
A commit is done by default. Use --no-cmmit to avoid committing local changes.
* `--message=msg`
Use this option to specify a commit message.
* `--pull`, `--no-pull`
By default, git pulls from remotes. Use --no-pull to disable.
* `--push`, `--no-push`
By default, git pushes to remotes. Use --no-push to disable.
* `--content`, `--no-content`
Normally, syncing does not transfer the contents of annexed files. Normally, syncing does not transfer the contents of annexed files.
This option causes the content of files in the work tree The --content option causes the content of files in the work tree
to also be uploaded and downloaded as necessary. to also be uploaded and downloaded as necessary.
By default, this tries to get each annexed file in the work tree Normally this tries to get each annexed file in the work tree
that the local repository does not yet have, and then copies each that the local repository does not yet have, and then copies each
file in the work tree to every remote that it is syncing with. file in the work tree to every remote that it is syncing with.
This behavior can be overridden by configuring the preferred content This behavior can be overridden by configuring the preferred content