separate operations
This commit is contained in:
parent
fb8231f3a1
commit
4200b8038a
1 changed files with 30 additions and 24 deletions
|
@ -17,39 +17,45 @@ import qualified Data.ByteString.Lazy.Char8 as L
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [command "sync" paramPaths seek "synchronize local repository with remote"]
|
def = [command "sync" paramPaths seek "synchronize local repository with remote"]
|
||||||
|
|
||||||
|
-- syncing involves several operations, any of which can independantly fail
|
||||||
seek :: [CommandSeek]
|
seek :: [CommandSeek]
|
||||||
seek = [withNothing start]
|
seek = map withNothing [commit, pull, push]
|
||||||
|
|
||||||
start :: CommandStart
|
commit :: CommandStart
|
||||||
start = do
|
commit = do
|
||||||
showStart "sync" "."
|
showStart "commit" ""
|
||||||
showOutput
|
next $ next $ do
|
||||||
next perform
|
showOutput
|
||||||
|
-- Commit will fail when the tree is clean, so ignore failure.
|
||||||
|
_ <- inRepo $ Git.runBool "commit" [Param "-a", Param "-m", Param "sync"]
|
||||||
|
return True
|
||||||
|
|
||||||
perform :: CommandPerform
|
pull :: CommandStart
|
||||||
perform = do
|
pull = do
|
||||||
remote <- defaultRemote =<< currentBranch
|
remote <- defaultRemote
|
||||||
checkRemote remote
|
showStart "pull" remote
|
||||||
commit
|
next $ next $ do
|
||||||
inRepo $ Git.run "pull" [Param remote]
|
showOutput
|
||||||
Annex.Branch.update
|
checkRemote remote
|
||||||
inRepo $ Git.run "push" [Param remote, matchingbranches]
|
inRepo $ Git.runBool "pull" [Param remote]
|
||||||
next $ return True
|
|
||||||
|
push :: CommandStart
|
||||||
|
push = do
|
||||||
|
remote <- defaultRemote
|
||||||
|
showStart "push" remote
|
||||||
|
next $ next $ do
|
||||||
|
Annex.Branch.update
|
||||||
|
showOutput
|
||||||
|
inRepo $ Git.runBool "push" [Param remote, matchingbranches]
|
||||||
where
|
where
|
||||||
-- git push may be configured to not push matching
|
-- git push may be configured to not push matching
|
||||||
-- branches; this should ensure it always does.
|
-- branches; this should ensure it always does.
|
||||||
matchingbranches = Param ":"
|
matchingbranches = Param ":"
|
||||||
|
|
||||||
commit :: Annex ()
|
|
||||||
commit = do
|
|
||||||
-- Commit will fail when the tree is clean (or when in a confliced
|
|
||||||
-- merge, etc). Ignore failure.
|
|
||||||
_ <- inRepo $ Git.runBool "commit" [Param "-a", Param "-m", Param "sync"]
|
|
||||||
return ()
|
|
||||||
|
|
||||||
-- the remote defaults to origin when not configured
|
-- the remote defaults to origin when not configured
|
||||||
defaultRemote :: String -> Annex String
|
defaultRemote :: Annex String
|
||||||
defaultRemote branch =
|
defaultRemote = do
|
||||||
|
branch <- currentBranch
|
||||||
fromRepo $ Git.configGet ("branch." ++ branch ++ ".remote") "origin"
|
fromRepo $ Git.configGet ("branch." ++ branch ++ ".remote") "origin"
|
||||||
|
|
||||||
currentBranch :: Annex String
|
currentBranch :: Annex String
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue