Fix handling of paths when run outside the repo.
The main problem was that dirstate.getcwd() returned just "",
which was interpreted as "we're at the repo root". It now returns
an absolute path.
The util.pathto function was also changed to deal with the "cwd is
an absolute path" case.
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -34,10 +34,14 @@ class dirstate(object):
cwd = os.getcwd()
if cwd == self.root: return ''
# self.root ends with a path separator if self.root is '/' or 'C:\'
- common_prefix_len = len(self.root)
- if not self.root.endswith(os.sep):
- common_prefix_len += 1
- return cwd[common_prefix_len:]
+ rootsep = self.root
+ if not rootsep.endswith(os.sep):
+ rootsep += os.sep
+ if cwd.startswith(rootsep):
+ return cwd[len(rootsep):]
+ else:
+ # we're outside the repo. return an absolute path.
+ return cwd
def hgignore(self):
'''return the contents of .hgignore files as a list of patterns.
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -326,6 +326,10 @@ def pathto(root, n1, n2):
n2 should always be relative to root.
'''
if not n1: return localpath(n2)
+ if os.path.isabs(n1):
+ if os.path.splitdrive(root)[0] != os.path.splitdrive(n1)[0]:
+ return os.path.join(root, localpath(n2))
+ n2 = '/'.join((pconvert(root), n2))
a, b = n1.split(os.sep), n2.split('/')
a.reverse()
b.reverse()
--- a/tests/test-import
+++ b/tests/test-import
@@ -32,6 +32,17 @@ hg --cwd a diff -r0:1 > tip.patch
hg --cwd b import -mpatch ../tip.patch
rm -r b
+echo % hg -R repo import
+# put the clone in a subdir - having a directory named "a"
+# used to hide a bug.
+mkdir dir
+hg clone -r0 a dir/b
+hg --cwd a export tip > dir/tip.patch
+cd dir
+hg -R b import tip.patch
+cd ..
+rm -r dir
+
echo % import from stdin
hg clone -r0 a b
hg --cwd a export tip | hg --cwd b import -
--- a/tests/test-import.out
+++ b/tests/test-import.out
@@ -30,6 +30,14 @@ adding file changes
added 1 changesets with 2 changes to 2 files
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
applying ../tip.patch
+% hg -R repo import
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 1 changesets with 2 changes to 2 files
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+applying tip.patch
% import from stdin
requesting all changes
adding changesets
--- a/tests/test-walk
+++ b/tests/test-walk
@@ -59,3 +59,9 @@ hg rm fenugreek
hg debugwalk fenugreek
touch new
hg debugwalk new
+cd ..
+hg -R t debugwalk t/mammals/skunk
+mkdir t2
+cd t2
+hg -R ../t debugwalk ../t/mammals/skunk
+hg --cwd ../t debugwalk mammals/skunk
--- a/tests/test-walk.out
+++ b/tests/test-walk.out
@@ -95,3 +95,6 @@ fifo: unsupported file type (type is fif
m fenugreek fenugreek exact
m fenugreek fenugreek exact
f new new exact
+f mammals/skunk t/mammals/skunk exact
+f mammals/skunk ../t/mammals/skunk exact
+f mammals/skunk mammals/skunk exact