[PATCH 3 of 6 remotenames-ext] discovery: do not crash if no bookmarks are passed to push discovery

Ryan McElroy rm at fb.com
Mon Feb 19 06:53:40 EST 2018


# HG changeset patch
# User Ryan McElroy <rmcelroy at fb.com>
# Date 1519041052 28800
#      Mon Feb 19 03:50:52 2018 -0800
# Node ID 50ca5e43b0b816aeabcfd50b09dd9728c02dac86
# Parent  7cee78e9b823b9671cbfff28086a0cb914a2edf0
discovery: do not crash if no bookmarks are passed to push discovery

Today, there are cases where this function will be called but bookmarks
will not have been populated. We will eliminate one of these paths next,
but for safety, let's make sure we abort gracefully rather than with a
stacktrace by referencing something that does not exist.

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -891,6 +891,11 @@ def expushdiscoverybookmarks(pushop):
                 raise error.Abort(msg % ', '.join(sorted(anonheads)), hint=hint)
         return ret
 
+    # in this path, we have a push --to command
+    if not len(pushop.bookmarks):
+        # if there are no bookmarks, something went wrong. bail gracefully.
+        raise error.Abort('no bookmark found to push')
+
     bookmark = pushop.bookmarks[0]
     rev = pushop.revs[0]
 
diff --git a/tests/test-remotenames-pushto-pathandname.t b/tests/test-remotenames-pushto-pathandname.t
--- a/tests/test-remotenames-pushto-pathandname.t
+++ b/tests/test-remotenames-pushto-pathandname.t
@@ -42,3 +42,12 @@ Try to do the right push
   added 1 changesets with 1 changes to 1 files
   updating bookmark ababagalamaga
 
+Set up an svn default push path and test behavior
+
+  $ hg paths --add default-push svn+ssh://nowhere/in/particular
+  $ hg push --to foo ../orig
+  pushing rev 71b4c8f22183 to destination ../orig bookmark foo
+  searching for changes
+  abort: no bookmark found to push
+  [255]
+


More information about the Mercurial-devel mailing list