diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -1165,15 +1165,19 @@ def add(ui, repo, match, dryrun, listsub 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) diff --git a/mercurial/help/subrepos.txt b/mercurial/help/subrepos.txt --- a/mercurial/help/subrepos.txt +++ b/mercurial/help/subrepos.txt @@ -73,7 +73,9 @@ Interaction with Mercurial Commands ----------------------------------- :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 diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -353,6 +353,12 @@ class abstractsubrepo(object): 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 @@ class hgsubrepo(abstractsubrepo): 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): diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t --- a/tests/test-subrepo.t +++ b/tests/test-subrepo.t @@ -892,7 +892,7 @@ Test behavior of add for explicit path i $ 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 @@ Adding with an explicit path in a subrep ? 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