[PATCH] dispatch: give better error message when cwd doesn't exist (issue2293)
Mads Kiilerich
mads at kiilerich.com
Fri Jul 23 17:41:14 CDT 2010
# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1279924688 -7200
# Node ID c4e62434006307975aea472b5d2c2be5d4c124d2
# Parent c1b11ee12fe72771441296968a069ddcc55444e2
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
@@ -380,7 +380,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:
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 @@
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 @@
% [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)!
More information about the Mercurial-devel
mailing list