diff --git a/edenscm/hgext/infinitepush/client.py b/edenscm/hgext/infinitepush/client.py index cb60b19b3e..2b648f343a 100644 --- a/edenscm/hgext/infinitepush/client.py +++ b/edenscm/hgext/infinitepush/client.py @@ -100,6 +100,30 @@ def extsetup(ui): ) +def preparepush(ui, dest): + # If the user is saying they want to push to "default", and this is a + # scratch push, then we're going to go to the infinitepush destination + # instead, if it exists. This ensures that as long as infinitepush and + # infinitepush-other (see below) route to different places (respectively + # Mercurial and Mononoke), then infinite pushes without a path OR with a + # path of "default" will be routed to both of them. Put it another way: when + # you do a scratch push, "default" means the infinitepush path. + if dest == "default": + try: + return (True, ui.paths.getpath("infinitepush")) + except error.RepoError: + # Fallthrough to the next block. + pass + + if dest is None or dest in ("default", "infinitepush"): + path = ui.paths.getpath( + dest, default=("infinitepush", "default-push", "default") + ) + return (True, path) + + return (False, ui.paths.getpath(dest)) + + def _push(orig, ui, repo, dest=None, *args, **opts): bookmark = opts.get("to") or "" create = opts.get("create") or False @@ -163,22 +187,23 @@ def _push(orig, ui, repo, dest=None, *args, **opts): if scratchpush: ui.setconfig("experimental", "infinitepush-scratchpush", True) + oldphasemove = extensions.wrapfunction( exchange, "_localphasemove", _phasemove ) - path = ui.paths.getpath( - dest, default=("infinitepush", "default-push", "default") - ) - # We'll replicate the push if the user provided no destination and - # intended their push to go to the default infinitepush destination. - if dest is None: + replicate, path = preparepush(ui, dest) + + # We'll replicate the push if the user intended their push to go to + # the default infinitepush destination. + if replicate: try: otherpath = repo.ui.paths.getpath("infinitepush-other") except error.RepoError: pass else: path = ui.paths.getpath(dest, default=("default-push", "default")) + # Copy-paste from `push` command if not path: raise error.Abort( diff --git a/tests/test-infinitepush-push-to-other.t b/tests/test-infinitepush-push-to-other.t index e651159b45..cd5bb9e68c 100644 --- a/tests/test-infinitepush-push-to-other.t +++ b/tests/test-infinitepush-push-to-other.t @@ -24,6 +24,8 @@ Check that we replicate a push $ cp "$TESTTMP/defaulthgrc" "$HGRCPATH" $ cat >> "$HGRCPATH" << EOF > [paths] + > default-push=ssh://user@dummy/repo3 + > infinitepush=ssh://user@dummy/repo1 > infinitepush-other=ssh://user@dummy/repo2 > [infinitepush] > branchpattern=re:scratch/.+ @@ -40,6 +42,34 @@ Check that we replicate a push searching for changes remote: pushing 1 commit: remote: 67145f466344 initialcommit + $ mkcommit morecommit + $ hg push infinitepush -r . --to scratch/test123 + pushing to ssh://user@dummy/repo1 + searching for changes + remote: pushing 2 commits: + remote: 67145f466344 initialcommit + remote: 6b2f28e02245 morecommit + please wait while we replicate this push to an alternate repository + pushing to ssh://user@dummy/repo2 + searching for changes + remote: pushing 2 commits: + remote: 67145f466344 initialcommit + remote: 6b2f28e02245 morecommit + $ mkcommit anothercommit + $ hg push default -r . --to scratch/test123 + pushing to ssh://user@dummy/repo1 + searching for changes + remote: pushing 3 commits: + remote: 67145f466344 initialcommit + remote: 6b2f28e02245 morecommit + remote: 17528c345014 anothercommit + please wait while we replicate this push to an alternate repository + pushing to ssh://user@dummy/repo2 + searching for changes + remote: pushing 3 commits: + remote: 67145f466344 initialcommit + remote: 6b2f28e02245 morecommit + remote: 17528c345014 anothercommit $ cd .. Check that we do not replicate a push to the same destination @@ -53,7 +83,7 @@ Check that we do not replicate a push to the same destination > EOF $ cd client2 $ mkcommit initialcommit - $ hg push -r . --to scratch/test123 --create + $ hg push -r . --to scratch/test456 --create pushing to ssh://user@dummy/repo1 searching for changes remote: pushing 1 commit: @@ -70,7 +100,7 @@ Check that we do not replicate a push when the destination is set > EOF $ cd client3 $ mkcommit initialcommit - $ hg push ssh://user@dummy/repo3 -r . --to scratch/test123 --create + $ hg push ssh://user@dummy/repo3 -r . --to scratch/test789 --create pushing to ssh://user@dummy/repo3 searching for changes remote: pushing 1 commit: