diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- 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. diff --git a/mercurial/util.py b/mercurial/util.py --- 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() diff --git a/tests/test-import b/tests/test-import --- 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 - diff --git a/tests/test-import.out b/tests/test-import.out --- 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 diff --git a/tests/test-walk b/tests/test-walk --- 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 diff --git a/tests/test-walk.out b/tests/test-walk.out --- 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