changeset 31859:8e282aa3c3ff

show: fix corrupt json output with no bookmarks
author Ryan McElroy <rmcelroy@fb.com>
date Fri, 07 Apr 2017 10:46:32 -0700
parents ad366d57d574
children 56f58027a513
files hgext/show.py tests/test-show.t
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/show.py	Fri Apr 07 10:26:13 2017 -0700
+++ b/hgext/show.py	Fri Apr 07 10:46:32 2017 -0700
@@ -19,6 +19,7 @@
     cmdutil,
     commands,
     error,
+    formatter,
     pycompat,
     registrar,
 )
@@ -109,8 +110,11 @@
     """bookmarks and their associated changeset"""
     marks = repo._bookmarks
     if not len(marks):
-        # TODO json output is corrupted; consider using formatter
-        ui.write(_('(no bookmarks set)\n'))
+        # This is a bit hacky. Ideally, templates would have a way to
+        # specify an empty output, but we shouldn't corrupt JSON while
+        # waiting for this functionality.
+        if not isinstance(fm, formatter.jsonformatter):
+            ui.write(_('(no bookmarks set)\n'))
         return
 
     active = repo._activebookmark
--- a/tests/test-show.t	Fri Apr 07 10:26:13 2017 -0700
+++ b/tests/test-show.t	Fri Apr 07 10:46:32 2017 -0700
@@ -114,4 +114,12 @@
    }
   ]
 
+JSON works with no bookmarks
+
+  $ hg book -d a-longer-bookmark
+  $ hg book -d book1
+  $ hg show bookmarks -T json
+  [
+  ]
+
   $ cd ..