replicate hg push for scratch branches to infinitepush-other

Summary: This updates `hg push` to replicate pushes to the `infinitepush-other` path. This ensures that we replicate pushes to scratch branches to Mononoke once we enable this mechanism.

Reviewed By: markbt

Differential Revision: D15538790

fbshipit-source-id: 0baa31f26f516cf5d2f6ec5a14d8006c912766c2
This commit is contained in:
Thomas Orozco 2019-05-30 08:29:57 -07:00 committed by Facebook Github Bot
parent 5e6a627073
commit b26f3f5a25
2 changed files with 104 additions and 0 deletions

View File

@ -158,6 +158,9 @@ def _push(orig, ui, repo, dest=None, *args, **opts):
opts.get("non_forward_move"),
"--non-forward-move",
)
otherpath = None
if scratchpush:
ui.setconfig("experimental", "infinitepush-scratchpush", True)
oldphasemove = extensions.wrapfunction(
@ -166,6 +169,14 @@ def _push(orig, ui, repo, dest=None, *args, **opts):
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:
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
@ -184,6 +195,21 @@ def _push(orig, ui, repo, dest=None, *args, **opts):
# know about them. Let's save it before push and restore after
remotescratchbookmarks = bookmarks.readremotebookmarks(ui, repo, dest)
result = orig(ui, repo, dest, *args, **opts)
# If an alternate Infinitepush destination is specified, replicate the
# push there. This ensures scratch bookmarks (and their commits) can
# properly be replicated to Mononoke.
if otherpath is not None:
otherdest = otherpath.pushloc or otherpath.loc
if otherdest != dest:
m = _(
"please wait while we replicate this push to an alternate repository\n"
)
ui.warn(m)
# NOTE: We ignore the result here (which only represents whether
# there were changes to land).
orig(ui, repo, otherdest, *args, **opts)
if bookmarks.remotebookmarksenabled(ui):
if bookmark and scratchpush:
other = hg.peer(repo, opts, dest)

View File

@ -0,0 +1,78 @@
$ setconfig extensions.treemanifest=!
Setup the test
$ . "$TESTDIR/library.sh"
$ . "$TESTDIR/infinitepush/library.sh"
$ setupcommon
$ enable infinitepush pushrebase
$ cp "$HGRCPATH" "$TESTTMP/defaulthgrc"
$ hg init repo1
$ cd repo1
$ setupserver
$ cd ..
$ hg init repo2
$ cd repo2
$ setupserver
$ cd ..
$ hg init repo3
$ cd repo3
$ setupserver
$ cd ..
Check that we replicate a push
$ hg clone ssh://user@dummy/repo1 client -q
$ cp "$TESTTMP/defaulthgrc" "$HGRCPATH"
$ cat >> "$HGRCPATH" << EOF
> [paths]
> infinitepush-other=ssh://user@dummy/repo2
> [infinitepush]
> branchpattern=re:scratch/.+
> EOF
$ cd client
$ mkcommit initialcommit
$ hg push -r . --to scratch/test123 --create
pushing to ssh://user@dummy/repo1
searching for changes
remote: pushing 1 commit:
remote: 67145f466344 initialcommit
please wait while we replicate this push to an alternate repository
pushing to ssh://user@dummy/repo2
searching for changes
remote: pushing 1 commit:
remote: 67145f466344 initialcommit
$ cd ..
Check that we do not replicate a push to the same destination
$ hg clone ssh://user@dummy/repo1 client2 -q
$ cp "$TESTTMP/defaulthgrc" "$HGRCPATH"
$ cat >> "$HGRCPATH" << EOF
> [paths]
> infinitepush-other=ssh://user@dummy/repo1
> [infinitepush]
> branchpattern=re:scratch/.+
> EOF
$ cd client2
$ mkcommit initialcommit
$ hg push -r . --to scratch/test123 --create
pushing to ssh://user@dummy/repo1
searching for changes
remote: pushing 1 commit:
remote: 67145f466344 initialcommit
$ cd ..
Check that we do not replicate a push when the destination is set
$ hg clone ssh://user@dummy/repo1 client3 -q
$ cp "$TESTTMP/defaulthgrc" "$HGRCPATH"
$ cat >> "$HGRCPATH" << EOF
> [paths]
> infinitepush-other=ssh://user@dummy/repo2
> [infinitepush]
> branchpattern=re:scratch/.+
> EOF
$ cd client3
$ mkcommit initialcommit
$ hg push ssh://user@dummy/repo3 -r . --to scratch/test123 --create
pushing to ssh://user@dummy/repo3
searching for changes
remote: pushing 1 commit:
remote: 67145f466344 initialcommit
$ cd ..