@@ -88,6 +88,7 @@ private Process StartGitProcess(params string[] args)
8888#if DEBUG
8989 Console . WriteLine ( "Running git command: " + string . Join ( " " , args ) ) ;
9090#endif
91+ #if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
9192 // run `git ...args` in CheckDirectory working directory with 3 second timeout
9293 var procInfo = new ProcessStartInfo ( "git" )
9394 {
@@ -102,9 +103,12 @@ private Process StartGitProcess(params string[] args)
102103 } ;
103104 foreach ( var a in args )
104105 procInfo . ArgumentList . Add ( a ) ;
105-
106-
107106 return Process . Start ( procInfo ) ;
107+ #else
108+ // Old frameworks don't support ArgumentList, so I rather pull in a dependency than write my own escaping
109+ var command = Medallion . Shell . Shell . Default . Run ( "git" , args , options => options . WorkingDirectory ( CheckDirectory ) . Timeout ( TimeSpan . FromSeconds ( 15 ) ) ) ;
110+ return command . Process ;
111+ #endif
108112 }
109113
110114 private void HandleProcessExit ( Process proc , Task outputReaderTask , params string [ ] args )
@@ -145,21 +149,13 @@ private string[] RunGitCommand(params string[] args)
145149
146150 private byte [ ] RunGitBinaryCommand ( params string [ ] args )
147151 {
148- const int BUFFER_SIZE = 1024 ;
149-
150152 var proc = StartGitProcess ( args ) ;
151153
152- List < byte > ret = new ( ) ;
154+ MemoryStream ret = new ( ) ;
153155
154156 var outputReaderTask = Task . Run ( ( ) =>
155157 {
156- byte [ ] buffer = new byte [ BUFFER_SIZE ] ;
157-
158- int charsRead = 0 ;
159- while ( ( charsRead = proc . StandardOutput . BaseStream . Read ( buffer , 0 , BUFFER_SIZE ) ) != 0 )
160- {
161- ret . AddRange ( buffer . AsSpan ( 0 , charsRead ) . ToArray ( ) ) ;
162- }
158+ proc . StandardOutput . BaseStream . CopyTo ( ret ) ;
163159 } ) ;
164160
165161 HandleProcessExit ( proc , outputReaderTask , args ) ;
@@ -323,7 +319,7 @@ internal void CheckOutputBinaryCore(byte[] outputBytes, string checkName, string
323319 {
324320 using ( var t = File . Create ( filename ) )
325321 {
326- t . Write ( outputBytes ) ;
322+ t . Write ( outputBytes , 0 , outputBytes . Length ) ;
327323 }
328324 }
329325 return ;
@@ -333,7 +329,7 @@ internal void CheckOutputBinaryCore(byte[] outputBytes, string checkName, string
333329 {
334330 using ( var t = File . Create ( filename ) )
335331 {
336- t . Write ( outputBytes ) ;
332+ t . Write ( outputBytes , 0 , outputBytes . Length ) ;
337333 }
338334
339335 if ( IsModified ( filename ) )
0 commit comments