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
--- a/mercurial/dispatch.py Thu Jul 22 23:18:38 2010 +0900
+++ b/mercurial/dispatch.py Sat Jul 24 00:38:08 2010 +0200
@@ -366,7 +366,12 @@
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:
--- a/tests/test-dispatch Thu Jul 22 23:18:38 2010 +0900
+++ b/tests/test-dispatch Sat Jul 24 00:38:08 2010 +0200
@@ -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 @@
EOF
hg cat a
+echo '% working directory removed'
+rm -rf $dir/a
+hg --version
+
echo '% no repo'
-cd ..
+cd $dir
hg cat
exit 0
--- a/tests/test-dispatch.out Thu Jul 22 23:18:38 2010 +0900
+++ b/tests/test-dispatch.out Sat Jul 24 00:38:08 2010 +0200
@@ -33,5 +33,7 @@
% [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)!