Patchwork [V3] subrepos: support adding files in git subrepos

login
register
mail settings
Submitter Mathias De Maré
Date Feb. 27, 2015, 7:15 p.m.
Message ID <8fd7bd0c2fc4726916d5.1425064510@mathias-1015PE>
Download mbox | patch
Permalink /patch/7849/
State Accepted
Headers show

Comments

Mathias De Maré - Feb. 27, 2015, 7:15 p.m.
# HG changeset patch
# User Mathias De Maré <mathias.demare@gmail.com>
# Date 1424764162 -3600
#      Tue Feb 24 08:49:22 2015 +0100
# Node ID 8fd7bd0c2fc4726916d5fba76c590fa820089dc1
# Parent  54c7ba64eddcbee8c5d6bfdb54a7074a7369fba9
subrepos: support adding files in git subrepos

This support includes correct matching, so includes,
excludes and patterns are all supported.
Matt Harbison - Feb. 28, 2015, 12:48 a.m.
On Fri, 27 Feb 2015 14:15:10 -0500, Mathias De Maré  
<mathias.demare@gmail.com> wrote:

> # HG changeset patch
> # User Mathias De Maré <mathias.demare@gmail.com>
> # Date 1424764162 -3600
> #      Tue Feb 24 08:49:22 2015 +0100
> # Node ID 8fd7bd0c2fc4726916d5fba76c590fa820089dc1
> # Parent  54c7ba64eddcbee8c5d6bfdb54a7074a7369fba9
> subrepos: support adding files in git subrepos

Looks good to me.  I'll follow up with the .hgignore fix once this lands.

--Matt
Pierre-Yves David - March 2, 2015, 8:57 p.m.
On 02/27/2015 07:15 PM, Mathias De Maré wrote:
> # HG changeset patch
> # User Mathias De Maré <mathias.demare@gmail.com>
> # Date 1424764162 -3600
> #      Tue Feb 24 08:49:22 2015 +0100
> # Node ID 8fd7bd0c2fc4726916d5fba76c590fa820089dc1
> # Parent  54c7ba64eddcbee8c5d6bfdb54a7074a7369fba9
> subrepos: support adding files in git subrepos

Looks good to me and pushed to the clowncopter.

pyflakes sents his greeting.

Patch

diff --git a/mercurial/help/subrepos.txt b/mercurial/help/subrepos.txt
--- a/mercurial/help/subrepos.txt
+++ b/mercurial/help/subrepos.txt
@@ -78,7 +78,7 @@ 
 :add: add does not recurse in subrepos unless -S/--subrepos is
     specified.  However, if you specify the full path of a file in a
     subrepo, it will be added even without -S/--subrepos specified.
-    Git and Subversion subrepositories are currently silently
+    Subversion subrepositories are currently silently
     ignored.
 
 :addremove: addremove does not recurse into subrepos unless
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1524,6 +1524,30 @@ 
             return False
 
     @annotatesubrepoerror
+    def add(self, ui, match, prefix, explicitonly, **opts):
+        if self._gitmissing():
+            return []
+        rev = self._state[1]
+        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)]
+        for f in files:
+            exact = match.exact(f)
+            command = ["add"]
+            if exact:
+                command.append("-f") #should be added, even if ignored
+            if ui.verbose or not exact:
+                ui.status(_('adding %s\n') % match.rel(f))
+            if not opts.get('dry_run'):
+                self._gitcommand(command + [f])
+        return []
+
+    @annotatesubrepoerror
     def remove(self):
         if self._gitmissing():
             return
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
@@ -134,6 +134,7 @@ 
   $ hg status --subrepos
   ? s/f
   $ hg add .
+  adding f
   $ git add f
   $ cd ..
 
@@ -850,4 +851,130 @@ 
   $ hg cat -r "parents(.)" --output tmp/%b/foobar s/foobar
   $ diff tmp/tc/foobar catparents
 
