Mercurial > public > mercurial-scm > hg-stable
diff mercurial/commands.py @ 39303:337443f09fc8
bookmark: add an --active flag to display the active bookmark
There is currently no official simple way to retrieve the current bookmark. In
particular for automation.
We add a `--active` flag to the `hg bookmarks` command. When set, the command
display the current bookmark name if any or return 1.
For now, this flag is read-only. However sensible combinations exist with
`--delete`, `--rename` and `--rev` and can be implemented later.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Thu, 16 Aug 2018 17:19:27 +0200 |
parents | 1ea6772fb415 |
children | 3fec8aa9b454 |
line wrap: on
line diff
--- a/mercurial/commands.py Thu Aug 23 01:48:39 2018 +0200 +++ b/mercurial/commands.py Thu Aug 16 17:19:27 2018 +0200 @@ -901,6 +901,7 @@ ('d', 'delete', False, _('delete a given bookmark')), ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), ('i', 'inactive', False, _('mark a bookmark inactive')), + ('', 'active', False, _('display the active bookmark')), ] + formatteropts, _('hg bookmarks [OPTIONS]... [NAME]...')) def bookmark(ui, repo, *names, **opts): @@ -927,6 +928,10 @@ A bookmark named '@' has the special property that :hg:`clone` will check it out by default if it exists. + The '--active' flag will display the current bookmark or return non-zero, + if combined with other action, they will be performed on the active + bookmark. + .. container:: verbose Examples: @@ -956,6 +961,7 @@ delete = opts.get(r'delete') rename = opts.get(r'rename') inactive = opts.get(r'inactive') + active = opts.get(r'active') if delete and rename: raise error.Abort(_("--delete and --rename are incompatible")) @@ -963,6 +969,16 @@ raise error.Abort(_("--rev is incompatible with --delete")) if rename and rev: raise error.Abort(_("--rev is incompatible with --rename")) + if delete and active: + raise error.Abort(_("--delete is incompatible with --active")) + if rev and active: + raise error.Abort(_("--rev is incompatible with --active")) + if rename and active: + raise error.Abort(_("--rename is incompatible with --active")) + if names and active: + raise error.Abort(_("NAMES is incompatible with --active")) + if inactive and active: + raise error.Abort(_("--inactive is incompatible with --active")) if not names and (delete or rev): raise error.Abort(_("bookmark name required")) @@ -987,6 +1003,11 @@ ui.status(_("no active bookmark\n")) else: bookmarks.deactivate(repo) + elif active: + book = repo._activebookmark + if book is None: + return 1 + ui.write("%s\n" % book, label=bookmarks.activebookmarklabel) else: # show bookmarks bookmarks.printbookmarks(ui, repo, **opts)