# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1503933308 -7200 # Node ID 5c0b6af37b2100ba7157cf2f7678c44426fafe04 # Parent 736ab58641f025b5680346a16958176e723d8ddb 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. diff -r 736ab58641f0 -r 5c0b6af37b21 README --- 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 ------------------- diff -r 736ab58641f0 -r 5c0b6af37b21 hgext3rd/topic/__init__.py --- 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, diff -r 736ab58641f0 -r 5c0b6af37b21 tests/test-topic.t --- 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