changeset 23326:f6b8d23492e5

remove: support remove with explicit paths in subrepos
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 12 Nov 2014 23:15:20 -0500
parents 4165cfd67519
children bd296bb4b5c8
files mercurial/cmdutil.py mercurial/help/subrepos.txt tests/test-subrepo-deep-nested-change.t
diffstat 3 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sat Nov 15 21:36:19 2014 -0500
+++ b/mercurial/cmdutil.py	Wed Nov 12 23:15:20 2014 -0500
@@ -2060,8 +2060,16 @@
 
     wctx = repo[None]
 
-    if subrepos:
-        for subpath in sorted(wctx.substate):
+    for subpath in sorted(wctx.substate):
+        def matchessubrepo(matcher, subpath):
+            if matcher.exact(subpath):
+                return True
+            for f in matcher.files():
+                if f.startswith(subpath):
+                    return True
+            return False
+
+        if subrepos or matchessubrepo(m, subpath):
             sub = wctx.sub(subpath)
             try:
                 submatch = matchmod.narrowmatcher(subpath, m)
@@ -2080,7 +2088,7 @@
                     return True
             return False
 
-        if f in repo.dirstate or f in wctx.dirs() or (subrepos and insubrepo()):
+        if f in repo.dirstate or f in wctx.dirs() or insubrepo():
             continue
 
         if os.path.exists(m.rel(join(f))):
--- a/mercurial/help/subrepos.txt	Sat Nov 15 21:36:19 2014 -0500
+++ b/mercurial/help/subrepos.txt	Wed Nov 12 23:15:20 2014 -0500
@@ -130,8 +130,10 @@
     ignored.
 
 :remove: remove does not recurse into subrepositories unless
-    -S/--subrepos is specified.  Git and Subversion subrepositories
-    are currently silently ignored.
+    -S/--subrepos is specified.  However, if you specify a file or
+    directory path in a subrepo, it will be removed even without
+    -S/--subrepos.  Git and Subversion subrepositories are currently
+    silently ignored.
 
 :update: update restores the subrepos in the state they were
     originally committed in target changeset. If the recorded
--- a/tests/test-subrepo-deep-nested-change.t	Sat Nov 15 21:36:19 2014 -0500
+++ b/tests/test-subrepo-deep-nested-change.t	Wed Nov 12 23:15:20 2014 -0500
@@ -120,6 +120,14 @@
   R sub1/sub2/folder/test.txt
   R sub1/sub2/test.txt
   $ hg update -Cq
+  $ hg remove -I 're:.*.txt' sub1
+  $ hg status -S
+  $ hg remove sub1/sub2/folder/test.txt
+  $ hg remove sub1/.hgsubstate
+  $ hg status -S
+  R sub1/.hgsubstate
+  R sub1/sub2/folder/test.txt
+  $ hg update -Cq
 
   $ hg --config extensions.largefiles=! archive -S ../archive_all
   $ find ../archive_all | sort