From eb6cd02503faf7a7f273603866170349a949ba8c Mon Sep 17 00:00:00 2001 From: Matthew John Cheetham Date: Wed, 17 Apr 2024 09:44:35 -0700 Subject: [PATCH] diagnose: avoid poluting stderr stream in Git diagnostic Avoid poluting the standard error stream with a 'fatal' Git error message during the Git diagnostic run as part of the `diagnose` command. When checking if we are inside of a Git repo we should be using an explicit check for `IGit::IsInsideRepository` rather than trying to get the current repo path and checking for null. --- src/shared/Core/Diagnostics/GitDiagnostic.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/shared/Core/Diagnostics/GitDiagnostic.cs b/src/shared/Core/Diagnostics/GitDiagnostic.cs index e09f091dd..74c4c76b3 100644 --- a/src/shared/Core/Diagnostics/GitDiagnostic.cs +++ b/src/shared/Core/Diagnostics/GitDiagnostic.cs @@ -19,9 +19,16 @@ protected override Task RunInternalAsync(StringBuilder log, IList log.AppendLine($"Git version is '{gitVersion.OriginalString}'"); log.Append("Locating current repository..."); - string thisRepo =CommandContext.Git.GetCurrentRepository(); + if (!CommandContext.Git.IsInsideRepository()) + { + log.AppendLine("Not inside a Git repository."); + } + else + { + string thisRepo = CommandContext.Git.GetCurrentRepository(); + log.AppendLine($"Git repository at '{thisRepo}'"); + } log.AppendLine(" OK"); - log.AppendLine(thisRepo is null ? "Not inside a Git repository." : $"Git repository at '{thisRepo}'"); log.Append("Listing all Git configuration..."); ChildProcess configProc = CommandContext.Git.CreateProcess("config --list --show-origin");