subrepo: don't exclude files in .hgignore when adding to git
authorMatt Harbison <matt_harbison@yahoo.com>
Thu, 26 Feb 2015 15:53:54 -0500
changeset 24182 00ef3edcf1d5
parent 24181 5245caa0dcde
child 24183 932de135041f
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().
mercurial/subrepo.py
tests/test-subrepo-git.t
--- a/mercurial/subrepo.py	Wed Jan 14 01:15:26 2015 +0100
+++ b/mercurial/subrepo.py	Thu Feb 26 15:53:54 2015 -0500
@@ -1526,14 +1526,15 @@
     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"]
--- a/tests/test-subrepo-git.t	Wed Jan 14 01:15:26 2015 +0100
+++ b/tests/test-subrepo-git.t	Thu Feb 26 15:53:54 2015 -0500
@@ -922,11 +922,11 @@
   > *.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