Patchwork [V2] subrepo: add status support for untracked files in git subrepos

login
register
mail settings
Submitter Mathias De Maré
Date Dec. 2, 2014, 5:20 a.m.
Message ID <22008bac811bec11c3e9.1417497657@mathias-Latitude-E6540>
Download mbox | patch
Permalink /patch/6943/
State Not Applicable
Headers show

Comments

Mathias De Maré - Dec. 2, 2014, 5:20 a.m.
# HG changeset patch
# User Mathias De Maré <mathias.demare@gmail.com>
# Date 1417292190 -3600
#      Sam Nov 29 21:16:30 2014 +0100
# Node ID 22008bac811bec11c3e938d5aa4281aafe68bd76
# Parent  b913c394386f0a6ebbdcb7e321ff82816d7799fe
subrepo: add status support for untracked files in git subrepos

Retrieving the status of a git subrepo did not show untracked
files. Using 'git ls-files', we can retrieve these files
and display the correct status.
Mathias De Maré - Dec. 2, 2014, 7:32 a.m.
Please ignore this patch, V1 has already been pushed (and this one only has
a different commit message).

On Tue, Dec 2, 2014 at 6:20 AM, Mathias De Maré <mathias.demare@gmail.com>
wrote:

> # HG changeset patch
> # User Mathias De Maré <mathias.demare@gmail.com>
> # Date 1417292190 -3600
> #      Sam Nov 29 21:16:30 2014 +0100
> # Node ID 22008bac811bec11c3e938d5aa4281aafe68bd76
> # Parent  b913c394386f0a6ebbdcb7e321ff82816d7799fe
> subrepo: add status support for untracked files in git subrepos
>
> Retrieving the status of a git subrepo did not show untracked
> files. Using 'git ls-files', we can retrieve these files
> and display the correct status.
>
> diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
> --- a/mercurial/subrepo.py
> +++ b/mercurial/subrepo.py
> @@ -1565,16 +1565,25 @@ class gitsubrepo(abstractsubrepo):
>              if status == 'M':
>                  modified.append(f)
>              elif status == 'A':
>                  added.append(f)
>              elif status == 'D':
>                  removed.append(f)
>
>          deleted, unknown, ignored, clean = [], [], [], []
> +
> +        if not rev2:
> +            command = ['ls-files', '--others', '--exclude-standard']
> +            out = self._gitcommand(command)
> +            for line in out.split('\n'):
> +                if len(line) == 0:
> +                    continue
> +                unknown.append(line)
> +
>          return scmutil.status(modified, added, removed, deleted,
>                                unknown, ignored, clean)
>
>      def shortid(self, revid):
>          return revid[:7]
>
>  types = {
>      'hg': hgsubrepo,
> 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
> @@ -114,17 +114,20 @@ clone root separately, make different lo
>
>    $ cd ../t
>    $ hg clone . ../tb 2> /dev/null
>    updating to branch default
>    cloning subrepo s from $TESTTMP/gitroot
>    3 files updated, 0 files merged, 0 files removed, 0 files unresolved
>
>    $ cd ../tb/s
> +  $ hg status --subrepos
>    $ echo f > f
> +  $ hg status --subrepos
> +  ? s/f
>    $ git add f
>    $ cd ..
>
>    $ hg status --subrepos
>    A s/f
>    $ hg commit --subrepos -m f
>    committing subrepository s
>    $ hg debugsub
> @@ -417,24 +420,27 @@ Check hg update --clean
>    $ cd s
>    $ echo c1 > f1
>    $ echo c1 > f2
>    $ git add f1
>    $ cd ..
>    $ hg status -S
>    M s/g
>    A s/f1
> +  ? s/f2
>    $ ls s
>    f
>    f1
>    f2
>    g
>    $ hg update --clean
>    1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>    $ hg status -S
> +  ? s/f1
> +  ? s/f2
>    $ ls s
>    f
>    f1
>    f2
>    g
>
>  Sticky subrepositories, no changes
>    $ cd $TESTTMP/ta
>

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1565,16 +1565,25 @@  class gitsubrepo(abstractsubrepo):
             if status == 'M':
                 modified.append(f)
             elif status == 'A':
                 added.append(f)
             elif status == 'D':
                 removed.append(f)
 
         deleted, unknown, ignored, clean = [], [], [], []
+
+        if not rev2:
+            command = ['ls-files', '--others', '--exclude-standard']
+            out = self._gitcommand(command)
+            for line in out.split('\n'):
+                if len(line) == 0:
+                    continue
+                unknown.append(line)
+
         return scmutil.status(modified, added, removed, deleted,
                               unknown, ignored, clean)
 
     def shortid(self, revid):
         return revid[:7]
 
 types = {
     'hg': hgsubrepo,
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
@@ -114,17 +114,20 @@  clone root separately, make different lo
 
   $ cd ../t
   $ hg clone . ../tb 2> /dev/null
   updating to branch default
   cloning subrepo s from $TESTTMP/gitroot
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ cd ../tb/s
+  $ hg status --subrepos
   $ echo f > f
+  $ hg status --subrepos
+  ? s/f
   $ git add f
   $ cd ..
 
   $ hg status --subrepos
   A s/f
   $ hg commit --subrepos -m f
   committing subrepository s
   $ hg debugsub
@@ -417,24 +420,27 @@  Check hg update --clean
   $ cd s
   $ echo c1 > f1
   $ echo c1 > f2
   $ git add f1
   $ cd ..
   $ hg status -S
   M s/g
   A s/f1
+  ? s/f2
   $ ls s
   f
   f1
   f2
   g
   $ hg update --clean
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg status -S
+  ? s/f1
+  ? s/f2
   $ ls s
   f
   f1
   f2
   g
 
 Sticky subrepositories, no changes
   $ cd $TESTTMP/ta