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

login
register
mail settings
Submitter Matt Harbison
Date March 3, 2015, 3:43 a.m.
Message ID <72f885c8b7aff110a147.1425354220@Envy>
Download mbox | patch
Permalink /patch/7883/
State Accepted
Commit 00ef3edcf1d5d0b1bb7215e785460769f48acfe8
Headers show

Comments

Matt Harbison - March 3, 2015, 3:43 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@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().
Mathias De Maré - March 3, 2015, 5:39 p.m.
On Tue, Mar 3, 2015 at 4:43 AM, Matt Harbison <mharbison72@gmail.com> wrote:

> # HG changeset patch
> # User Matt Harbison <matt_harbison@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().
>

This looks good to me.

Greetings,
Mathias

>
> 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
>

Patch

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