diff --git a/Scalar.Common/Git/GitProcess.cs b/Scalar.Common/Git/GitProcess.cs index b1b7c17d7d..3802e0fb67 100644 --- a/Scalar.Common/Git/GitProcess.cs +++ b/Scalar.Common/Git/GitProcess.cs @@ -442,11 +442,21 @@ public Result BackgroundFetch(string remote) userInteractive: false); } - public string[] GetRemotes() + public bool TryGetRemotes(out string[] remotes, out string error) { - return this.InvokeGitInWorkingDirectoryRoot("remote", fetchMissingObjects: false) - .Output - .Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); + GitProcess.Result result = this.InvokeGitInWorkingDirectoryRoot("remote", fetchMissingObjects: false); + + if (result.ExitCodeIsFailure) + { + remotes = null; + error = result.Errors; + return false; + } + + remotes = result.Output + .Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); + error = null; + return true; } public Result SparseCheckoutSet(List foldersToSet) @@ -754,6 +764,9 @@ protected virtual Result InvokeGitImpl( this.executingProcess.Start(); + this.executingProcess.BeginOutputReadLine(); + this.executingProcess.BeginErrorReadLine(); + try { if (this.LowerPriority) @@ -771,9 +784,10 @@ protected virtual Result InvokeGitImpl( { // This is thrown if the process completes before we can set a property. } - - this.executingProcess.BeginOutputReadLine(); - this.executingProcess.BeginErrorReadLine(); + catch (Win32Exception) + { + // This is thrown if the process completes before we can set a property. + } if (!this.executingProcess.WaitForExit(timeoutMs)) { @@ -865,7 +879,8 @@ private Result InvokeGitInWorkingDirectoryRoot( fetchMissingObjects: fetchMissingObjects, writeStdIn: writeStdIn, parseStdOutLine: parseStdOutLine, - timeoutMs: -1); + timeoutMs: -1, + userInteractive: userInteractive); } /// diff --git a/Scalar.Common/Maintenance/FetchStep.cs b/Scalar.Common/Maintenance/FetchStep.cs index ba02d58275..5331442a20 100644 --- a/Scalar.Common/Maintenance/FetchStep.cs +++ b/Scalar.Common/Maintenance/FetchStep.cs @@ -158,14 +158,26 @@ private bool TryFetchUsingGitProtocol(GitProcess gitProcess, out string error) using (ITracer activity = this.Context.Tracer.StartActivity(nameof(GitProcess.BackgroundFetch), EventLevel.LogAlways)) { - string[] remotes = gitProcess.GetRemotes(); + if (!gitProcess.TryGetRemotes(out string[] remotes, out string errors)) + { + error = $"Failed to load remotes with error: {errors}"; + activity.RelatedError(error); + return false; + } + bool response = true; error = ""; foreach (string remote in remotes) { + activity.RelatedInfo($"Running fetch for remote '{remote}'"); GitProcess.Result result = gitProcess.BackgroundFetch(remote); + if (!string.IsNullOrWhiteSpace(result.Output)) + { + activity.RelatedError($"Background fetch from '{remote}' completed with stdout: {result.Output}"); + } + if (!string.IsNullOrWhiteSpace(result.Errors)) { error += result.Errors; @@ -176,6 +188,7 @@ private bool TryFetchUsingGitProtocol(GitProcess gitProcess, out string error) { response = false; // Keep going through other remotes, but the overall result will still be false. + activity.RelatedError($"Background fetch from '{remote}' failed"); } }