+cleanup
+  $ rm -r tmp
+  $ rm catparents
+
+add git files, using either files or patterns
+  $ echo "hsss! hsssssssh!" > s/snake.python
+  $ echo "ccc" > s/c.c
+  $ echo "cpp" > s/cpp.cpp
+
+  $ hg add s/snake.python s/c.c s/cpp.cpp
+  $ hg st --subrepos s
+  M s/foobar
+  A s/c.c
+  A s/cpp.cpp
+  A s/snake.python
+  ? s/barfoo
+  $ hg revert s
+  reverting subrepo ../gitroot
+
+  $ hg add --subrepos "glob:**.python"
+  adding s/snake.python (glob)
+  $ hg st --subrepos s
+  A s/snake.python
+  ? s/barfoo
+  ? s/c.c
+  ? s/cpp.cpp
+  ? s/foobar.orig
+  $ hg revert s
+  reverting subrepo ../gitroot
+
+  $ hg add --subrepos s
+  adding s/barfoo (glob)
+  adding s/c.c (glob)
+  adding s/cpp.cpp (glob)
+  adding s/foobar.orig (glob)
+  adding s/snake.python (glob)
+  $ hg st --subrepos s
+  A s/barfoo
+  A s/c.c
+  A s/cpp.cpp
+  A s/foobar.orig
+  A s/snake.python
+  $ hg revert s
+  reverting subrepo ../gitroot
+make sure everything is reverted correctly
+  $ hg st --subrepos s
+  ? s/barfoo
+  ? s/c.c
+  ? s/cpp.cpp
+  ? s/foobar.orig
+  ? s/snake.python
+
+  $ hg add --subrepos --exclude "path:s/c.c"
+  adding s/barfoo (glob)
+  adding s/cpp.cpp (glob)
+  adding s/foobar.orig (glob)
+  adding s/snake.python (glob)
+  $ hg st --subrepos s
+  A s/barfoo
+  A s/cpp.cpp
+  A s/foobar.orig
+  A s/snake.python
+  ? s/c.c
+  $ hg revert --all -q
+
+.hgignore should not have influence in subrepos
+  $ cat > .hgignore << EOF
+  > syntax: glob
+  > *.python
+  > EOF
+  $ hg add .hgignore
+  $ hg add --subrepos "glob:**.python"
+  adding s/snake.python (glob)
+  $ hg st --subrepos s
+  A s/snake.python
+  ? s/barfoo
+  ? s/c.c
+  ? s/cpp.cpp
+  ? s/foobar.orig
+  $ hg revert --all -q
+
+.gitignore should have influence,
+except for explicitly added files (no patterns)
+  $ cat > s/.gitignore << EOF
+  > *.python
+  > EOF
+  $ hg add s/.gitignore
+  $ hg st --subrepos s
+  A s/.gitignore
+  ? s/barfoo
+  ? s/c.c
+  ? s/cpp.cpp
+  ? s/foobar.orig
+  $ hg add --subrepos "glob:**.python"
+  $ hg st --subrepos s
+  A s/.gitignore
+  ? s/barfoo
+  ? s/c.c
+  ? s/cpp.cpp
+  ? s/foobar.orig
+  $ hg add --subrepos s/snake.python
+  $ hg st --subrepos s
+  A s/.gitignore
+  A s/snake.python
+  ? s/barfoo
+  ? s/c.c
+  ? s/cpp.cpp
+  ? s/foobar.orig
+
+correctly do a dry run
+  $ hg add --subrepos s --dry-run
+  adding s/barfoo (glob)
+  adding s/c.c (glob)
+  adding s/cpp.cpp (glob)
+  adding s/foobar.orig (glob)
+  $ hg st --subrepos s
+  A s/.gitignore
+  A s/snake.python
+  ? s/barfoo
+  ? s/c.c
+  ? s/cpp.cpp
+  ? s/foobar.orig
+
+currently no error given when adding an already tracked file
+  $ hg add s/.gitignore
+
   $ cd ..