--- a/hgext/githelp.py Sat Oct 05 10:29:34 2019 -0400
+++ b/hgext/githelp.py Sun Oct 06 09:45:02 2019 -0400
@@ -29,9 +29,7 @@
registrar,
scmutil,
)
-from mercurial.utils import (
- procutil,
-)
+from mercurial.utils import procutil
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
@@ -42,6 +40,7 @@
cmdtable = {}
command = registrar.command(cmdtable)
+
def convert(s):
if s.startswith("origin/"):
return s[7:]
@@ -51,30 +50,37 @@
s = re.sub('~$', '~1', s)
return s
-@command('githelp|git', [
- ], _('hg githelp'),
- helpcategory=command.CATEGORY_HELP, helpbasic=True)
+
+@command(
+ 'githelp|git',
+ [],
+ _('hg githelp'),
+ helpcategory=command.CATEGORY_HELP,
+ helpbasic=True,
+)
def githelp(ui, repo, *args, **kwargs):
'''suggests the Mercurial equivalent of the given git command
Usage: hg githelp -- <git command>
'''
- if len(args) == 0 or (len(args) == 1 and args[0] =='git'):
- raise error.Abort(_('missing git command - '
- 'usage: hg githelp -- <git command>'))
+ if len(args) == 0 or (len(args) == 1 and args[0] == 'git'):
+ raise error.Abort(
+ _('missing git command - ' 'usage: hg githelp -- <git command>')
+ )
if args[0] == 'git':
args = args[1:]
cmd = args[0]
if not cmd in gitcommands:
- raise error.Abort(_("error: unknown git command %s") % (cmd))
+ raise error.Abort(_("error: unknown git command %s") % cmd)
ui.pager('githelp')
args = args[1:]
return gitcommands[cmd](ui, repo, *args, **kwargs)
+
def parseoptions(ui, cmdoptions, args):
cmdoptions = list(cmdoptions)
opts = {}
@@ -91,24 +97,32 @@
elif (r'-' + ex.opt) in ex.msg:
flag = '-' + pycompat.bytestr(ex.opt)
else:
- raise error.Abort(_("unknown option %s") %
- pycompat.bytestr(ex.opt))
+ raise error.Abort(
+ _("unknown option %s") % pycompat.bytestr(ex.opt)
+ )
try:
args.remove(flag)
except Exception:
msg = _("unknown option '%s' packed with other options")
hint = _("please try passing the option as its own flag: -%s")
- raise error.Abort(msg % pycompat.bytestr(ex.opt),
- hint=hint % pycompat.bytestr(ex.opt))
+ raise error.Abort(
+ msg % pycompat.bytestr(ex.opt),
+ hint=hint % pycompat.bytestr(ex.opt),
+ )
ui.warn(_("ignoring unknown option %s\n") % flag)
args = list([convert(x) for x in args])
- opts = dict([(k, convert(v)) if isinstance(v, str) else (k, v)
- for k, v in opts.iteritems()])
+ opts = dict(
+ [
+ (k, convert(v)) if isinstance(v, str) else (k, v)
+ for k, v in opts.iteritems()
+ ]
+ )
return args, opts
+
class Command(object):
def __init__(self, name):
self.name = name
@@ -149,6 +163,7 @@
def __and__(self, other):
return AndCommand(self, other)
+
class AndCommand(object):
def __init__(self, left, right):
self.left = left
@@ -160,6 +175,7 @@
def __and__(self, other):
return AndCommand(self, other)
+
def add(ui, repo, *args, **kwargs):
cmdoptions = [
('A', 'all', None, ''),
@@ -167,9 +183,13 @@
]
args, opts = parseoptions(ui, cmdoptions, args)
- if (opts.get('patch')):
- ui.status(_("note: Mercurial will commit when complete, "
- "as there is no staging area in Mercurial\n\n"))
+ if opts.get('patch'):
+ ui.status(
+ _(
+ "note: Mercurial will commit when complete, "
+ "as there is no staging area in Mercurial\n\n"
+ )
+ )
cmd = Command('commit --interactive')
else:
cmd = Command("add")
@@ -177,18 +197,23 @@
if not opts.get('all'):
cmd.extend(args)
else:
- ui.status(_("note: use hg addremove to remove files that have "
- "been deleted\n\n"))
+ ui.status(
+ _(
+ "note: use hg addremove to remove files that have "
+ "been deleted\n\n"
+ )
+ )
ui.status((bytes(cmd)), "\n")
+
def am(ui, repo, *args, **kwargs):
- cmdoptions=[
- ]
+ cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
cmd = Command('import')
ui.status(bytes(cmd), "\n")
+
def apply(ui, repo, *args, **kwargs):
cmdoptions = [
('p', 'p', int, ''),
@@ -197,7 +222,7 @@
args, opts = parseoptions(ui, cmdoptions, args)
cmd = Command('import --no-commit')
- if (opts.get('p')):
+ if opts.get('p'):
cmd['-p'] = opts.get('p')
if opts.get('directory'):
cmd['--prefix'] = opts.get('directory')
@@ -205,17 +230,19 @@
ui.status((bytes(cmd)), "\n")
+
def bisect(ui, repo, *args, **kwargs):
ui.status(_("see 'hg help bisect' for how to use bisect\n\n"))
+
def blame(ui, repo, *args, **kwargs):
- cmdoptions = [
- ]
+ cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
cmd = Command('annotate -udl')
cmd.extend([convert(v) for v in args])
ui.status((bytes(cmd)), "\n")
+
def branch(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'set-upstream', None, ''),
@@ -259,6 +286,7 @@
cmd.append(args[0])
ui.status((bytes(cmd)), "\n")
+
def ispath(repo, string):
"""
The first argument to git checkout can either be a revision or a path. Let's
@@ -287,6 +315,7 @@
return didexist
+
def checkout(ui, repo, *args, **kwargs):
cmdoptions = [
('b', 'branch', '', ''),
@@ -297,7 +326,7 @@
paths = []
if '--' in args:
sepindex = args.index('--')
- paths.extend(args[sepindex + 1:])
+ paths.extend(args[sepindex + 1 :])
args = args[:sepindex]
args, opts = parseoptions(ui, cmdoptions, args)
@@ -350,6 +379,7 @@
ui.status((bytes(cmd)), "\n")
+
def cherrypick(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'continue', None, ''),
@@ -372,6 +402,7 @@
ui.status((bytes(cmd)), "\n")
+
def clean(ui, repo, *args, **kwargs):
cmdoptions = [
('d', 'd', None, ''),
@@ -387,6 +418,7 @@
ui.status((bytes(cmd)), "\n")
+
def clone(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'bare', None, ''),
@@ -405,8 +437,12 @@
if opts.get('bare'):
cmd['-U'] = None
- ui.status(_("note: Mercurial does not have bare clones. "
- "-U will clone the repo without checking out a commit\n\n"))
+ ui.status(
+ _(
+ "note: Mercurial does not have bare clones. "
+ "-U will clone the repo without checking out a commit\n\n"
+ )
+ )
elif opts.get('no_checkout'):
cmd['-U'] = None
@@ -417,6 +453,7 @@
ui.status((bytes(cmd)), "\n")
+
def commit(ui, repo, *args, **kwargs):
cmdoptions = [
('a', 'all', None, ''),
@@ -448,9 +485,13 @@
cmd['-m'] = "'%s'" % (opts.get('message'),)
if opts.get('all'):
- ui.status(_("note: Mercurial doesn't have a staging area, "
- "so there is no --all. -A will add and remove files "
- "for you though.\n\n"))
+ ui.status(
+ _(
+ "note: Mercurial doesn't have a staging area, "
+ "so there is no --all. -A will add and remove files "
+ "for you though.\n\n"
+ )
+ )
if opts.get('file'):
cmd['-l'] = opts.get('file')
@@ -465,9 +506,15 @@
ui.status((bytes(cmd)), "\n")
+
def deprecated(ui, repo, *args, **kwargs):
- ui.warn(_('this command has been deprecated in the git project, '
- 'thus isn\'t supported by this tool\n\n'))
+ ui.warn(
+ _(
+ 'this command has been deprecated in the git project, '
+ 'thus isn\'t supported by this tool\n\n'
+ )
+ )
+
def diff(ui, repo, *args, **kwargs):
cmdoptions = [
@@ -480,8 +527,12 @@
cmd = Command('diff')
if opts.get('cached'):
- ui.status(_('note: Mercurial has no concept of a staging area, '
- 'so --cached does nothing\n\n'))
+ ui.status(
+ _(
+ 'note: Mercurial has no concept of a staging area, '
+ 'so --cached does nothing\n\n'
+ )
+ )
if opts.get('reverse'):
cmd['--reverse'] = None
@@ -496,14 +547,20 @@
ui.status((bytes(cmd)), "\n")
+
def difftool(ui, repo, *args, **kwargs):
- ui.status(_('Mercurial does not enable external difftool by default. You '
- 'need to enable the extdiff extension in your .hgrc file by adding\n'
- 'extdiff =\n'
- 'to the [extensions] section and then running\n\n'
- 'hg extdiff -p <program>\n\n'
- 'See \'hg help extdiff\' and \'hg help -e extdiff\' for more '
- 'information.\n'))
+ ui.status(
+ _(
+ 'Mercurial does not enable external difftool by default. You '
+ 'need to enable the extdiff extension in your .hgrc file by adding\n'
+ 'extdiff =\n'
+ 'to the [extensions] section and then running\n\n'
+ 'hg extdiff -p <program>\n\n'
+ 'See \'hg help extdiff\' and \'hg help -e extdiff\' for more '
+ 'information.\n'
+ )
+ )
+
def fetch(ui, repo, *args, **kwargs):
cmdoptions = [
@@ -517,10 +574,14 @@
if len(args) > 0:
cmd.append(args[0])
if len(args) > 1:
- ui.status(_("note: Mercurial doesn't have refspecs. "
- "-r can be used to specify which commits you want to "
- "pull. -B can be used to specify which bookmark you "
- "want to pull.\n\n"))
+ ui.status(
+ _(
+ "note: Mercurial doesn't have refspecs. "
+ "-r can be used to specify which commits you want to "
+ "pull. -B can be used to specify which bookmark you "
+ "want to pull.\n\n"
+ )
+ )
for v in args[1:]:
if v in repo._bookmarks:
cmd['-B'] = v
@@ -529,9 +590,9 @@
ui.status((bytes(cmd)), "\n")
+
def grep(ui, repo, *args, **kwargs):
- cmdoptions = [
- ]
+ cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
cmd = Command('grep')
@@ -542,9 +603,9 @@
ui.status((bytes(cmd)), "\n")
+
def init(ui, repo, *args, **kwargs):
- cmdoptions = [
- ]
+ cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
cmd = Command('init')
@@ -554,6 +615,7 @@
ui.status((bytes(cmd)), "\n")
+
def log(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'follow', None, ''),
@@ -568,10 +630,18 @@
('p', 'patch', None, ''),
]
args, opts = parseoptions(ui, cmdoptions, args)
- ui.status(_('note: -v prints the entire commit message like Git does. To '
- 'print just the first line, drop the -v.\n\n'))
- ui.status(_("note: see hg help revset for information on how to filter "
- "log output\n\n"))
+ ui.status(
+ _(
+ 'note: -v prints the entire commit message like Git does. To '
+ 'print just the first line, drop the -v.\n\n'
+ )
+ )
+ ui.status(
+ _(
+ "note: see hg help revset for information on how to filter "
+ "log output\n\n"
+ )
+ )
cmd = Command('log')
cmd['-v'] = None
@@ -590,13 +660,21 @@
if opts.get('pretty') or opts.get('format') or opts.get('oneline'):
format = opts.get('format', '')
if 'format:' in format:
- ui.status(_("note: --format format:??? equates to Mercurial's "
- "--template. See hg help templates for more info.\n\n"))
+ ui.status(
+ _(
+ "note: --format format:??? equates to Mercurial's "
+ "--template. See hg help templates for more info.\n\n"
+ )
+ )
cmd['--template'] = '???'
else:
- ui.status(_("note: --pretty/format/oneline equate to Mercurial's "
- "--style or --template. See hg help templates for "
- "more info.\n\n"))
+ ui.status(
+ _(
+ "note: --pretty/format/oneline equate to Mercurial's "
+ "--style or --template. See hg help templates for "
+ "more info.\n\n"
+ )
+ )
cmd['--style'] = '???'
if len(args) > 0:
@@ -608,6 +686,7 @@
ui.status((bytes(cmd)), "\n")
+
def lsfiles(ui, repo, *args, **kwargs):
cmdoptions = [
('c', 'cached', None, ''),
@@ -620,8 +699,12 @@
]
args, opts = parseoptions(ui, cmdoptions, args)
- if (opts.get('modified') or opts.get('deleted')
- or opts.get('others') or opts.get('ignored')):
+ if (
+ opts.get('modified')
+ or opts.get('deleted')
+ or opts.get('others')
+ or opts.get('ignored')
+ ):
cmd = Command('status')
if opts.get('deleted'):
cmd['-d'] = None
@@ -634,8 +717,12 @@
else:
cmd = Command('files')
if opts.get('stage'):
- ui.status(_("note: Mercurial doesn't have a staging area, ignoring "
- "--stage\n"))
+ ui.status(
+ _(
+ "note: Mercurial doesn't have a staging area, ignoring "
+ "--stage\n"
+ )
+ )
if opts.get('_zero'):
cmd['-0'] = None
cmd.append('.')
@@ -644,9 +731,9 @@
ui.status((bytes(cmd)), "\n")
+
def merge(ui, repo, *args, **kwargs):
- cmdoptions = [
- ]
+ cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
cmd = Command('merge')
@@ -656,6 +743,7 @@
ui.status((bytes(cmd)), "\n")
+
def mergebase(ui, repo, *args, **kwargs):
cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
@@ -663,13 +751,17 @@
if len(args) != 2:
args = ['A', 'B']
- cmd = Command("log -T '{node}\\n' -r 'ancestor(%s,%s)'"
- % (args[0], args[1]))
+ cmd = Command(
+ "log -T '{node}\\n' -r 'ancestor(%s,%s)'" % (args[0], args[1])
+ )
- ui.status(_('note: ancestors() is part of the revset language\n'),
- _("(learn more about revsets with 'hg help revsets')\n\n"))
+ ui.status(
+ _('note: ancestors() is part of the revset language\n'),
+ _("(learn more about revsets with 'hg help revsets')\n\n"),
+ )
ui.status((bytes(cmd)), "\n")
+
def mergetool(ui, repo, *args, **kwargs):
cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
@@ -681,6 +773,7 @@
cmd.extend(args)
ui.status((bytes(cmd)), "\n")
+
def mv(ui, repo, *args, **kwargs):
cmdoptions = [
('f', 'force', None, ''),
@@ -698,6 +791,7 @@
ui.status((bytes(cmd)), "\n")
+
def pull(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'all', None, ''),
@@ -712,10 +806,14 @@
if len(args) > 0:
cmd.append(args[0])
if len(args) > 1:
- ui.status(_("note: Mercurial doesn't have refspecs. "
- "-r can be used to specify which commits you want to "
- "pull. -B can be used to specify which bookmark you "
- "want to pull.\n\n"))
+ ui.status(
+ _(
+ "note: Mercurial doesn't have refspecs. "
+ "-r can be used to specify which commits you want to "
+ "pull. -B can be used to specify which bookmark you "
+ "want to pull.\n\n"
+ )
+ )
for v in args[1:]:
if v in repo._bookmarks:
cmd['-B'] = v
@@ -724,6 +822,7 @@
ui.status((bytes(cmd)), "\n")
+
def push(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'all', None, ''),
@@ -736,10 +835,14 @@
if len(args) > 0:
cmd.append(args[0])
if len(args) > 1:
- ui.status(_("note: Mercurial doesn't have refspecs. "
- "-r can be used to specify which commits you want "
- "to push. -B can be used to specify which bookmark "
- "you want to push.\n\n"))
+ ui.status(
+ _(
+ "note: Mercurial doesn't have refspecs. "
+ "-r can be used to specify which commits you want "
+ "to push. -B can be used to specify which bookmark "
+ "you want to push.\n\n"
+ )
+ )
for v in args[1:]:
if v in repo._bookmarks:
cmd['-B'] = v
@@ -751,6 +854,7 @@
ui.status((bytes(cmd)), "\n")
+
def rebase(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'all', None, ''),
@@ -763,12 +867,20 @@
args, opts = parseoptions(ui, cmdoptions, args)
if opts.get('interactive'):
- ui.status(_("note: hg histedit does not perform a rebase. "
- "It just edits history.\n\n"))
+ ui.status(
+ _(
+ "note: hg histedit does not perform a rebase. "
+ "It just edits history.\n\n"
+ )
+ )
cmd = Command('histedit')
if len(args) > 0:
- ui.status(_("also note: 'hg histedit' will automatically detect"
- " your stack, so no second argument is necessary\n\n"))
+ ui.status(
+ _(
+ "also note: 'hg histedit' will automatically detect"
+ " your stack, so no second argument is necessary\n\n"
+ )
+ )
ui.status((bytes(cmd)), "\n")
return
@@ -784,9 +896,13 @@
cmd['--abort'] = None
if opts.get('onto'):
- ui.status(_("note: if you're trying to lift a commit off one branch, "
- "try hg rebase -d <destination commit> -s <commit to be "
- "lifted>\n\n"))
+ ui.status(
+ _(
+ "note: if you're trying to lift a commit off one branch, "
+ "try hg rebase -d <destination commit> -s <commit to be "
+ "lifted>\n\n"
+ )
+ )
cmd['-d'] = convert(opts.get('onto'))
if len(args) < 2:
raise error.Abort(_("expected format: git rebase --onto X Y Z"))
@@ -800,6 +916,7 @@
ui.status((bytes(cmd)), "\n")
+
def reflog(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'all', None, ''),
@@ -813,8 +930,13 @@
cmd.append(args[0])
ui.status(bytes(cmd), "\n\n")
- ui.status(_("note: in hg commits can be deleted from repo but we always"
- " have backups\n"))
+ ui.status(
+ _(
+ "note: in hg commits can be deleted from repo but we always"
+ " have backups\n"
+ )
+ )
+
def reset(ui, repo, *args, **kwargs):
cmdoptions = [
@@ -828,11 +950,19 @@
hard = opts.get('hard')
if opts.get('mixed'):
- ui.status(_('note: --mixed has no meaning since Mercurial has no '
- 'staging area\n\n'))
+ ui.status(
+ _(
+ 'note: --mixed has no meaning since Mercurial has no '
+ 'staging area\n\n'
+ )
+ )
if opts.get('soft'):
- ui.status(_('note: --soft has no meaning since Mercurial has no '
- 'staging area\n\n'))
+ ui.status(
+ _(
+ 'note: --soft has no meaning since Mercurial has no '
+ 'staging area\n\n'
+ )
+ )
cmd = Command('update')
if hard:
@@ -842,14 +972,18 @@
ui.status((bytes(cmd)), "\n")
+
def revert(ui, repo, *args, **kwargs):
- cmdoptions = [
- ]
+ cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
if len(args) > 1:
- ui.status(_("note: hg backout doesn't support multiple commits at "
- "once\n\n"))
+ ui.status(
+ _(
+ "note: hg backout doesn't support multiple commits at "
+ "once\n\n"
+ )
+ )
cmd = Command('backout')
if args:
@@ -857,6 +991,7 @@
ui.status((bytes(cmd)), "\n")
+
def revparse(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'show-cdup', None, ''),
@@ -872,6 +1007,7 @@
else:
ui.status(_("note: see hg help revset for how to refer to commits\n"))
+
def rm(ui, repo, *args, **kwargs):
cmdoptions = [
('f', 'force', None, ''),
@@ -889,6 +1025,7 @@
ui.status((bytes(cmd)), "\n")
+
def show(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'name-status', None, ''),
@@ -921,6 +1058,7 @@
ui.status((bytes(cmd)), "\n")
+
def stash(ui, repo, *args, **kwargs):
cmdoptions = [
('p', 'patch', None, ''),
@@ -956,8 +1094,12 @@
if action == 'apply':
cmd['--keep'] = None
elif action == 'branch' or action == 'create':
- ui.status(_("note: Mercurial doesn't have equivalents to the "
- "git stash branch or create actions\n\n"))
+ ui.status(
+ _(
+ "note: Mercurial doesn't have equivalents to the "
+ "git stash branch or create actions\n\n"
+ )
+ )
return
else:
if len(args) > 0:
@@ -968,6 +1110,7 @@
ui.status((bytes(cmd)), "\n")
+
def status(ui, repo, *args, **kwargs):
cmdoptions = [
('', 'ignored', None, ''),
@@ -982,28 +1125,29 @@
ui.status((bytes(cmd)), "\n")
+
def svn(ui, repo, *args, **kwargs):
if not args:
raise error.Abort(_('missing svn command'))
svncmd = args[0]
if svncmd not in gitsvncommands:
- raise error.Abort(_('unknown git svn command "%s"') % (svncmd))
+ raise error.Abort(_('unknown git svn command "%s"') % svncmd)
args = args[1:]
return gitsvncommands[svncmd](ui, repo, *args, **kwargs)
+
def svndcommit(ui, repo, *args, **kwargs):
- cmdoptions = [
- ]
+ cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
cmd = Command('push')
ui.status((bytes(cmd)), "\n")
+
def svnfetch(ui, repo, *args, **kwargs):
- cmdoptions = [
- ]
+ cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
cmd = Command('pull')
@@ -1011,9 +1155,9 @@
ui.status((bytes(cmd)), "\n")
+
def svnfindrev(ui, repo, *args, **kwargs):
- cmdoptions = [
- ]
+ cmdoptions = []
args, opts = parseoptions(ui, cmdoptions, args)
if not args:
@@ -1024,6 +1168,7 @@
ui.status((bytes(cmd)), "\n")
+
def svnrebase(ui, repo, *args, **kwargs):
cmdoptions = [
('l', 'local', None, ''),
@@ -1039,6 +1184,7 @@
ui.status((bytes(cmd)), "\n")
+
def tag(ui, repo, *args, **kwargs):
cmdoptions = [
('f', 'force', None, ''),
@@ -1067,6 +1213,7 @@
ui.status((bytes(cmd)), "\n")
+
gitcommands = {
'add': add,
'am': am,