Patchwork [9,of,9,V2] addremove: support addremove with explicit paths in subrepos

login
register
mail settings
Submitter Matt Harbison
Date Nov. 30, 2014, 5:52 a.m.
Message ID <cb680a267b90146e4e5e.1417326757@Envy>
Download mbox | patch
Permalink /patch/6904/
State Superseded
Commit cb42050f2dadfbb876452e23287441a937c20c5c
Headers show

Comments

Matt Harbison - Nov. 30, 2014, 5:52 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1415594785 18000
#      Sun Nov 09 23:46:25 2014 -0500
# Node ID cb680a267b90146e4e5e533c6cb06145f3de2edd
# Parent  370287c9b750b8cb4b3aaf13257d8c8d824bbbcf
addremove: support addremove with explicit paths in subrepos

Git and svn subrepos are currently not supported.

Patch

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)