Skip to content
Snippets Groups Projects
Commit 78cbae27 authored by Dan Villiom Podlaski Christiansen's avatar Dan Villiom Podlaski Christiansen
Browse files

push: abort with an error when no bookmarks or tags exist

Previously, we would simply invent a master bookmark when this
occurred, but in the specific case where the remote is empty. I
believe that's actually unhelpful in the long run: Should a user not
know about bookmarks, the first push will succeed, and subsequent
pushes then not do anything. How did that bookmark get there?

Instead, we should trigger a hard error for this case; that way, we'll
hopefully cause the user to take a step back and find out how the
command really works.
parent 1c9ac8cf
No related branches found
No related tags found
1 merge request!124Adjust initial clone and push behaviour
......@@ -22,7 +22,6 @@
from mercurial.utils import dateutil
from mercurial import (
bookmarks,
commands,
context,
encoding,
error,
......@@ -1177,26 +1176,11 @@
def get_changed_refs(self, refs, exportable, force):
new_refs = refs.copy()
# The remote repo is empty and the local one doesn't have
# bookmarks/tags
#
# (older dulwich versions return the proto-level
# capabilities^{} key when the dict should have been
# empty. That check can probably be removed at some point in
# the future.)
if not refs or next(iter(refs.keys())) == b'capabilities^{}':
if not exportable:
tip = self.repo.filtered(b'served').lookup(b'tip')
if tip != nullid:
if b'capabilities^{}' in new_refs:
del new_refs[b'capabilities^{}']
tip = hex(tip)
commands.bookmark(self.ui, self.repo, b'master',
rev=tip, force=True)
bookmarks.activate(self.repo, b'master')
new_refs[LOCAL_BRANCH_PREFIX + b'master'] = (
self.map_git_get(tip)
)
if not exportable:
raise error.Abort(
b'no bookmarks or tags to push to git',
hint=b'see "hg help bookmarks" for details on creating them',
)
# mapped nodes might be hidden
unfiltered = self.repo.unfiltered()
......
......@@ -19,6 +19,7 @@
$ echo ignored > .gitignore
$ hg add .gitignore
$ hg ci -m ignore
$ hg book master
$ hg push
pushing to $TESTTMP/repo.git
searching for changes
......
......@@ -12,6 +12,7 @@
updating to branch default
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd hgrepo
$ hg book master
Configure an author map
......
......@@ -20,6 +20,7 @@
$ touch alpha
$ hg add alpha
$ fn_hg_commit -m alpha
$ hg book -r . master
$ touch beta
$ hg add beta
$ fn_hg_commit --secret -m beta
......
......@@ -195,8 +195,9 @@
$ hg -R hgrepo2 push gitrepo2
pushing to gitrepo2
searching for changes
no changes found
[1]
abort: no bookmarks or tags to push to git
(see "hg help bookmarks" for details on creating them)
[255]
The remote repo is empty and the local one doesn't have any bookmarks/tags
$ cd hgrepo2
......@@ -209,12 +210,12 @@
$ hg push ../gitrepo2
pushing to ../gitrepo2
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
adding reference refs/heads/master
abort: no bookmarks or tags to push to git
(see "hg help bookmarks" for details on creating them)
[255]
$ hg summary
parent: -1:000000000000 (no revision checked out)
branch: default
commit: (clean)
update: 1 new changesets (update)
phases: 1 draft
......@@ -215,8 +216,8 @@
$ hg summary
parent: -1:000000000000 (no revision checked out)
branch: default
commit: (clean)
update: 1 new changesets (update)
phases: 1 draft
Only one bookmark 'master' should be created
That should not create any bookmarks
$ hg bookmarks
......@@ -222,5 +223,5 @@
$ hg bookmarks
* master 0:8aded40be5af
no bookmarks set
test for ssh vulnerability
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment