1
1
using System . Collections . Generic ;
2
+ using System . Text ;
2
3
using System . Text . RegularExpressions ;
3
4
4
5
namespace SourceGit . Commands
@@ -9,6 +10,8 @@ public partial class QuerySubmodules : Command
9
10
private static partial Regex REG_FORMAT1 ( ) ;
10
11
[ GeneratedRegex ( @"^[\-\+ ][0-9a-f]+\s(.*)$" ) ]
11
12
private static partial Regex REG_FORMAT2 ( ) ;
13
+ [ GeneratedRegex ( @"^\s?[\w\?]{1,4}\s+(.+)$" ) ]
14
+ private static partial Regex REG_FORMAT_STATUS ( ) ;
12
15
13
16
public QuerySubmodules ( string repo )
14
17
{
@@ -17,28 +20,59 @@ public QuerySubmodules(string repo)
17
20
Args = "submodule status" ;
18
21
}
19
22
20
- public List < string > Result ( )
23
+ public List < Models . Submodule > Result ( )
21
24
{
22
- Exec ( ) ;
23
- return _submodules ;
24
- }
25
+ var submodules = new List < Models . Submodule > ( ) ;
26
+ var rs = ReadToEnd ( ) ;
27
+ if ( ! rs . IsSuccess )
28
+ return submodules ;
25
29
26
- protected override void OnReadline ( string line )
27
- {
28
- var match = REG_FORMAT1 ( ) . Match ( line ) ;
29
- if ( match . Success )
30
+ var builder = new StringBuilder ( ) ;
31
+ var lines = rs . StdOut . Split ( '\n ' , System . StringSplitOptions . RemoveEmptyEntries ) ;
32
+ foreach ( var line in lines )
30
33
{
31
- _submodules . Add ( match . Groups [ 1 ] . Value ) ;
32
- return ;
34
+ var match = REG_FORMAT1 ( ) . Match ( line ) ;
35
+ if ( match . Success )
36
+ {
37
+ var path = match . Groups [ 1 ] . Value ;
38
+ builder . Append ( $ "\" { path } \" ") ;
39
+ submodules . Add ( new Models . Submodule ( ) { Path = path } ) ;
40
+ continue ;
41
+ }
42
+
43
+ match = REG_FORMAT2 ( ) . Match ( line ) ;
44
+ if ( match . Success )
45
+ {
46
+ var path = match . Groups [ 1 ] . Value ;
47
+ builder . Append ( $ "\" { path } \" ") ;
48
+ submodules . Add ( new Models . Submodule ( ) { Path = path } ) ;
49
+ }
33
50
}
34
51
35
- match = REG_FORMAT2 ( ) . Match ( line ) ;
36
- if ( match . Success )
52
+ if ( submodules . Count > 0 )
37
53
{
38
- _submodules . Add ( match . Groups [ 1 ] . Value ) ;
54
+ Args = $ "status -uno --porcelain -- { builder } ";
55
+ rs = ReadToEnd ( ) ;
56
+ if ( ! rs . IsSuccess )
57
+ return submodules ;
58
+
59
+ var dirty = new HashSet < string > ( ) ;
60
+ lines = rs . StdOut . Split ( '\n ' , System . StringSplitOptions . RemoveEmptyEntries ) ;
61
+ foreach ( var line in lines )
62
+ {
63
+ var match = REG_FORMAT_STATUS ( ) . Match ( line ) ;
64
+ if ( match . Success )
65
+ {
66
+ var path = match . Groups [ 1 ] . Value ;
67
+ dirty . Add ( path ) ;
68
+ }
69
+ }
70
+
71
+ foreach ( var submodule in submodules )
72
+ submodule . IsDirty = dirty . Contains ( submodule . Path ) ;
39
73
}
40
- }
41
74
42
- private readonly List < string > _submodules = new List < string > ( ) ;
75
+ return submodules ;
76
+ }
43
77
}
44
78
}
0 commit comments