@@ -91,7 +91,7 @@ public static bool RevertAllChanges()
91
91
}
92
92
93
93
private delegate bool AddState ( string type , FileStates stateType ) ;
94
- private static void ParseFileState ( string line , ref int mode , List < FileState > states )
94
+ private static bool ParseFileState ( string line , ref int mode , List < FileState > states )
95
95
{
96
96
var addState = new AddState ( delegate ( string type , FileStates stateType )
97
97
{
@@ -127,52 +127,52 @@ private static void ParseFileState(string line, ref int mode, List<FileState> st
127
127
// gather normal files
128
128
switch ( line )
129
129
{
130
- case "Changes to be committed:" : mode = 0 ; return ;
131
- case "Changes not staged for commit:" : mode = 1 ; return ;
132
- case "Unmerged paths:" : mode = 2 ; return ;
133
- case "Untracked files:" : mode = 3 ; return ;
130
+ case "Changes to be committed:" : mode = 0 ; return true ;
131
+ case "Changes not staged for commit:" : mode = 1 ; return true ;
132
+ case "Unmerged paths:" : mode = 2 ; return true ;
133
+ case "Untracked files:" : mode = 3 ; return true ;
134
134
}
135
135
136
+ bool pass = false ;
136
137
if ( mode == 0 )
137
138
{
138
- bool pass = addState ( "\t new file:" , FileStates . NewInIndex ) ;
139
+ pass = addState ( "\t new file:" , FileStates . NewInIndex ) ;
139
140
if ( ! pass ) pass = addState ( "\t modified:" , FileStates . ModifiedInIndex ) ;
140
141
if ( ! pass ) pass = addState ( "\t deleted:" , FileStates . DeletedFromIndex ) ;
141
142
if ( ! pass ) pass = addState ( "\t renamed:" , FileStates . RenamedInIndex ) ;
142
- // TODO: check for valid unhanled types
143
- //if (!pass)
144
- //{
145
- // var match = Regex.Match(line, @"\t(.*):");
146
- // if (match.Success)
147
- // {
148
-
149
- // return false;
150
- // }
151
- //}
152
143
}
153
144
else if ( mode == 1 )
154
145
{
155
- bool pass = addState ( "\t modified:" , FileStates . ModifiedInWorkdir ) ;
146
+ pass = addState ( "\t modified:" , FileStates . ModifiedInWorkdir ) ;
156
147
if ( ! pass ) pass = addState ( "\t deleted:" , FileStates . DeletedFromWorkdir ) ;
157
148
if ( ! pass ) pass = addState ( "\t renamed:" , FileStates . RenamedInWorkdir ) ;
158
149
}
159
150
else if ( mode == 2 )
160
151
{
161
- addState ( "\t both modified:" , FileStates . Conflicted ) ;
152
+ pass = addState ( "\t both modified:" , FileStates . Conflicted ) ;
162
153
}
163
154
else if ( mode == 3 )
164
155
{
165
- addState ( "\t " , FileStates . NewInWorkdir ) ;
156
+ pass = addState ( "\t " , FileStates . NewInWorkdir ) ;
166
157
}
158
+
159
+ if ( ! pass )
160
+ {
161
+ var match = Regex . Match ( line , @"\t(.*):" ) ;
162
+ if ( match . Success ) return false ;
163
+ }
164
+
165
+ return true ;
167
166
}
168
167
169
168
public static bool GetFileState ( string filename , out FileState fileState )
170
169
{
171
170
var states = new List < FileState > ( ) ;
172
171
int mode = - 1 ;
172
+ bool failedToParse = false ;
173
173
var stdCallback = new StdCallbackMethod ( delegate ( string line )
174
174
{
175
- ParseFileState ( line , ref mode , states ) ;
175
+ if ( ! ParseFileState ( line , ref mode , states ) ) failedToParse = true ;
176
176
} ) ;
177
177
178
178
var result = Tools . RunExe ( "git" , string . Format ( "status -u \" {0}\" " , filename ) , stdCallback : stdCallback ) ;
@@ -183,6 +183,12 @@ public static bool GetFileState(string filename, out FileState fileState)
183
183
fileState = null ;
184
184
return false ;
185
185
}
186
+
187
+ if ( failedToParse )
188
+ {
189
+ fileState = null ;
190
+ return false ;
191
+ }
186
192
187
193
if ( states . Count != 0 )
188
194
{
@@ -200,9 +206,10 @@ public static bool GetFileStates(out FileState[] fileStates)
200
206
{
201
207
var states = new List < FileState > ( ) ;
202
208
int mode = - 1 ;
209
+ bool failedToParse = false ;
203
210
var stdCallback = new StdCallbackMethod ( delegate ( string line )
204
211
{
205
- ParseFileState ( line , ref mode , states ) ;
212
+ if ( ! ParseFileState ( line , ref mode , states ) ) failedToParse = true ;
206
213
} ) ;
207
214
208
215
var result = Tools . RunExe ( "git" , "status -u" , stdCallback : stdCallback ) ;
@@ -214,6 +221,12 @@ public static bool GetFileStates(out FileState[] fileStates)
214
221
return false ;
215
222
}
216
223
224
+ if ( failedToParse )
225
+ {
226
+ fileStates = null ;
227
+ return false ;
228
+ }
229
+
217
230
fileStates = states . ToArray ( ) ;
218
231
return true ;
219
232
}
0 commit comments