diff mercurial/subrepo.py @ 12996:3a42651b0a62

subrepo: removing (and restoring) git subrepo state
author Eric Eisner <ede@mit.edu>
date Sun, 14 Nov 2010 18:31:40 -0500
parents d90fc91c8377
children 9efc316a6716
line wrap: on
line diff
--- a/mercurial/subrepo.py	Sun Nov 14 18:31:29 2010 -0500
+++ b/mercurial/subrepo.py	Sun Nov 14 18:31:40 2010 -0500
@@ -678,7 +678,14 @@
     def get(self, state):
         source, revision, kind = state
         self._fetch(source, revision)
-        if self._gitstate() == revision:
+        # if the repo was set to be bare, unbare it
+        if self._gitcommand(['config', '--get', 'core.bare']
+                            ).strip() == 'true':
+            self._gitcommand(['config', 'core.bare', 'false'])
+            if self._gitstate() == revision:
+                self._gitcommand(['reset', '--hard', 'HEAD'])
+                return
+        elif self._gitstate() == revision:
             return
         current, bm = self._gitbranchmap()
         if revision not in bm:
@@ -742,6 +749,24 @@
                             'nothing to push') % self._relpath)
             return False
 
+    def remove(self):
+        if self.dirty():
+            self._ui.warn(_('not removing repo %s because '
+                            'it has changes.\n') % self._path)
+            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._gitcommand(['config', 'core.bare', 'true'])
+        for f in os.listdir(self._path):
+            if f == '.git':
+                continue
+            path = os.path.join(self._path, f)
+            if os.path.isdir(path) and not os.path.islink(path):
+                shutil.rmtree(path)
+            else:
+                os.remove(path)
+
 types = {
     'hg': hgsubrepo,
     'svn': svnsubrepo,