changeset 15410:9e99d2bbb1b1

add: support adding explicit files in subrepos Change the behavior of the add command such that explicit paths in subrepos are always added. This eliminates the previous behavior where if you called "hg add" for an explicit path in a subrepo without specifying the -S option, it would be silently ignored. If you specify patterns, or no arguments at all, the -S option will still be needed to activate recursion into subrepos.
author David M. Carr <david@carrclan.us>
date Wed, 02 Nov 2011 01:17:11 -0400
parents 83c2e6772408
children afc02adf4ded
files mercurial/cmdutil.py mercurial/help/subrepos.txt mercurial/subrepo.py tests/test-subrepo.t
diffstat 4 files changed, 28 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Tue Nov 01 23:53:29 2011 -0400
+++ b/mercurial/cmdutil.py	Wed Nov 02 01:17:11 2011 -0400
@@ -1165,15 +1165,19 @@
             if ui.verbose or not exact:
                 ui.status(_('adding %s\n') % match.rel(join(f)))
 
-    if listsubrepos:
-        for subpath in wctx.substate:
-            sub = wctx.sub(subpath)
-            try:
-                submatch = matchmod.narrowmatcher(subpath, match)
+    for subpath in wctx.substate:
+        sub = wctx.sub(subpath)
+        try:
+            submatch = matchmod.narrowmatcher(subpath, match)
+            if listsubrepos:
                 bad.extend(sub.add(ui, submatch, dryrun, prefix))
-            except error.LookupError:
-                ui.status(_("skipping missing subrepository: %s\n")
-                               % join(subpath))
+            else:
+                for f in sub.walk(submatch):
+                    if submatch.exact(f):
+                        bad.extend(sub.add(ui, submatch, dryrun, prefix))
+        except error.LookupError:
+            ui.status(_("skipping missing subrepository: %s\n")
+                           % join(subpath))
 
     if not dryrun:
         rejected = wctx.add(names, prefix)
--- a/mercurial/help/subrepos.txt	Tue Nov 01 23:53:29 2011 -0400
+++ b/mercurial/help/subrepos.txt	Wed Nov 02 01:17:11 2011 -0400
@@ -73,7 +73,9 @@
 -----------------------------------
 
 :add: add does not recurse in subrepos unless -S/--subrepos is
-    specified. Subversion subrepositories are currently silently
+    specified.  However, if you specify the full path of a file in a
+    subrepo, it will be added even without -S/--subrepos specified.
+    Subversion subrepositories are currently silently
     ignored.
 
 :archive: archive does not recurse in subrepositories unless
--- a/mercurial/subrepo.py	Tue Nov 01 23:53:29 2011 -0400
+++ b/mercurial/subrepo.py	Wed Nov 02 01:17:11 2011 -0400
@@ -353,6 +353,12 @@
                         unit=_('files'), total=total)
         ui.progress(_('archiving (%s)') % relpath, None)
 
+    def walk(self, match):
+        '''
+        walk recursively through the directory tree, finding all files
+        matched by the match function
+        '''
+        pass
 
 class hgsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
@@ -543,6 +549,9 @@
         ctx = self._repo[rev]
         return ctx.flags(name)
 
+    def walk(self, match):
+        ctx = self._repo[None]
+        return ctx.walk(match)
 
 class svnsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
--- a/tests/test-subrepo.t	Tue Nov 01 23:53:29 2011 -0400
+++ b/tests/test-subrepo.t	Wed Nov 02 01:17:11 2011 -0400
@@ -892,7 +892,7 @@
   $ hg init s
   $ hg ci -m0
   committing subrepository s
-Adding with an explicit path in a subrepo currently fails silently
+Adding with an explicit path in a subrepo adds the file
   $ echo c1 > f1
   $ echo c2 > s/f2
   $ hg st -S
@@ -900,14 +900,13 @@
   ? s/f2
   $ hg add s/f2
   $ hg st -S
+  A s/f2
   ? f1
-  ? s/f2
-  $ hg ci -R s -Am0
-  adding f2
+  $ hg ci -R s -m0
   $ hg ci -Am1
   adding f1
   committing subrepository s
-Adding with an explicit path in a subrepo with -S adds the file
+Adding with an explicit path in a subrepo with -S has the same behavior
   $ echo c3 > f3
   $ echo c4 > s/f4
   $ hg st -S