subrepo: fix subrelpath for git subrepos
authorEric Eisner <ede@mit.edu>
Mon, 20 Dec 2010 13:59:33 -0500
changeset 13181 413bef846806
parent 13180 a79e0688a5ee
child 13182 2537bd17421d
subrepo: fix subrelpath for git subrepos This patch conforms gitsubrepo code to the variable naming scheme of the other subrepo implementations. All user-facing path references should be relative to the root repository.
mercurial/subrepo.py
tests/test-subrepo-git.t
--- a/mercurial/subrepo.py	Mon Dec 20 13:59:33 2010 -0500
+++ b/mercurial/subrepo.py	Mon Dec 20 13:59:33 2010 -0500
@@ -172,6 +172,8 @@
 
 def subrelpath(sub):
     """return path to this subrepo as seen from outermost repo"""
+    if hasattr(sub, '_relpath'):
+        return sub._relpath
     if not hasattr(sub, '_repo'):
         return sub._path
     return reporelpath(sub._repo)
@@ -617,15 +619,17 @@
         # TODO add git version check.
         self._state = state
         self._ctx = ctx
-        self._relpath = path
-        self._path = ctx._repo.wjoin(path)
+        self._path = path
+        self._relpath = os.path.join(reporelpath(ctx._repo), path)
+        self._abspath = ctx._repo.wjoin(path)
         self._ui = ctx._repo.ui
 
     def _gitcommand(self, commands, env=None, stream=False):
         return self._gitdir(commands, env=env, stream=stream)[0]
 
     def _gitdir(self, commands, env=None, stream=False):
-        return self._gitnodir(commands, env=env, stream=stream, cwd=self._path)
+        return self._gitnodir(commands, env=env, stream=stream,
+                              cwd=self._abspath)
 
     def _gitnodir(self, commands, env=None, stream=False, cwd=None):
         """Calls the git command
@@ -711,9 +715,9 @@
         return tracking
 
     def _fetch(self, source, revision):
-        if not os.path.exists('%s/.git' % self._path):
+        if not os.path.exists(os.path.join(self._abspath, '.git')):
             self._ui.status(_('cloning subrepo %s\n') % self._relpath)
-            self._gitnodir(['clone', source, self._path])
+            self._gitnodir(['clone', source, self._abspath])
         if self._githavelocally(revision):
             return
         self._ui.status(_('pulling subrepo %s\n') % self._relpath)
@@ -725,7 +729,7 @@
         self._gitcommand(['fetch', source])
         if not self._githavelocally(revision):
             raise util.Abort(_("revision %s does not exist in subrepo %s\n") %
-                               (revision, self._path))
+                               (revision, self._relpath))
 
     def dirty(self, ignoreupdate=False):
         # version checked out changed?
@@ -859,16 +863,16 @@
     def remove(self):
         if self.dirty():
             self._ui.warn(_('not removing repo %s because '
-                            'it has changes.\n') % self._path)
+                            'it has changes.\n') % self._relpath)
             return
         # we can't fully delete the repository as it may contain
         # local-only history
-        self._ui.note(_('removing subrepo %s\n') % self._path)
+        self._ui.note(_('removing subrepo %s\n') % self._relpath)
         self._gitcommand(['config', 'core.bare', 'true'])
-        for f in os.listdir(self._path):
+        for f in os.listdir(self._abspath):
             if f == '.git':
                 continue
-            path = os.path.join(self._path, f)
+            path = os.path.join(self._abspath, f)
             if os.path.isdir(path) and not os.path.islink(path):
                 shutil.rmtree(path)
             else:
@@ -892,7 +896,7 @@
                 data = info.linkname
             else:
                 data = tar.extractfile(info).read()
-            archiver.addfile(os.path.join(prefix, self._relpath, info.name),
+            archiver.addfile(os.path.join(prefix, self._path, info.name),
                              info.mode, info.issym(), data)
             ui.progress(_('archiving (%s)') % relpath, i + 1,
                         unit=_('files'))
--- a/tests/test-subrepo-git.t	Mon Dec 20 13:59:33 2010 -0500
+++ b/tests/test-subrepo-git.t	Mon Dec 20 13:59:33 2010 -0500
@@ -34,7 +34,7 @@
   $ git clone -q ../gitroot s
   $ hg add .hgsub
   $ hg commit -m 'new git subrepo'
-  committing subrepository $TESTTMP/t/s
+  committing subrepository s
   $ hg debugsub
   path s
    source   ../gitroot
@@ -53,7 +53,7 @@
 
   $ cd ..
   $ hg commit -m 'update git subrepo'
-  committing subrepository $TESTTMP/t/s
+  committing subrepository s
   $ hg debugsub
   path s
    source   ../gitroot
@@ -100,7 +100,7 @@
   $ cd ../ta
   $ echo ggg >> s/g
   $ hg commit -m ggg
-  committing subrepository $TESTTMP/ta/s
+  committing subrepository s
   $ hg debugsub
   path s
    source   ../gitroot
@@ -120,7 +120,7 @@
   $ cd ..
 
   $ hg commit -m f
-  committing subrepository $TESTTMP/tb/s
+  committing subrepository s
   $ hg debugsub
   path s
    source   ../gitroot
@@ -159,7 +159,7 @@
   gg
   ggg
   $ hg commit -m 'merge'
-  committing subrepository $TESTTMP/ta/s
+  committing subrepository s
   $ hg debugsub
   path s
    source   ../gitroot
@@ -212,7 +212,7 @@
   $ git pull -q >/dev/null 2>/dev/null
   $ cd ..
   $ hg commit -m 'git upstream sync'
-  committing subrepository $TESTTMP/ta/s
+  committing subrepository s
   $ hg debugsub
   path s
    source   ../gitroot
@@ -260,3 +260,35 @@
   g
   gg
   ggg
+
+create nested repo
+
+  $ cd ..
+  $ hg init outer
+  $ cd outer
+  $ echo b>b
+  $ hg add b
+  $ hg commit -m b
+
+  $ hg clone ../t inner
+  updating to branch default
+  cloning subrepo s
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo inner = inner > .hgsub
+  $ hg add .hgsub
+  $ hg commit -m 'nested sub'
+  committing subrepository inner
+
+nested commit
+
+  $ echo ffff >> inner/s/f
+  $ hg commit -m nested
+  committing subrepository inner
+  committing subrepository inner/s
+
+nested archive
+
+  $ hg archive --subrepos ../narchive
+  $ ls ../narchive/inner/s
+  f
+  g