# HG changeset patch
# User Patrick Mezard <pmezard@gmail.com>
# Date 1297624441 -3600
# Node ID 40ddf8213fa25dd09e582aa394c4e1ddde690144
# Parent  f214fb3f92cd235a97b46b3e96365599528ee4da
pushmod: do not delete the whole branch when deleting .hgsub

When deleting .hgsub, and only .hgsub, the root directory '' was marked as
changed. Since it was not listed in the existing directory list, this single
record was enough to trigger a deletion of the current branch. We changed the
directory parser to always emit the '' element.

diff --git a/hgsubversion/pushmod.py b/hgsubversion/pushmod.py
--- a/hgsubversion/pushmod.py
+++ b/hgsubversion/pushmod.py
@@ -33,12 +33,16 @@ def _getdirchanges(svn, branchpath, pare
     in either list.
     """
     def finddirs(path, includeself=False):
-        if includeself:
+        if includeself and path:
             yield path
         pos = path.rfind('/')
         while pos != -1:
             yield path[:pos]
             pos = path.rfind('/', 0, pos)
+        # Include the root path, properties can be set explicitely on it
+        # (like externals), and you want to preserve it if there are any
+        # other child item still existing.
+        yield ''
 
     def getctxdirs(ctx, keptdirs, extdirs):
         dirs = {}
diff --git a/tests/test_externals.py b/tests/test_externals.py
--- a/tests/test_externals.py
+++ b/tests/test_externals.py
@@ -362,6 +362,20 @@ HEAD subdir1/deps/project2
         self.assertTrue('subdir2/a' in self.repo['tip'])
         self.assertTrue('subdir1/a' not in self.repo['tip'])
 
+        # Move the externals so they are defined on the base directory,
+        # this used to cause full branch removal when deleting the .hgsub
+        changes = [
+            ('.hgsub', '.hgsub', """\
+subdir1/deps/project1 = [hgsubversion] :^/externals/project1 subdir1/deps/project1
+"""),
+            ('.hgsubstate', '.hgsubstate', """\
+HEAD subdir1/deps/project1
+"""),
+            ]
+        self.commitchanges(changes)
+        self.pushrevisions(stupid)
+        self.assertchanges(changes, self.repo['tip'])
+
         # Test externals removal
         changes = [
             ('.hgsub', None, None),