diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -1526,14 +1526,15 @@ class gitsubrepo(abstractsubrepo): def add(self, ui, match, prefix, explicitonly, **opts): if self._gitmissing(): return [] - if match.files(): - files = match.files() - else: - (modified, added, removed, - deleted, unknown, ignored, clean) = self.status(None) - files = unknown + + (modified, added, removed, + deleted, unknown, ignored, clean) = self.status(None) - files = [f for f in files if match(f)] + # Unknown files not of interest will be rejected by the matcher + files = unknown + files.extend(match.files()) + + files = [f for f in sorted(set(files)) if match(f)] for f in files: exact = match.exact(f) command = ["add"] diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t --- a/tests/test-subrepo-git.t +++ b/tests/test-subrepo-git.t @@ -922,11 +922,11 @@ make sure everything is reverted correct > *.python > EOF $ hg add .hgignore - $ hg add --subrepos "glob:**.python" + $ hg add --subrepos "glob:**.python" s/barfoo adding s/snake.python (glob) $ hg st --subrepos s + A s/barfoo A s/snake.python - ? s/barfoo ? s/c.c ? s/cpp.cpp ? s/foobar.orig