@@ -11,6 +11,10 @@ public partial class QuerySubmodules : Command
11
11
private static partial Regex REG_FORMAT_STATUS ( ) ;
12
12
[ GeneratedRegex ( @"^\s?[\w\?]{1,4}\s+(.+)$" ) ]
13
13
private static partial Regex REG_FORMAT_DIRTY ( ) ;
14
+ [ GeneratedRegex ( @"^submodule\.(\S*)\.path=(.*)$" ) ]
15
+ private static partial Regex REG_FORMAT_PATH ( ) ;
16
+ [ GeneratedRegex ( @"^submodule\.(\S*)\.url=(.*)$" ) ]
17
+ private static partial Regex REG_FORMAT_URL ( ) ;
14
18
15
19
public QuerySubmodules ( string repo )
16
20
{
@@ -25,7 +29,8 @@ public QuerySubmodules(string repo)
25
29
var rs = ReadToEnd ( ) ;
26
30
27
31
var lines = rs . StdOut . Split ( [ '\r ' , '\n ' ] , StringSplitOptions . RemoveEmptyEntries ) ;
28
- var needCheckLocalChanges = new Dictionary < string , Models . Submodule > ( ) ;
32
+ var map = new Dictionary < string , Models . Submodule > ( ) ;
33
+ var needCheckLocalChanges = false ;
29
34
foreach ( var line in lines )
30
35
{
31
36
var match = REG_FORMAT_STATUS ( ) . Match ( line ) ;
@@ -49,22 +54,69 @@ public QuerySubmodules(string repo)
49
54
break ;
50
55
default :
51
56
module . Status = Models . SubmoduleStatus . Normal ;
52
- needCheckLocalChanges . Add ( path , module ) ;
57
+ needCheckLocalChanges = true ;
53
58
break ;
54
59
}
55
60
61
+ map . Add ( path , module ) ;
56
62
submodules . Add ( module ) ;
57
63
}
58
64
}
59
65
60
- if ( needCheckLocalChanges . Count > 0 )
66
+ if ( submodules . Count > 0 )
67
+ {
68
+ Args = "config --file .gitmodules --list" ;
69
+ rs = ReadToEnd ( ) ;
70
+ if ( rs . IsSuccess )
71
+ {
72
+ var modules = new Dictionary < string , ModuleInfo > ( ) ;
73
+ lines = rs . StdOut . Split ( [ '\r ' , '\n ' ] , StringSplitOptions . RemoveEmptyEntries ) ;
74
+ foreach ( var line in lines )
75
+ {
76
+ var match = REG_FORMAT_PATH ( ) . Match ( line ) ;
77
+ if ( match . Success )
78
+ {
79
+ var name = match . Groups [ 1 ] . Value ;
80
+ var path = match . Groups [ 2 ] . Value ;
81
+ if ( modules . TryGetValue ( name , out var m ) )
82
+ m . Path = path ;
83
+ else
84
+ modules . Add ( name , new ModuleInfo ( ) { Path = path } ) ;
85
+
86
+ continue ;
87
+ }
88
+
89
+ match = REG_FORMAT_URL ( ) . Match ( line ) ;
90
+ if ( match . Success )
91
+ {
92
+ var name = match . Groups [ 1 ] . Value ;
93
+ var url = match . Groups [ 2 ] . Value ;
94
+ if ( modules . TryGetValue ( name , out var m ) )
95
+ m . URL = url ;
96
+ else
97
+ modules . Add ( name , new ModuleInfo ( ) { URL = url } ) ;
98
+ }
99
+ }
100
+
101
+ foreach ( var kv in modules )
102
+ {
103
+ if ( map . TryGetValue ( kv . Value . Path , out var m ) )
104
+ m . URL = kv . Value . URL ;
105
+ }
106
+ }
107
+ }
108
+
109
+ if ( needCheckLocalChanges )
61
110
{
62
111
var builder = new StringBuilder ( ) ;
63
- foreach ( var kv in needCheckLocalChanges )
112
+ foreach ( var kv in map )
64
113
{
65
- builder . Append ( '"' ) ;
66
- builder . Append ( kv . Key ) ;
67
- builder . Append ( "\" " ) ;
114
+ if ( kv . Value . Status == Models . SubmoduleStatus . Normal )
115
+ {
116
+ builder . Append ( '"' ) ;
117
+ builder . Append ( kv . Key ) ;
118
+ builder . Append ( "\" " ) ;
119
+ }
68
120
}
69
121
70
122
Args = $ "--no-optional-locks status -uno --porcelain -- { builder } ";
@@ -79,13 +131,19 @@ public QuerySubmodules(string repo)
79
131
if ( match . Success )
80
132
{
81
133
var path = match . Groups [ 1 ] . Value ;
82
- if ( needCheckLocalChanges . TryGetValue ( path , out var m ) )
134
+ if ( map . TryGetValue ( path , out var m ) )
83
135
m . Status = Models . SubmoduleStatus . Modified ;
84
136
}
85
137
}
86
138
}
87
139
88
140
return submodules ;
89
141
}
142
+
143
+ private class ModuleInfo
144
+ {
145
+ public string Path { get ; set ; } = string . Empty ;
146
+ public string URL { get ; set ; } = string . Empty ;
147
+ }
90
148
}
91
149
}
0 commit comments