diff --git a/mercurial/pathutil.py b/mercurial/pathutil.py --- a/mercurial/pathutil.py +++ b/mercurial/pathutil.py @@ -152,7 +152,17 @@ def canonpath(root, cwd, myname, auditor 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 diff --git a/tests/test-globalopts.t b/tests/test-globalopts.t --- a/tests/test-globalopts.t +++ b/tests/test-globalopts.t @@ -88,6 +88,7 @@ Implicit -R: [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)!