Patchwork [2,of,3,V2] remove: support remove with explicit paths in subrepos

login
register
mail settings
Submitter Matt Harbison
Date Nov. 16, 2014, 6:16 a.m.
Message ID <39371efb61771bea0759.1416118592@Envy>
Download mbox | patch
Permalink /patch/6746/
State Accepted
Commit f6b8d23492e530fa3b99504cbc2a7b964316a69a
Headers show

Comments

Matt Harbison - Nov. 16, 2014, 6:16 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1415852120 18000
#      Wed Nov 12 23:15:20 2014 -0500
# Node ID 39371efb61771bea0759c1e2238b43ec60d394a4
# Parent  a35171de7e3c42d7bdcbc3717e6f8fb620a76bb0
remove: support remove with explicit paths in subrepos

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -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))):
diff --git a/mercurial/help/subrepos.txt b/mercurial/help/subrepos.txt
--- a/mercurial/help/subrepos.txt
+++ b/mercurial/help/subrepos.txt
@@ -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
diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -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