diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -526,10 +526,6 @@ def _dispatch(req): args = req.args ui = req.ui - shellaliasfn = _checkshellalias(ui, args) - if shellaliasfn: - return shellaliasfn() - # read --config before doing anything else # (e.g. to change trust settings for reading .hg/hgrc) cfgs = _parseconfig(ui, _earlygetopt(['--config'], args)) @@ -542,6 +538,12 @@ def _dispatch(req): rpath = _earlygetopt(["-R", "--repository", "--repo"], args) path, lui = _getlocal(ui, rpath) + # Now that we're operating in the right directory/repository with + # the right config settings, check for shell aliases + shellaliasfn = _checkshellalias(ui, args) + if shellaliasfn: + return shellaliasfn() + # Configure extensions in phases: uisetup, extsetup, cmdtable, and # reposetup. Programs like TortoiseHg will call _dispatch several # times so we keep track of configured extensions in _loaded. diff --git a/tests/test-alias.t b/tests/test-alias.t --- a/tests/test-alias.t +++ b/tests/test-alias.t @@ -251,7 +251,7 @@ shell aliases with global options $ hg --cwd .. count 'branch(default)' 2 $ hg echo --cwd .. - --cwd .. + repo specific shell aliases @@ -274,8 +274,6 @@ shell alias defined in current repo hg: unknown command 'subalias' [255] $ hg -R .. subalias > /dev/null - hg: unknown command 'subalias' - [255] shell alias defined in other repo @@ -284,6 +282,7 @@ shell alias defined in other repo hg: unknown command 'mainalias' [255] $ hg -R .. mainalias + warning: --repository ignored main $ hg --cwd .. mainalias main