Mercurial > public > mercurial-scm > hg-stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
39302:b17d27ea61fb | 39303:337443f09fc8 |
---|---|
899 [('f', 'force', False, _('force')), | 899 [('f', 'force', False, _('force')), |
900 ('r', 'rev', '', _('revision for bookmark action'), _('REV')), | 900 ('r', 'rev', '', _('revision for bookmark action'), _('REV')), |
901 ('d', 'delete', False, _('delete a given bookmark')), | 901 ('d', 'delete', False, _('delete a given bookmark')), |
902 ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), | 902 ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), |
903 ('i', 'inactive', False, _('mark a bookmark inactive')), | 903 ('i', 'inactive', False, _('mark a bookmark inactive')), |
904 ('', 'active', False, _('display the active bookmark')), | |
904 ] + formatteropts, | 905 ] + formatteropts, |
905 _('hg bookmarks [OPTIONS]... [NAME]...')) | 906 _('hg bookmarks [OPTIONS]... [NAME]...')) |
906 def bookmark(ui, repo, *names, **opts): | 907 def bookmark(ui, repo, *names, **opts): |
907 '''create a new bookmark or list existing bookmarks | 908 '''create a new bookmark or list existing bookmarks |
908 | 909 |
924 Specifying bookmark as '.' to -m or -d options is equivalent to specifying | 925 Specifying bookmark as '.' to -m or -d options is equivalent to specifying |
925 the active bookmark's name. | 926 the active bookmark's name. |
926 | 927 |
927 A bookmark named '@' has the special property that :hg:`clone` will | 928 A bookmark named '@' has the special property that :hg:`clone` will |
928 check it out by default if it exists. | 929 check it out by default if it exists. |
930 | |
931 The '--active' flag will display the current bookmark or return non-zero, | |
932 if combined with other action, they will be performed on the active | |
933 bookmark. | |
929 | 934 |
930 .. container:: verbose | 935 .. container:: verbose |
931 | 936 |
932 Examples: | 937 Examples: |
933 | 938 |
954 force = opts.get(r'force') | 959 force = opts.get(r'force') |
955 rev = opts.get(r'rev') | 960 rev = opts.get(r'rev') |
956 delete = opts.get(r'delete') | 961 delete = opts.get(r'delete') |
957 rename = opts.get(r'rename') | 962 rename = opts.get(r'rename') |
958 inactive = opts.get(r'inactive') | 963 inactive = opts.get(r'inactive') |
964 active = opts.get(r'active') | |
959 | 965 |
960 if delete and rename: | 966 if delete and rename: |
961 raise error.Abort(_("--delete and --rename are incompatible")) | 967 raise error.Abort(_("--delete and --rename are incompatible")) |
962 if delete and rev: | 968 if delete and rev: |
963 raise error.Abort(_("--rev is incompatible with --delete")) | 969 raise error.Abort(_("--rev is incompatible with --delete")) |
964 if rename and rev: | 970 if rename and rev: |
965 raise error.Abort(_("--rev is incompatible with --rename")) | 971 raise error.Abort(_("--rev is incompatible with --rename")) |
972 if delete and active: | |
973 raise error.Abort(_("--delete is incompatible with --active")) | |
974 if rev and active: | |
975 raise error.Abort(_("--rev is incompatible with --active")) | |
976 if rename and active: | |
977 raise error.Abort(_("--rename is incompatible with --active")) | |
978 if names and active: | |
979 raise error.Abort(_("NAMES is incompatible with --active")) | |
980 if inactive and active: | |
981 raise error.Abort(_("--inactive is incompatible with --active")) | |
966 if not names and (delete or rev): | 982 if not names and (delete or rev): |
967 raise error.Abort(_("bookmark name required")) | 983 raise error.Abort(_("bookmark name required")) |
968 | 984 |
969 if delete or rename or names or inactive: | 985 if delete or rename or names or inactive: |
970 with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: | 986 with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: |
985 ui.status(_("no bookmarks set\n")) | 1001 ui.status(_("no bookmarks set\n")) |
986 elif not repo._activebookmark: | 1002 elif not repo._activebookmark: |
987 ui.status(_("no active bookmark\n")) | 1003 ui.status(_("no active bookmark\n")) |
988 else: | 1004 else: |
989 bookmarks.deactivate(repo) | 1005 bookmarks.deactivate(repo) |
1006 elif active: | |
1007 book = repo._activebookmark | |
1008 if book is None: | |
1009 return 1 | |
1010 ui.write("%s\n" % book, label=bookmarks.activebookmarklabel) | |
990 else: # show bookmarks | 1011 else: # show bookmarks |
991 bookmarks.printbookmarks(ui, repo, **opts) | 1012 bookmarks.printbookmarks(ui, repo, **opts) |
992 | 1013 |
993 @command('branch', | 1014 @command('branch', |
994 [('f', 'force', None, | 1015 [('f', 'force', None, |