From d8f73fb505f8a14a4f9f0d9088ce1ae917cbd4d8 Mon Sep 17 00:00:00 2001 From: Ryan McElroy Date: Wed, 11 Feb 2015 19:54:34 -0800 Subject: [PATCH] push: properly limit anonymous heads --- remotenames.py | 37 ++++++++++++++++++++----------------- tests/test-pushto.t | 26 ++++++++++++++++++++------ 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/remotenames.py b/remotenames.py index 899f916bcc..7a9cd5b06a 100644 --- a/remotenames.py +++ b/remotenames.py @@ -203,25 +203,28 @@ def expushdiscoverybookmarks(pushop): remotemarks = pushop.remote.listkeys('bookmarks') if not _pushto and not repo.ui.configbool('remotenames', 'pushanonheads'): - # simple check to make sure we don't push an anonymous head - revs = pushop.revs - if revs: - revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)] + # check to make sure we don't push an anonymous head + if pushop.revs: + revs = set(repo.lookup(r) for r in scmutil.revrange(repo, pushop.revs)) else: - revs = [repo.lookup('.')] - # first rev should be the head; later we should use revsets - rev = repo[revs[0]] - localonly = [b for b in rev.bookmarks() if b not in remotemarks] - if localonly: - for chead in pushop.commonheads: - if rev != repo[chead] and repo[chead].descendant(rev): - msg = _("push creates new anonymous head without " - "the bookmark: '%s'") % localonly[0] - hint = _("use 'hg push -B %s' to create a " - "new remote bookmark") % localonly[0] - raise util.Abort(msg, hint=hint) - if not _pushto: + revs = set(repo.lookup(r) for r in repo.revs('head()')) + # find heads that don't have a bookmark going with them + for bookmark in pushop.bookmarks: + rev = repo.lookup(bookmark) + if rev in revs: + revs.remove(rev) + # remove heads that already have a remote bookmark + for bookmark, node in remotemarks.iteritems(): + rev = repo.lookup(node) + if rev in revs: + revs.remove(rev) + if revs: + msg = _("push would create new anonymous heads (%s)" % + ', '.join([short(r) for r in revs])) + hint = _("use 'hg push --to NAME' to create a new remote bookmark") + raise util.Abort(msg, hint=hint) + if not _pushto: return exchange._pushdiscoverybookmarks(pushop) rev, bookmark, force = _pushto diff --git a/tests/test-pushto.t b/tests/test-pushto.t index 5a701e5dde..849cb6fe76 100644 --- a/tests/test-pushto.t +++ b/tests/test-pushto.t @@ -4,12 +4,7 @@ Set up extension and repos $ echo "publish = False" >> $HGRCPATH $ echo "[extensions]" >> $HGRCPATH $ echo "remotenames=$(dirname $TESTDIR)/remotenames.py" >> $HGRCPATH - $ echo "[remotenames]" >> $HGRCPATH - $ echo "forceto = True" >> $HGRCPATH $ hg init repo1 - -Test that forceto works - $ hg clone repo1 repo2 updating to branch default 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -21,6 +16,25 @@ Test that anonymous heads are disallowed by default $ hg add a $ hg commit -m a $ hg push + pushing to $TESTTMP/repo1 + searching for changes + abort: push would create new anonymous heads (cb9a9f314b8b) + (use 'hg push --to NAME' to create a new remote bookmark) + [255] + $ echo "[remotenames]" >> $HGRCPATH + $ echo "pushanonheads = True" >> $HGRCPATH + $ hg push + pushing to $TESTTMP/repo1 + searching for changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files + +Test that forceto works + + $ echo "forceto = True" >> $HGRCPATH + $ hg push abort: config requires --to when pushing [255] @@ -51,7 +65,7 @@ Test that --force is required to create new bookmarks adding changesets adding manifests adding file changes - added 2 changesets with 2 changes to 1 files + added 1 changesets with 1 changes to 1 files exporting bookmark @ Test that --force is required to move bookmarks to odd locations