@@ -125,8 +125,6 @@ private bool TryUpdateSource(string name, string branch, string relativePath, ID
125
125
_logger . LogInformation ( "Pull: {Name}\t {Branch}\t {RelativePath}" , name , branch , relativePath ) ;
126
126
// --allow-unrelated-histories due to shallow clones not finding a common ancestor
127
127
ExecIn ( checkoutFolder , "git" , "pull" , "--depth" , "1" , "--allow-unrelated-histories" , "--no-ff" ) ;
128
- head = Capture ( checkoutFolder , "git" , "rev-parse" , "HEAD" ) ;
129
- return true ;
130
128
}
131
129
catch ( Exception e )
132
130
{
@@ -136,9 +134,12 @@ private bool TryUpdateSource(string name, string branch, string relativePath, ID
136
134
checkoutFolder . Delete ( true ) ;
137
135
checkoutFolder . Refresh ( ) ;
138
136
}
137
+ return false ;
139
138
}
140
139
141
- return false ;
140
+ head = Capture ( checkoutFolder , "git" , "rev-parse" , "HEAD" ) ;
141
+
142
+ return true ;
142
143
}
143
144
144
145
private string CheckoutFromScratch ( Repository repository , string name , string branch , string relativePath ,
@@ -183,19 +184,26 @@ private void ExecIn(IDirectoryInfo? workingDirectory, string binary, params stri
183
184
// ReSharper disable once UnusedMember.Local
184
185
private string Capture ( IDirectoryInfo ? workingDirectory , string binary , params string [ ] args )
185
186
{
186
- // Try 10 times to capture the output of the command, if it fails we'll throw an exception on the last try
187
- for ( var i = 0 ; i < 9 ; i ++ )
187
+ // Try 10 times to capture the output of the command, if it fails, we'll throw an exception on the last try
188
+ Exception ? e = null ;
189
+ for ( var i = 0 ; i <= 9 ; i ++ )
188
190
{
189
191
try
190
192
{
191
193
return CaptureOutput ( ) ;
192
194
}
193
- catch
195
+ catch ( Exception ex )
194
196
{
195
- // ignored
197
+ if ( ex is not null )
198
+ e = ex ;
196
199
}
197
200
}
198
- return CaptureOutput ( ) ;
201
+
202
+ if ( e is not null )
203
+ collector . EmitError ( "" , "failure capturing stdout" , e ) ;
204
+
205
+
206
+ return string . Empty ;
199
207
200
208
string CaptureOutput ( )
201
209
{
@@ -208,9 +216,9 @@ string CaptureOutput()
208
216
ConsoleOutWriter = NoopConsoleWriter . Instance
209
217
} ;
210
218
var result = Proc . Start ( arguments ) ;
211
- if ( result . ExitCode != 0 )
212
- collector . EmitError ( "" , $ "Exit code: { result . ExitCode } while executing { binary } { string . Join ( " " , args ) } in { workingDirectory } ") ;
213
- var line = result . ConsoleOut . FirstOrDefault ( ) ? . Line ?? throw new Exception ( $ "No output captured for { binary } : { workingDirectory } ") ;
219
+ var line = result . ExitCode != 0
220
+ ? throw new Exception ( $ "Exit code is not 0. Received { result . ExitCode } from { binary } : { workingDirectory } ")
221
+ : result . ConsoleOut . FirstOrDefault ( ) ? . Line ?? throw new Exception ( $ "No output captured for { binary } : { workingDirectory } ") ;
214
222
return line ;
215
223
}
216
224
}
0 commit comments