topics: add a current flag to display current topic
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 28 Aug 2017 17:15:08 +0200
changeset 2867 5c0b6af37b21
parent 2866 736ab58641f0
child 2868 e46b68547017
topics: add a current flag to display current topic This patch adds a current flag which can be used by user to display the current topic.
README
hgext3rd/topic/__init__.py
tests/test-topic.t
--- a/README	Mon Aug 28 17:10:41 2017 +0200
+++ b/README	Mon Aug 28 17:15:08 2017 +0200
@@ -121,6 +121,11 @@
 Changelog
 =========
 
+6.7.0 - in progress
+-------------------
+
+  * topic: gain a --current flag
+
 6.6.0 -- 2017-07-25
 -------------------
 
--- a/hgext3rd/topic/__init__.py	Mon Aug 28 17:10:41 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Mon Aug 28 17:15:08 2017 +0200
@@ -312,6 +312,7 @@
         ('r', 'rev', '', 'revset of existing revisions', _('REV')),
         ('l', 'list', False, 'show the stack of changeset in the topic'),
         ('', 'age', False, 'show when you last touched the topics'),
+        ('', 'current', None, 'display the current topic only'),
     ] + commands.formatteropts,
     _('hg topics [TOPIC]'))
 def topics(ui, repo, topic='', clear=False, rev=None, list=False, **opts):
@@ -338,6 +339,13 @@
     The active topic (if any) will be prepended with a "*".
 
     The --verbose version of this command display various information on the state of each topic."""
+
+    current = opts.get('current')
+    if current and topic:
+        raise error.Abort(_("cannot use --current when setting a topic"))
+    if current and clear:
+        raise error.Abort(_("cannot use --current and --clear"))
+
     if list:
         if clear or rev:
             raise error.Abort(_("cannot use --clear or --rev with --list"))
@@ -375,7 +383,21 @@
     if topic:
         return _changecurrenttopic(repo, topic)
 
-    _listtopics(ui, repo, opts)
+    # `hg topic --current`
+    ret = 0
+    if current and not repo.currenttopic:
+        ui.write_err(_('no active topic\n'))
+        ret = 1
+    elif current:
+        fm = ui.formatter('topic', opts)
+        namemask = '%s\n'
+        label = 'topic.active'
+        fm.startitem()
+        fm.write('topic', namemask, repo.currenttopic, label=label)
+        fm.end()
+    else:
+        _listtopics(ui, repo, opts)
+    return ret
 
 @command('stack', [
     ] + commands.formatteropts,
--- a/tests/test-topic.t	Mon Aug 28 17:10:41 2017 +0200
+++ b/tests/test-topic.t	Mon Aug 28 17:15:08 2017 +0200
@@ -47,6 +47,7 @@
    -r --rev REV revset of existing revisions
    -l --list    show the stack of changeset in the topic
       --age     show when you last touched the topics
+      --current display the current topic only
   
   (some details hidden, use --verbose to show complete help)
   $ hg topics
@@ -72,6 +73,15 @@
 
 Still no topics
   $ hg topics
+  $ hg topics --current
+  no active topic
+  [1]
+  $ hg topics --current somerandomtopic
+  abort: cannot use --current when setting a topic
+  [255]
+  $ hg topics --current --clear
+  abort: cannot use --current and --clear
+  [255]
 
 Test commit flag and help text
 
@@ -104,6 +114,8 @@
   $ hg topics
    * fran
      narf
+  $ hg topics --current
+  fran
   $ echo >> fran work >> beta
   $ hg ci -m 'start on fran'
   $ hg co narf