infinitepush: handle remotenames hoisting correctly

Summary:
There was a report from an infinitepush user who complained about
`hg update remote/scratch/book` failing to pull the bookmark, while
`hg update scratch/book` pulling fine. It confuses users because they see
`remote/scratch/book` in smartlog.

On the other hand let's not allow `hg pull -B remote/scratch/book` to stay
consistent with remotenames.

Test Plan: Slowly run tests

Reviewers: #fbhgext, ryanmce

Reviewed By: #fbhgext, ryanmce

Subscribers: ryanmce

Differential Revision: https://phab.mercurial-scm.org/D172
This commit is contained in:
Stanislau Hlebik 2017-07-21 08:19:59 -07:00
parent 886a31ce5a
commit 3ea83ba4bc
2 changed files with 59 additions and 1 deletions

View File

@ -179,6 +179,21 @@ def _getloglevel(ui):
raise error.Abort(_('invalid log level %s') % loglevel)
return numeric_loglevel
def _tryhoist(ui, remotebookmark):
'''returns a bookmarks with hoisted part removed
Remotenames extension has a 'hoist' config that allows to use remote
bookmarks without specifying remote path. For example, 'hg update master'
works as well as 'hg update remote/master'. We want to allow the same in
infinitepush.
'''
if common.isremotebooksenabled(ui):
hoist = ui.config('remotenames', 'hoist', 'default') + '/'
if remotebookmark.startswith(hoist):
return remotebookmark[len(hoist):]
return remotebookmark
class bundlestore(object):
def __init__(self, repo):
self._repo = repo
@ -590,6 +605,7 @@ def _update(orig, ui, repo, node=None, rev=None, **opts):
if not opts.get('date') and (rev or node) not in repo:
mayberemote = rev or node
mayberemote = _tryhoist(ui, mayberemote)
dopull = False
kwargs = {}
if _scratchbranchmatcher(mayberemote):
@ -602,7 +618,7 @@ def _update(orig, ui, repo, node=None, rev=None, **opts):
if dopull:
ui.warn(
_("'%s' does not exist locally - looking for it " +
"remotely...\n") % mayberemote)
"remotely...\n") % mayberemote)
# Try pulling node from remote repo
try:
cmdname = '^pull'

View File

@ -180,3 +180,45 @@ Try to push with remotebookmarks disabled
remote: 36667a3f76e4 newscratch
$ hg book
scratch/secondbranch 2:36667a3f76e4
Create new bookmark and try to pull it
$ mkcommit newcommittoupdate1
$ hg push -q -r . --to scratch/branchtoupdateto1 --create
$ hg up -q ".^"
$ mkcommit newcommittoupdate2
created new head
$ hg push -q -r . --to scratch/branchtoupdateto2 --create
$ hg up -q ".^"
$ mkcommit newcommittopull
created new head
$ hg push -q -r . --to scratch/branchtopull --create
$ cd ../client
$ hg up default/scratch/branchtoupdateto1
'scratch/branchtoupdateto1' does not exist locally - looking for it remotely...
pulling from ssh://user@dummy/repo
searching for changes
adding changesets
adding manifests
adding file changes
added 2 changesets with 2 changes to 2 files (+1 heads)
(run 'hg heads .' to see heads, 'hg merge' to merge)
'scratch/branchtoupdateto1' found remotely
2 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ cat >> $HGRCPATH << EOF
> [remotenames]
> hoist=remote
> rename.default=remote
> EOF
$ hg up remote/scratch/branchtoupdateto2
'scratch/branchtoupdateto2' does not exist locally - looking for it remotely...
pulling from ssh://user@dummy/repo
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 2 files (+1 heads)
(run 'hg heads .' to see heads, 'hg merge' to merge)
'scratch/branchtoupdateto2' found remotely
1 files updated, 0 files merged, 1 files removed, 0 files unresolved