##// END OF EJS Templates
bookmarks: refactor option checking to pick one from --delete/rename/active
Yuya Nishihara -
r39784:78ee63c7 default
parent child Browse files
Show More
@@ -961,36 +961,33 b' def bookmark(ui, repo, *names, **opts):'
961 opts = pycompat.byteskwargs(opts)
961 opts = pycompat.byteskwargs(opts)
962 force = opts.get('force')
962 force = opts.get('force')
963 rev = opts.get('rev')
963 rev = opts.get('rev')
964 delete = opts.get('delete')
965 rename = opts.get('rename')
964 rename = opts.get('rename')
966 inactive = opts.get('inactive')
965 inactive = opts.get('inactive')
967 active = opts.get('active')
966
968
967 selactions = [k for k in ['delete', 'rename', 'active'] if opts.get(k)]
969 if delete and rename:
968 if len(selactions) > 1:
970 raise error.Abort(_("--delete and --rename are incompatible"))
969 raise error.Abort(_('--%s and --%s are incompatible')
971 if delete and rev:
970 % tuple(selactions[:2]))
972 raise error.Abort(_("--rev is incompatible with --delete"))
971 if selactions:
973 if rename and rev:
972 action = selactions[0]
974 raise error.Abort(_("--rev is incompatible with --rename"))
973 else:
975 if delete and active:
974 action = None
976 raise error.Abort(_("--delete is incompatible with --active"))
975
977 if rev and active:
976 if rev and action in {'delete', 'rename', 'active'}:
978 raise error.Abort(_("--rev is incompatible with --active"))
977 raise error.Abort(_("--rev is incompatible with --%s") % action)
979 if rename and active:
978 if names and action == 'active':
980 raise error.Abort(_("--rename is incompatible with --active"))
981 if names and active:
982 raise error.Abort(_("NAMES is incompatible with --active"))
979 raise error.Abort(_("NAMES is incompatible with --active"))
983 if inactive and active:
980 if inactive and action == 'active':
984 raise error.Abort(_("--inactive is incompatible with --active"))
981 raise error.Abort(_("--inactive is incompatible with --active"))
985 if not names and (delete or rev):
982 if not names and (action == 'delete' or rev):
986 raise error.Abort(_("bookmark name required"))
983 raise error.Abort(_("bookmark name required"))
987
984
988 if delete or rename or names or inactive:
985 if action in {'delete', 'rename'} or names or inactive:
989 with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr:
986 with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr:
990 if delete:
987 if action == 'delete':
991 names = pycompat.maplist(repo._bookmarks.expandname, names)
988 names = pycompat.maplist(repo._bookmarks.expandname, names)
992 bookmarks.delete(repo, tr, names)
989 bookmarks.delete(repo, tr, names)
993 elif rename:
990 elif action == 'rename':
994 if not names:
991 if not names:
995 raise error.Abort(_("new bookmark name required"))
992 raise error.Abort(_("new bookmark name required"))
996 elif len(names) > 1:
993 elif len(names) > 1:
@@ -1006,7 +1003,7 b' def bookmark(ui, repo, *names, **opts):'
1006 ui.status(_("no active bookmark\n"))
1003 ui.status(_("no active bookmark\n"))
1007 else:
1004 else:
1008 bookmarks.deactivate(repo)
1005 bookmarks.deactivate(repo)
1009 elif active:
1006 elif action == 'active':
1010 book = repo._activebookmark
1007 book = repo._activebookmark
1011 if book is None:
1008 if book is None:
1012 return 1
1009 return 1
General Comments 0
You need to be logged in to leave comments. Login now