@@ -11,6 +11,10 @@ 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*)\.path=(.*)$" ) ]
15+ private static partial Regex REG_FORMAT_PATH ( ) ;
16+ [ GeneratedRegex ( @"^submodule\.(\S*)\.url=(.*)$" ) ]
17+ private static partial Regex REG_FORMAT_URL ( ) ;
1418
1519 public QuerySubmodules ( string repo )
1620 {
@@ -25,7 +29,8 @@ public QuerySubmodules(string repo)
2529 var rs = ReadToEnd ( ) ;
2630
2731 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 ;
2934 foreach ( var line in lines )
3035 {
3136 var match = REG_FORMAT_STATUS ( ) . Match ( line ) ;
@@ -49,22 +54,69 @@ public QuerySubmodules(string repo)
4954 break ;
5055 default :
5156 module . Status = Models . SubmoduleStatus . Normal ;
52- needCheckLocalChanges . Add ( path , module ) ;
57+ needCheckLocalChanges = true ;
5358 break ;
5459 }
5560
61+ map . Add ( path , module ) ;
5662 submodules . Add ( module ) ;
5763 }
5864 }
5965
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 )
61110 {
62111 var builder = new StringBuilder ( ) ;
63- foreach ( var kv in needCheckLocalChanges )
112+ foreach ( var kv in map )
64113 {
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+ }
68120 }
69121
70122 Args = $ "--no-optional-locks status -uno --porcelain -- { builder } ";
@@ -79,13 +131,19 @@ public QuerySubmodules(string repo)
79131 if ( match . Success )
80132 {
81133 var path = match . Groups [ 1 ] . Value ;
82- if ( needCheckLocalChanges . TryGetValue ( path , out var m ) )
134+ if ( map . TryGetValue ( path , out var m ) )
83135 m . Status = Models . SubmoduleStatus . Modified ;
84136 }
85137 }
86138 }
87139
88140 return submodules ;
89141 }
142+
143+ private class ModuleInfo
144+ {
145+ public string Path { get ; set ; } = string . Empty ;
146+ public string URL { get ; set ; } = string . Empty ;
147+ }
90148 }
91149}
0 commit comments