private static bool TryGetRemoteUri()

in src/Microsoft.VisualStudio.SlnGen/GitRepositoryInfo.cs [56:95]


        private static bool TryGetRemoteUri(out Uri remoteUri, string name = "origin")
        {
            remoteUri = null;

            Process process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    Arguments = $"remote get-url {name}",
                    FileName = "git",
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    WorkingDirectory = Environment.CurrentDirectory,
                },
            };

            try
            {
                if (!process.Start() || !process.WaitForExit((int)TimeSpan.FromSeconds(5).TotalMilliseconds))
                {
                    return false;
                }

                string output = process.StandardOutput.ReadToEnd().Trim();

                if (!output.IsNullOrWhiteSpace() && Uri.TryCreate(output, UriKind.Absolute, out remoteUri))
                {
                    remoteUri = StripUsernameAndPassword(remoteUri);

                    return true;
                }
            }
            catch (Exception)
            {
                // Ignored
            }

            return false;
        }