-Requires Mercurial >= 1.3.1
+Requires Mercurial >= 1.3.1
The test script `tests/test-autosync` can either be executed directly or used
within the Mercurial testing suite.
def _cmdopts(cte, ouropts):
"""Build options dictionary for a command.
Option names are read from the given command table entry. Option values are
those set in `ouropts` or the defaults set in the command table entry.
def _alert(ui, repo, error):
"""Run the alert program, if defined."""
alert = repo.ui.config("autosync", "alert")
alert = util.expandpath(alert)
def _sync(ui, repo, other, opts):
"""Synchronize once or continuously, depending on `opts`."""
raise util.Abort("interval must be a positive number")
raise util.Abort("initial repository, first change should get pulled "
# set up options for sub-commands
commitopts = _cmdopts(commands.table["^commit|ci"], opts)
commitopts["message"] = "Automated commit"
fetchopts = _cmdopts(fetch_ct["fetch"], opts)
fetchopts["source"] = other
pushopts = _cmdopts(commands.table["^push"], opts)
# force non-interactive merge (unless defined otherwise in autosync->merge)
automerge = repo.ui.config("autosync", "merge")
os.environ["HGMERGE"] = automerge or "internal:merge"
# run one synchronization cycle only ?
_cycle(ui, repo.root, commitopts, fetchopts, pushopts)
# loop synchronization cycles !
ts = datetime.strftime(datetime.now(), "%x %X")
ui.write("%s\n" % (" %s " % ts).center(79, "-"))
def autosync(ui, repo, other="default", **opts):
- """commit, fetch and push at regular intervals
+ """commit, fetch and push at regular intervals
Commit changes in the working copy, fetch (pull, merge and commit) changes
from another repository and push local changes back to the other repository
- either continuously (default) or once only.
The idea of this command is to use Mercurial as a synchronization engine
to keep files in sync across work stations. Think of configuration files or
to-do lists as examples for things to synchronize. On a higher level this
command not only synchronizes repositories but working copies. A central
repository (usually without a working copy) must be used as synchronization
repo1 <--sync--> hub <--sync--> repo2
Running this command in repo1 and repo2 ensures the working copies (!) of
both repositories stay in sync (as long as there are no conflicting
By default Mercurial's internal non-interactive merge is used when fetching
from another repository. This can be changed with the `merge` option.
Errors and merge conflicts which cannot be resolved automatically are
the alert tool. Independent of these options, autosync keeps running when
there are problems and retries after the next interval, hoping things get
When running in daemon mode, any output gets logged into the file
`autosync.log` within the repository's `.hg` directory (use --daemon-log
to set a different file).
This command denies to run in a virgin repository as this may unrelate
repositories which were supposed to get synchronized. Before running
autosync, pull or commit something first manually.
runfn = lambda: _sync(ui, repo, other, opts)
logfile = opts["daemon_log"]
cmdutil.service(opts, runfn=runfn, logfile=logfile)