@@ -11,6 +11,8 @@ public partial class QuerySubmodules : Command
1111 private static partial Regex REG_FORMAT_STATUS ( ) ;
1212 [ GeneratedRegex ( @"^\s?[\w\?]{1,4}\s+(.+)$" ) ]
1313 private static partial Regex REG_FORMAT_DIRTY ( ) ;
14+ [ GeneratedRegex ( @"^submodule\.(\S*)\.(\w+)=(.*)$" ) ]
15+ private static partial Regex REG_FORMAT_MODULE_INFO ( ) ;
1416
1517 public QuerySubmodules ( string repo )
1618 {
@@ -25,7 +27,8 @@ public QuerySubmodules(string repo)
2527 var rs = ReadToEnd ( ) ;
2628
2729 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 ;
2932 foreach ( var line in lines )
3033 {
3134 var match = REG_FORMAT_STATUS ( ) . Match ( line ) ;
@@ -49,22 +52,64 @@ public QuerySubmodules(string repo)
4952 break ;
5053 default :
5154 module . Status = Models . SubmoduleStatus . Normal ;
52- needCheckLocalChanges . Add ( path , module ) ;
55+ needCheckLocalChanges = true ;
5356 break ;
5457 }
5558
59+ map . Add ( path , module ) ;
5660 submodules . Add ( module ) ;
5761 }
5862 }
5963
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 )
61103 {
62104 var builder = new StringBuilder ( ) ;
63- foreach ( var kv in needCheckLocalChanges )
105+ foreach ( var kv in map )
64106 {
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+ }
68113 }
69114
70115 Args = $ "--no-optional-locks status -uno --porcelain -- { builder } ";
@@ -79,13 +124,19 @@ public QuerySubmodules(string repo)
79124 if ( match . Success )
80125 {
81126 var path = match . Groups [ 1 ] . Value ;
82- if ( needCheckLocalChanges . TryGetValue ( path , out var m ) )
127+ if ( map . TryGetValue ( path , out var m ) )
83128 m . Status = Models . SubmoduleStatus . Modified ;
84129 }
85130 }
86131 }
87132
88133 return submodules ;
89134 }
135+
136+ private class ModuleInfo
137+ {
138+ public string Path { get ; set ; } = string . Empty ;
139+ public string URL { get ; set ; } = string . Empty ;
140+ }
90141 }
91142}
0 commit comments