changeset 4230:c93562fb12cc

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.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Fri, 16 Mar 2007 00:22:58 -0300
parents 24c22a3f2ef8
children 83153299aab5
files mercurial/dirstate.py mercurial/util.py tests/test-import tests/test-import.out tests/test-walk tests/test-walk.out
diffstat 6 files changed, 40 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Fri Mar 16 00:22:57 2007 -0300
+++ b/mercurial/dirstate.py	Fri Mar 16 00:22:58 2007 -0300
@@ -34,10 +34,14 @@
         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	Fri Mar 16 00:22:57 2007 -0300
+++ b/mercurial/util.py	Fri Mar 16 00:22:58 2007 -0300
@@ -326,6 +326,10 @@
     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	Fri Mar 16 00:22:57 2007 -0300
+++ b/tests/test-import	Fri Mar 16 00:22:58 2007 -0300
@@ -32,6 +32,17 @@
 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	Fri Mar 16 00:22:57 2007 -0300
+++ b/tests/test-import.out	Fri Mar 16 00:22:58 2007 -0300
@@ -30,6 +30,14 @@
 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	Fri Mar 16 00:22:57 2007 -0300
+++ b/tests/test-walk	Fri Mar 16 00:22:58 2007 -0300
@@ -59,3 +59,9 @@
 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	Fri Mar 16 00:22:57 2007 -0300
+++ b/tests/test-walk.out	Fri Mar 16 00:22:58 2007 -0300
@@ -95,3 +95,6 @@
 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