/// <summary>
        /// Clone a Google Cloud Source Repository locally.
        /// </summary>
        /// <param name="url">The repository remote URL.</param>
        /// <param name="localPath">Local path to save the repository</param>
        /// <returns>
        /// A <seealso cref="GitRepository"/> object.
        /// </returns>
        /// <exception cref="GitCommandException">Throw when git command fails</exception>
        public static async Task <GitRepository> CloneAsync(string url, string localPath)
        {
            if (Directory.Exists(localPath))
            {
                throw new ArgumentException($"{localPath} arleady exists.");
            }

            Directory.CreateDirectory(localPath);

            // git clone https://host/myrepo/ "c:\git\myrepo" --config credential.helper=manager
            string command = $@"clone {url} ""{localPath}"" --config credential.helper=manager";
            var    output  = await GitRepository.RunGitCommandAsync(command, localPath);

            Debug.WriteLine(output.FirstOrDefault() ?? "");
            return(await GitRepository.GetGitCommandWrapperForPathAsync(localPath));
        }
Example #2
0
 /// <summary>
 /// Verifies git-credential-manager is installed properly.
 /// </summary>
 /// <returns>
 /// true: Verified, git-credential-manager command executed successfully.
 /// false: The command failed for some reason.
 /// </returns>
 public static async Task <bool> IsGitCredentialManagerInstalledAsync() =>
 (await GitRepository.RunGitCommandAsync(
      "credential-manager version",
      Directory.GetCurrentDirectory(),
      throwOnError: false)) != null;
 /// <summary>
 /// Set global git config useHttpPath for CSR host.
 /// Refer to https://git-scm.com/docs/gitcredentials
 /// </summary>
 public static Task SetUseHttpPathAsync() =>
 GitRepository.RunGitCommandAsync(
     $"config --global credential.{CsrUrlAuthority}.useHttpPath true",
     Directory.GetCurrentDirectory());