diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2060,8 +2060,16 @@ def remove(ui, repo, m, prefix, after, f wctx = repo[None] - if subrepos: - for subpath in sorted(wctx.substate): + for subpath in sorted(wctx.substate): + def matchessubrepo(matcher, subpath): + if matcher.exact(subpath): + return True + for f in matcher.files(): + if f.startswith(subpath): + return True + return False + + if subrepos or matchessubrepo(m, subpath): sub = wctx.sub(subpath) try: submatch = matchmod.narrowmatcher(subpath, m) @@ -2080,7 +2088,7 @@ def remove(ui, repo, m, prefix, after, f return True return False - if f in repo.dirstate or f in wctx.dirs() or (subrepos and insubrepo()): + if f in repo.dirstate or f in wctx.dirs() or insubrepo(): continue if os.path.exists(m.rel(join(f))): diff --git a/mercurial/help/subrepos.txt b/mercurial/help/subrepos.txt --- a/mercurial/help/subrepos.txt +++ b/mercurial/help/subrepos.txt @@ -130,8 +130,10 @@ Interaction with Mercurial Commands ignored. :remove: remove does not recurse into subrepositories unless - -S/--subrepos is specified. Git and Subversion subrepositories - are currently silently ignored. + -S/--subrepos is specified. However, if you specify a file or + directory path in a subrepo, it will be removed even without + -S/--subrepos. Git and Subversion subrepositories are currently + silently ignored. :update: update restores the subrepos in the state they were originally committed in target changeset. If the recorded 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 @@ -120,6 +120,14 @@ Check that deep archiving works R sub1/sub2/folder/test.txt R sub1/sub2/test.txt $ hg update -Cq + $ hg remove -I 're:.*.txt' sub1 + $ hg status -S + $ hg remove sub1/sub2/folder/test.txt + $ hg remove sub1/.hgsubstate + $ hg status -S + R sub1/.hgsubstate + R sub1/sub2/folder/test.txt + $ hg update -Cq $ hg --config extensions.largefiles=! archive -S ../archive_all $ find ../archive_all | sort