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