diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
index b7e192240c41db8d02419b7bcd2be9a2b6194023_bWVyY3VyaWFsL2NtZHV0aWwucHk=..97175d9bf7cf14db3747ff3f2b093ea2ed34db95_bWVyY3VyaWFsL2NtZHV0aWwucHk= 100644
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2340,10 +2340,10 @@
 
     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)
@@ -2344,10 +2344,11 @@
                     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
index b7e192240c41db8d02419b7bcd2be9a2b6194023_dGVzdHMvdGVzdC1zdWJyZXBvLWRlZXAtbmVzdGVkLWNoYW5nZS50..97175d9bf7cf14db3747ff3f2b093ea2ed34db95_dGVzdHMvdGVzdC1zdWJyZXBvLWRlZXAtbmVzdGVkLWNoYW5nZS50 100644
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -297,6 +297,12 @@
   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)