[PATCH 1 of 2] subrepo: don't exclude files in .hgignore when adding to git

Matt Harbison mharbison72 at gmail.com
Tue Mar 3 03:43:40 UTC 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1424984034 18000
#      Thu Feb 26 15:53:54 2015 -0500
# Node ID 72f885c8b7aff110a147cc7ff12f5951bf5aaf03
# Parent  67952dc7a88faf32211e61b8f9606f62d271eaf3
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 @@
     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
 
-        files = [f for f in files if match(f)]
+        (modified, added, removed,
+         deleted, unknown, ignored, clean) = self.status(None)
+
+        # 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 @@
   > *.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


More information about the Mercurial-devel mailing list