Mercurial > public > mercurial-scm > hg-stable
diff mercurial/dispatch.py @ 6150:aafdea37f796
Infer a --repository argument from command arguments when reasonable.
In particular: if invoked without -R from a CWD not inside a repo, having been
passed one or more file paths as command arguments, where the nearest enclosing
repo of all of those paths is the same, quietly infer a -R option for that repo.
Otherwise abort with an error message as before.
author | Jesse Glick <jesse.glick@sun.com> |
---|---|
date | Fri, 25 Jan 2008 04:11:32 -0500 |
parents | 50a277e6ceae |
children | f89fd07fc51d |
line wrap: on
line diff
--- a/mercurial/dispatch.py Tue Feb 19 10:53:40 2008 -0800 +++ b/mercurial/dispatch.py Fri Jan 25 04:11:32 2008 -0500 @@ -150,8 +150,7 @@ return -1 -def _findrepo(): - p = os.getcwd() +def _findrepo(p): while not os.path.isdir(os.path.join(p, ".hg")): oldp, p = p, os.path.dirname(p) if p == oldp: @@ -254,7 +253,7 @@ os.chdir(cwd[-1]) # read the local repository .hgrc into a local ui object - path = _findrepo() or "" + path = _findrepo(os.getcwd()) or "" if not path: lui = ui if path: @@ -345,6 +344,11 @@ ui.setconfig("bundle", "mainreporoot", repo.root) except hg.RepoError: if cmd not in commands.optionalrepo.split(): + if args and not path: # try to infer -R from command args + repos = map(_findrepo, args) + guess = repos[0] + if guess and repos.count(guess) == len(repos): + return _dispatch(ui, ['--repository', guess] + fullargs) if not path: raise hg.RepoError(_("There is no Mercurial repository here" " (.hg not found)"))