subrepo: prune empty directories when removing svn subrepo stable
authorPatrick Mezard <pmezard@gmail.com>
Wed, 17 Nov 2010 21:25:23 +0100
branchstable
changeset 13015 82ca0c43bc44
parent 13014 d1c52354b0a9
child 13016 9efc316a6716
child 13017 d0e21c5fde41
subrepo: prune empty directories when removing svn subrepo
mercurial/subrepo.py
tests/test-subrepo-svn.t
--- a/mercurial/subrepo.py	Wed Nov 17 21:24:36 2010 +0100
+++ b/mercurial/subrepo.py	Wed Nov 17 21:25:23 2010 +0100
@@ -564,7 +564,12 @@
             os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE)
             os.remove(path)
 
-        shutil.rmtree(self._ctx._repo.wjoin(self._path), onerror=onerror)
+        path = self._ctx._repo.wjoin(self._path)
+        shutil.rmtree(path, onerror=onerror)
+        try:
+            os.removedirs(os.path.dirname(path))
+        except OSError:
+            pass
 
     def get(self, state):
         status = self._svncommand(['checkout', state[0], '--revision', state[1]])
--- a/tests/test-subrepo-svn.t	Wed Nov 17 21:24:36 2010 +0100
+++ b/tests/test-subrepo-svn.t	Wed Nov 17 21:25:23 2010 +0100
@@ -63,11 +63,15 @@
 
 add first svn sub with leading whitespaces
 
-  $ echo "s = [svn]       $SVNREPO/src" >> .hgsub
+  $ echo "s =        [svn]       $SVNREPO/src" >> .hgsub
+  $ echo "subdir/s = [svn]       $SVNREPO/src" >> .hgsub
   $ svn co --quiet "$SVNREPO"/src s
+  $ mkdir subdir
+  $ svn co --quiet "$SVNREPO"/src subdir/s
   $ hg add .hgsub
   $ hg ci -m1
   committing subrepository s
+  committing subrepository subdir/s
 
 make sure we avoid empty commits (issue2445)
 
@@ -87,6 +91,9 @@
   path s
    source   file://*/svn-repo/src (glob)
    revision 2
+  path subdir/s
+   source   file://*/svn-repo/src (glob)
+   revision 2
 
 change file in svn and hg, commit
 
@@ -112,6 +119,9 @@
   path s
    source   file://*/svn-repo/src (glob)
    revision 3
+  path subdir/s
+   source   file://*/svn-repo/src (glob)
+   revision 2
 
   $ echo a > s/a
 
@@ -170,9 +180,10 @@
   $ hg diff --subrepos -r 1:2 | grep -v diff
   --- a/.hgsubstate	Thu Jan 01 00:00:00 1970 +0000
   +++ b/.hgsubstate	Thu Jan 01 00:00:00 1970 +0000
-  @@ -1,1 +1,1 @@
+  @@ -1,2 +1,2 @@
   -2 s
   +3 s
+   2 subdir/s
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,1 +1,2 @@
@@ -195,6 +206,14 @@
   $ cd ..
   $ hg clone t tc | fix_path
   updating to branch default
+  A    tc/subdir/s/alpha
+   U   tc/subdir/s
+  
+  Fetching external item into 'tc/subdir/s/externals'
+  A    tc/subdir/s/externals/other
+  Checked out external at revision 1.
+  
+  Checked out revision 2.
   A    tc/s/alpha
    U   tc/s
   
@@ -212,6 +231,9 @@
   path s
    source   file://*/svn-repo/src (glob)
    revision 3
+  path subdir/s
+   source   file://*/svn-repo/src (glob)
+   revision 2
 
 verify subrepo is contained within the repo directory
 
@@ -222,3 +244,4 @@
 
   $ hg up null
   0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  $ ls