Skip to content

Commit

Permalink
Fix stdin encoding for Git... again (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfederm authored Oct 23, 2024
1 parent f918a19 commit 2eb4fd6
Show file tree
Hide file tree
Showing 2 changed files with 729 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/Common/SourceControl/Git.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Build.Experimental.ProjectCache;
#if NETFRAMEWORK
using Process = Microsoft.MSBuildCache.SourceControl.GitProcess;
#endif

namespace Microsoft.MSBuildCache.SourceControl;

Expand Down Expand Up @@ -41,9 +44,7 @@ public static async Task<T> RunAsync<T>(
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.StandardOutputEncoding = Encoding.UTF8;
#if !NETFRAMEWORK
process.StartInfo.StandardInputEncoding = InputEncoding;
#endif

Stopwatch sw = Stopwatch.StartNew();

Expand All @@ -66,18 +67,10 @@ static void KillProcess(Process process)

using (cancellationToken.Register(() => KillProcess(process)))
{
#if NETFRAMEWORK
// In .NET Framework the StandardInputEncoding cannot be set and is always Console.InputEncoding.
// To work around, wrap the underlying stream in a writer with the correct encoding.
using (StreamWriter stdin = new StreamWriter(process.StandardInput.BaseStream, InputEncoding, 4096))
#else
using (StreamWriter stdin = process.StandardInput)
#endif
using (StreamReader stdout = process.StandardOutput)
using (StreamReader stderr = process.StandardError)
{
stdin.AutoFlush = true;

Task<T> resultTask = Task.Run(async () =>
{
try
Expand Down
Loading

0 comments on commit 2eb4fd6

Please sign in to comment.