# HG changeset patch # User Matt Harbison # Date 2015-02-26 20:53:54 # Node ID 00ef3edcf1d5d0b1bb7215e785460769f48acfe8 # Parent 5245caa0dcde940ce11d2356aa01f446f08659c8 subrepo: don't exclude files in .hgignore when adding to git The previous test gave a false success because only an hg-ignored pattern was specified. Therefore match.files() was empty, and it fell back to the files unknown to git. The simplest fix is to always consider what is unknown to git, as well as anything specified explicitly. Files that are ignored by git can only be introduced by an explicit mention in match.files(). 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