[PATCH 7 of 8 V3] addremove: support addremove with explicit paths in subrepos

Matt Harbison mharbison72 at gmail.com
Thu Dec 11 21:35:19 CST 2014


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1415594785 18000
#      Sun Nov 09 23:46:25 2014 -0500
# Node ID e2f70cc71434d6cca73e48544b7ed48576f37c64
# Parent  c80a67bfe20d133bfa3b93fb36859380a7c54bbe
addremove: support addremove with explicit paths in subrepos

Git and svn subrepos are currently not supported.

diff --git a/mercurial/help/subrepos.txt b/mercurial/help/subrepos.txt
--- a/mercurial/help/subrepos.txt
+++ b/mercurial/help/subrepos.txt
@@ -82,8 +82,10 @@
     ignored.
 
 :addremove: addremove does not recurse into subrepos unless
-    -S/--subrepos is specified.  Git and Subversion subrepositories
-    will print a warning and continue.
+    -S/--subrepos is specified.  However, if you specify the full
+    path of a directory in a subrepo, addremove will be performed on
+    it even without -S/--subrepos being specified.  Git and
+    Subversion subrepositories will print a warning and continue.
 
 :archive: archive does not recurse in subrepositories unless
     -S/--subrepos is specified.
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -723,9 +723,17 @@
     ret = 0
     join = lambda f: os.path.join(prefix, f)
 
+    def matchessubrepo(matcher, subpath):
+        if matcher.exact(subpath):
+            return True
+        for f in matcher.files():
+            if f.startswith(subpath):
+                return True
+        return False
+
     wctx = repo[None]
     for subpath in sorted(wctx.substate):
-        if opts.get('subrepos'):
+        if opts.get('subrepos') or matchessubrepo(m, subpath):
             sub = wctx.sub(subpath)
             try:
                 submatch = matchmod.narrowmatcher(subpath, m)
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
@@ -147,9 +147,18 @@
   A sub1/foo
   R sub1/sub2/test.txt
   $ hg update -Cq
+  $ touch sub1/sub2/folder/bar
+  $ hg addremove sub1/sub2
+  adding sub1/sub2/folder/bar (glob)
+  $ hg status -S
+  A sub1/sub2/folder/bar
+  ? foo/bar/abc
+  ? sub1/foo
+  $ hg update -Cq
   $ rm sub1/sub2/folder/test.txt
   $ rm sub1/sub2/test.txt
   $ hg ci -ASm "remove test.txt"
+  adding sub1/sub2/folder/bar (glob)
   removing sub1/sub2/folder/test.txt (glob)
   removing sub1/sub2/test.txt (glob)
   adding sub1/foo (glob)


More information about the Mercurial-devel mailing list