push: properly limit anonymous heads

This commit is contained in:
Ryan McElroy 2015-02-11 19:54:34 -08:00
parent dfcaf81724
commit d8f73fb505
2 changed files with 40 additions and 23 deletions

View File

@ -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

View File

@ -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