# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1280234620 -7200 # Node ID ee8f36a6c766c2cfd3afb4b0e0074dd489d0214e # Parent bf49d48e46024c0e1e5208301d4172f432954c90 alias: improved diagnostic when arguments include --cwd, etc. The logic pre-emptively checks for -R, --repo, --repository and --cwd in order to give the user a more helpful error message. In addition, each option is handled invididually, which avoids listing them all in the error. Before: % hg --config alias.broken='push --cwd /dev/null' broken abort: Option --cwd may not be abbreviated! After: % hg --config alias.broken='push --cwd /dev/null' broken error in definition for alias 'broken': --cwd may only be given on the command line diff -r bf49d48e4602 -r ee8f36a6c766 mercurial/dispatch.py --- a/mercurial/dispatch.py Tue Jul 27 20:50:09 2010 +0530 +++ b/mercurial/dispatch.py Tue Jul 27 14:43:40 2010 +0200 @@ -223,6 +223,18 @@ cmd = args.pop(0) args = map(util.expandpath, args) + for invalidarg in ("--cwd", "-R", "--repository", "--repo"): + if _earlygetopt([invalidarg], args): + def fn(ui, *args): + ui.warn(_("error in definition for alias '%s': %s may only " + "be given on the command line\n") + % (self.name, invalidarg)) + return 1 + + self.fn = fn + self.badalias = True + return + try: tableentry = cmdutil.findcmd(cmd, cmdtable, False)[1] if len(tableentry) > 2: diff -r bf49d48e4602 -r ee8f36a6c766 tests/test-alias --- a/tests/test-alias Tue Jul 27 20:50:09 2010 +0530 +++ b/tests/test-alias Tue Jul 27 14:43:40 2010 +0200 @@ -8,6 +8,10 @@ ambiguous = s recursive = recursive nodefinition = +no--cwd = status --cwd elsewhere +no-R = status -R elsewhere +no--repo = status --repo elsewhere +no--repository = status --repository elsewhere mylog = log lognull = log -r null shortlog = log --template '{rev} {node|short} | {date|isodate}\n' @@ -42,6 +46,16 @@ hg nodef hg help nodef +echo '% invalid options' +hg no--cwd +hg help no--cwd +hg no-R +hg help no-R +hg no--repo +hg help no--repo +hg no--repository +hg help no--repository + cd alias echo '% no usage' diff -r bf49d48e4602 -r ee8f36a6c766 tests/test-alias.out --- a/tests/test-alias.out Tue Jul 27 20:50:09 2010 +0530 +++ b/tests/test-alias.out Tue Jul 27 14:43:40 2010 +0200 @@ -11,6 +11,15 @@ % no definition no definition for alias 'nodefinition' no definition for alias 'nodefinition' +% invalid options +error in definition for alias 'no--cwd': --cwd may only be given on the command line +error in definition for alias 'no--cwd': --cwd may only be given on the command line +error in definition for alias 'no-R': -R may only be given on the command line +error in definition for alias 'no-R': -R may only be given on the command line +error in definition for alias 'no--repo': --repo may only be given on the command line +error in definition for alias 'no--repo': --repo may only be given on the command line +error in definition for alias 'no--repository': --repository may only be given on the command line +error in definition for alias 'no--repository': --repository may only be given on the command line % no usage no rollback information available adding foo