sync: New command that synchronises the local repository and default remote, by running git commit, pull, and push for you.
This commit is contained in:
parent
4b3c4c0c2b
commit
fb8231f3a1
4 changed files with 80 additions and 1 deletions
64
Command/Sync.hs
Normal file
64
Command/Sync.hs
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
{- git-annex command
|
||||||
|
-
|
||||||
|
- Copyright 2011 Joey Hess <joey@kitenet.net>
|
||||||
|
-
|
||||||
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
|
-}
|
||||||
|
|
||||||
|
module Command.Sync where
|
||||||
|
|
||||||
|
import Common.Annex
|
||||||
|
import Command
|
||||||
|
import qualified Annex.Branch
|
||||||
|
import qualified Git
|
||||||
|
|
||||||
|
import qualified Data.ByteString.Lazy.Char8 as L
|
||||||
|
|
||||||
|
def :: [Command]
|
||||||
|
def = [command "sync" paramPaths seek "synchronize local repository with remote"]
|
||||||
|
|
||||||
|
seek :: [CommandSeek]
|
||||||
|
seek = [withNothing start]
|
||||||
|
|
||||||
|
start :: CommandStart
|
||||||
|
start = do
|
||||||
|
showStart "sync" "."
|
||||||
|
showOutput
|
||||||
|
next perform
|
||||||
|
|
||||||
|
perform :: CommandPerform
|
||||||
|
perform = do
|
||||||
|
remote <- defaultRemote =<< currentBranch
|
||||||
|
checkRemote remote
|
||||||
|
commit
|
||||||
|
inRepo $ Git.run "pull" [Param remote]
|
||||||
|
Annex.Branch.update
|
||||||
|
inRepo $ Git.run "push" [Param remote, matchingbranches]
|
||||||
|
next $ return True
|
||||||
|
where
|
||||||
|
-- git push may be configured to not push matching
|
||||||
|
-- branches; this should ensure it always does.
|
||||||
|
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
|
||||||
|
defaultRemote :: String -> Annex String
|
||||||
|
defaultRemote branch =
|
||||||
|
fromRepo $ Git.configGet ("branch." ++ branch ++ ".remote") "origin"
|
||||||
|
|
||||||
|
currentBranch :: Annex String
|
||||||
|
currentBranch = last . split "/" . L.unpack . head . L.lines <$>
|
||||||
|
inRepo (Git.pipeRead [Param "symbolic-ref", Param "HEAD"])
|
||||||
|
|
||||||
|
checkRemote :: String -> Annex ()
|
||||||
|
checkRemote remote = do
|
||||||
|
remoteurl <- fromRepo $
|
||||||
|
Git.configGet ("remote." ++ remote ++ ".url") ""
|
||||||
|
when (null remoteurl) $ do
|
||||||
|
error $ "No url is configured for the remote: " ++ remote
|
|
@ -47,6 +47,7 @@ import qualified Command.Trust
|
||||||
import qualified Command.Untrust
|
import qualified Command.Untrust
|
||||||
import qualified Command.Semitrust
|
import qualified Command.Semitrust
|
||||||
import qualified Command.Dead
|
import qualified Command.Dead
|
||||||
|
import qualified Command.Sync
|
||||||
import qualified Command.AddUrl
|
import qualified Command.AddUrl
|
||||||
import qualified Command.Map
|
import qualified Command.Map
|
||||||
import qualified Command.Upgrade
|
import qualified Command.Upgrade
|
||||||
|
@ -61,6 +62,8 @@ cmds = concat
|
||||||
, Command.Copy.def
|
, Command.Copy.def
|
||||||
, Command.Unlock.def
|
, Command.Unlock.def
|
||||||
, Command.Lock.def
|
, Command.Lock.def
|
||||||
|
, Command.Sync.def
|
||||||
|
, Command.AddUrl.def
|
||||||
, Command.Init.def
|
, Command.Init.def
|
||||||
, Command.Describe.def
|
, Command.Describe.def
|
||||||
, Command.InitRemote.def
|
, Command.InitRemote.def
|
||||||
|
@ -72,7 +75,6 @@ cmds = concat
|
||||||
, Command.Untrust.def
|
, Command.Untrust.def
|
||||||
, Command.Semitrust.def
|
, Command.Semitrust.def
|
||||||
, Command.Dead.def
|
, Command.Dead.def
|
||||||
, Command.AddUrl.def
|
|
||||||
, Command.FromKey.def
|
, Command.FromKey.def
|
||||||
, Command.DropKey.def
|
, Command.DropKey.def
|
||||||
, Command.Fix.def
|
, Command.Fix.def
|
||||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -9,6 +9,8 @@ git-annex (3.20111204) UNRELEASED; urgency=low
|
||||||
multiple different encrypted special remotes.
|
multiple different encrypted special remotes.
|
||||||
* unannex: Can be run on files that have been added to the annex, but not
|
* unannex: Can be run on files that have been added to the annex, but not
|
||||||
yet committed.
|
yet committed.
|
||||||
|
* sync: New command that synchronises the local repository and default
|
||||||
|
remote, by running git commit, pull, and push for you.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Sun, 04 Dec 2011 12:22:37 -0400
|
-- Joey Hess <joeyh@debian.org> Sun, 04 Dec 2011 12:22:37 -0400
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,17 @@ subdirectories).
|
||||||
Use this to undo an unlock command if you don't want to modify
|
Use this to undo an unlock command if you don't want to modify
|
||||||
the files, or have made modifications you want to discard.
|
the files, or have made modifications you want to discard.
|
||||||
|
|
||||||
|
* sync
|
||||||
|
|
||||||
|
Use this command when you want to synchronize the local repository
|
||||||
|
with its default remote (typically "origin"). The sync process involves
|
||||||
|
first committing all local changes, then pulling and merging any changes
|
||||||
|
from the remote, and finally pushing the repository's state to the remote.
|
||||||
|
You can use standard git commands to do each of those steps by hand,
|
||||||
|
or if you don't want to worry about the details, you can use sync.
|
||||||
|
|
||||||
|
Note that sync does not transfer any file contents from or to the remote.
|
||||||
|
|
||||||
* addurl [url ...]
|
* addurl [url ...]
|
||||||
|
|
||||||
Downloads each url to a file, which is added to the annex.
|
Downloads each url to a file, which is added to the annex.
|
||||||
|
|
Loading…
Reference in a new issue