diff --git a/ChangeLog.md b/ChangeLog.md index 6716799c77..63e74c6e7b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix analyzer [RCS1196](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1196) ([PR](https://github.com/dotnet/roslynator/pull/1235)) - Fix analyzer [RCS1257](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1257) ([PR](https://github.com/dotnet/roslynator/pull/1264)) - Fix analyzer [RCS1259](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1259) ([PR](https://github.com/dotnet/roslynator/pull/1268)) +- [CLI] Fix reading of non-existent redirected input on git bash ([PR](https://github.com/dotnet/roslynator/pull/1265)) ## [4.6.2] - 2023-11-10 diff --git a/src/CommandLine/ConsoleHelpers.cs b/src/CommandLine/ConsoleHelpers.cs index 931d7c1f00..c10c895b01 100644 --- a/src/CommandLine/ConsoleHelpers.cs +++ b/src/CommandLine/ConsoleHelpers.cs @@ -1,25 +1,32 @@ // Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; +using System.Collections.Immutable; using System.IO; +using System.Threading.Tasks; namespace Roslynator.CommandLine; internal static class ConsoleHelpers { - public static IEnumerable ReadRedirectedInputAsLines() + public static async Task> ReadRedirectedInputAsLines() { if (Console.IsInputRedirected) { + ImmutableArray.Builder lines = ImmutableArray.CreateBuilder(); + using (Stream stream = Console.OpenStandardInput()) using (var streamReader = new StreamReader(stream, Console.InputEncoding)) { string line; - while ((line = streamReader.ReadLine()) is not null) - yield return line; + while ((line = await streamReader.ReadLineAsync()) is not null) + lines.Add(line); } + + return lines.ToImmutableArray(); } + + return ImmutableArray.Empty; } } diff --git a/src/CommandLine/Program.cs b/src/CommandLine/Program.cs index bc38fe3c4a..dc8eca9582 100644 --- a/src/CommandLine/Program.cs +++ b/src/CommandLine/Program.cs @@ -790,14 +790,26 @@ private static bool TryParsePaths(IEnumerable values, out ImmutableArray if (Console.IsInputRedirected) { - if (!TryEnsureFullPath( - ConsoleHelpers.ReadRedirectedInputAsLines().Where(f => !string.IsNullOrEmpty(f)), - out ImmutableArray paths2)) + Task> task = ConsoleHelpers.ReadRedirectedInputAsLines(); + + WriteLine("Reading redirected input...", Verbosity.Diagnostic); + + // https://github.com/dotnet/runtime/issues/95079 + if (task.Wait(TimeSpan.FromMilliseconds(500))) { - return false; - } + IEnumerable paths1 = task.Result.Where(f => !string.IsNullOrEmpty(f)); + + WriteLine("Successfully read redirected input:" + Environment.NewLine + " " + string.Join(Environment.NewLine + " ", paths1), Verbosity.Diagnostic); - paths = paths.AddRange(ImmutableArray.CreateRange(paths2, f => new PathInfo(f, PathOrigin.PipedInput))); + if (!TryEnsureFullPath(paths1, out ImmutableArray paths2)) + return false; + + paths = paths.AddRange(ImmutableArray.CreateRange(paths2, f => new PathInfo(f, PathOrigin.PipedInput))); + } + else + { + WriteLine("Unable to read redirected input", Verbosity.Diagnostic); + } } if (!paths.IsEmpty)