##// END OF EJS Templates
alias: inherit command optionalrepo flag (issue3298)...
Patrick Mezard -
r16609:d36a384b stable
parent child Browse files
Show More
@@ -243,6 +243,7 b' class cmdalias(object):'
243 self.opts = []
243 self.opts = []
244 self.help = ''
244 self.help = ''
245 self.norepo = True
245 self.norepo = True
246 self.optionalrepo = False
246 self.badalias = False
247 self.badalias = False
247
248
248 try:
249 try:
@@ -312,6 +313,8 b' class cmdalias(object):'
312 self.args = aliasargs(self.fn, args)
313 self.args = aliasargs(self.fn, args)
313 if cmd not in commands.norepo.split(' '):
314 if cmd not in commands.norepo.split(' '):
314 self.norepo = False
315 self.norepo = False
316 if cmd in commands.optionalrepo.split(' '):
317 self.optionalrepo = True
315 if self.help.startswith("hg " + cmd):
318 if self.help.startswith("hg " + cmd):
316 # drop prefix in old-style help lines so hg shows the alias
319 # drop prefix in old-style help lines so hg shows the alias
317 self.help = self.help[4 + len(cmd):]
320 self.help = self.help[4 + len(cmd):]
@@ -370,6 +373,8 b' def addaliases(ui, cmdtable):'
370 cmdtable[aliasdef.name] = (aliasdef, aliasdef.opts, aliasdef.help)
373 cmdtable[aliasdef.name] = (aliasdef, aliasdef.opts, aliasdef.help)
371 if aliasdef.norepo:
374 if aliasdef.norepo:
372 commands.norepo += ' %s' % alias
375 commands.norepo += ' %s' % alias
376 if aliasdef.optionalrepo:
377 commands.optionalrepo += ' %s' % alias
373
378
374 def _parse(ui, args):
379 def _parse(ui, args):
375 options = {}
380 options = {}
@@ -495,7 +500,6 b' def _getlocal(ui, rpath):'
495 return path, lui
500 return path, lui
496
501
497 def _checkshellalias(lui, ui, args):
502 def _checkshellalias(lui, ui, args):
498 norepo = commands.norepo
499 options = {}
503 options = {}
500
504
501 try:
505 try:
@@ -506,6 +510,12 b' def _checkshellalias(lui, ui, args):'
506 if not args:
510 if not args:
507 return
511 return
508
512
513 norepo = commands.norepo
514 optionalrepo = commands.optionalrepo
515 def restorecommands():
516 commands.norepo = norepo
517 commands.optionalrepo = optionalrepo
518
509 cmdtable = commands.table.copy()
519 cmdtable = commands.table.copy()
510 addaliases(lui, cmdtable)
520 addaliases(lui, cmdtable)
511
521
@@ -514,7 +524,7 b' def _checkshellalias(lui, ui, args):'
514 aliases, entry = cmdutil.findcmd(cmd, cmdtable,
524 aliases, entry = cmdutil.findcmd(cmd, cmdtable,
515 lui.configbool("ui", "strict"))
525 lui.configbool("ui", "strict"))
516 except (error.AmbiguousCommand, error.UnknownCommand):
526 except (error.AmbiguousCommand, error.UnknownCommand):
517 commands.norepo = norepo
527 restorecommands()
518 return
528 return
519
529
520 cmd = aliases[0]
530 cmd = aliases[0]
@@ -524,7 +534,7 b' def _checkshellalias(lui, ui, args):'
524 d = lambda: fn(ui, *args[1:])
534 d = lambda: fn(ui, *args[1:])
525 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {})
535 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {})
526
536
527 commands.norepo = norepo
537 restorecommands()
528
538
529 _loaded = set()
539 _loaded = set()
530 def _dispatch(req):
540 def _dispatch(req):
@@ -9,6 +9,7 b''
9 > # should clobber ci but not commit (issue2993)
9 > # should clobber ci but not commit (issue2993)
10 > ci = version
10 > ci = version
11 > myinit = init
11 > myinit = init
12 > optionalrepo = showconfig alias.myinit
12 > cleanstatus = status -c
13 > cleanstatus = status -c
13 > unknown = bargle
14 > unknown = bargle
14 > ambiguous = s
15 > ambiguous = s
@@ -108,8 +109,17 b' invalid options'
108 $ hg help no--repository
109 $ hg help no--repository
109 error in definition for alias 'no--repository': --repository may only be given on the command line
110 error in definition for alias 'no--repository': --repository may only be given on the command line
110
111
112 optional repository
113
114 $ hg optionalrepo
115 init
111 $ cd alias
116 $ cd alias
112
117 $ cat > .hg/hgrc <<EOF
118 > [alias]
119 > myinit = init -q
120 > EOF
121 $ hg optionalrepo
122 init -q
113
123
114 no usage
124 no usage
115
125
General Comments 0
You need to be logged in to leave comments. Login now