Mercurial > hg-stable
changeset 25011:7d6a507a4c53
pathutil: hint if a path is root relative instead of cwd relative (issue4663)
Given that this path is going to abort, it seems OK to spend the time to do an
alternate lookup to better inform the user. The path returned by util.pathto()
ends with '/' at least in some cases, so os.path.relpath() is used instead,
which requires python 2.6.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 11 May 2015 21:26:13 -0400 |
parents | ded7302e1c83 |
children | 256c8432e346 |
files | mercurial/pathutil.py tests/test-globalopts.t |
diffstat | 2 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/pathutil.py Mon May 11 22:47:01 2015 -0400 +++ b/mercurial/pathutil.py Mon May 11 21:26:13 2015 -0400 @@ -152,7 +152,17 @@ break name = dirname - raise util.Abort(_("%s not under root '%s'") % (myname, root)) + # A common mistake is to use -R, but specify a file relative to the repo + # instead of cwd. Detect that case, and provide a hint to the user. + hint = None + try: + canonpath(root, root, myname, auditor) + hint = _("consider using '--cwd %s'") % os.path.relpath(root, cwd) + except util.Abort: + pass + + raise util.Abort(_("%s not under root '%s'") % (myname, root), + hint=hint) def normasprefix(path): '''normalize the specified path as path prefix
--- a/tests/test-globalopts.t Mon May 11 22:47:01 2015 -0400 +++ b/tests/test-globalopts.t Mon May 11 21:26:13 2015 -0400 @@ -88,6 +88,7 @@ [255] $ hg -R b ann a/a abort: a/a not under root '$TESTTMP/b' (glob) + (consider using '--cwd b') [255] $ hg log abort: no repository found in '$TESTTMP' (.hg not found)!