diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2340,14 +2340,15 @@ def files(ui, ctx, m, fm, fmt, subrepos) for subpath in sorted(ctx.substate): def matchessubrepo(subpath): - return (m.always() or m.exact(subpath) + return (m.exact(subpath) or any(f.startswith(subpath + '/') for f in m.files())) if subrepos or matchessubrepo(subpath): sub = ctx.sub(subpath) try: submatch = matchmod.narrowmatcher(subpath, m) - if sub.printfiles(ui, submatch, fm, fmt, subrepos) == 0: + recurse = m.exact(subpath) or subrepos + if sub.printfiles(ui, submatch, fm, fmt, recurse) == 0: ret = 0 except error.LookupError: ui.status(_("skipping missing subrepository: %s\n") 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 @@ -297,6 +297,12 @@ Files sees uncommitted adds and removes sub1/sub2/folder/bar (glob) sub1/sub2/x.txt (glob) + $ hg files + .hgsub + .hgsubstate + foo/bar/abc (glob) + main + $ hg files -S -r '.^' sub1/sub2/folder sub1/sub2/folder/test.txt (glob)