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

login
register
mail settings
Submitter Ryan McElroy
Date Feb. 19, 2018, 11:53 a.m.
Message ID <50ca5e43b0b816aeabcf.1519041220@devbig314.prn1.facebook.com>
Download mbox | patch
Permalink /patch/28151/
State New
Headers show

Comments

Ryan McElroy - Feb. 19, 2018, 11:53 a.m.
# HG changeset patch
# User Ryan McElroy <rmcelroy@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.

Patch

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]
+