# HG changeset patch # User Mads Kiilerich # Date 2010-07-23 22:38:08 # Node ID f92f8921a5cc262f043c99a9ea7afcb9835b2aca # Parent c29012a73518b95991a2d4bf3b899302ae84de40 dispatch: give better error message when cwd doesn't exist (issue2293) Previous behavior wasn't very helpful: $ hg st foo abort: No such file or directory Now we tell more about what failed: abort: error getting current working directory: No such file or directory diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -366,7 +366,12 @@ def _dispatch(ui, args): os.chdir(cwd[-1]) # read the local repository .hgrc into a local ui object - path = cmdutil.findrepo(os.getcwd()) or "" + try: + wd = os.getcwd() + except OSError, e: + raise util.Abort(_("error getting current working directory: %s") % + e.strerror) + path = cmdutil.findrepo(wd) or "" if not path: lui = ui else: diff --git a/tests/test-dispatch b/tests/test-dispatch --- a/tests/test-dispatch +++ b/tests/test-dispatch @@ -3,6 +3,8 @@ "$TESTDIR/hghave" no-outer-repo || exit 80 +dir=`pwd` + hg init a cd a echo a > a @@ -19,8 +21,12 @@ cat = -r null EOF hg cat a +echo '% working directory removed' +rm -rf $dir/a +hg --version + echo '% no repo' -cd .. +cd $dir hg cat exit 0 diff --git a/tests/test-dispatch.out b/tests/test-dispatch.out --- a/tests/test-dispatch.out +++ b/tests/test-dispatch.out @@ -33,5 +33,7 @@ use "hg -v help cat" to show global opti % [defaults] a a: No such file in rev 000000000000 +% working directory removed +abort: error getting current working directory: No such file or directory % no repo abort: There is no Mercurial repository here (.hg not found)!