Ejemplo n.º 1
0
        /// <summary>
        /// Search for a local git repository that contains a Git Commit.
        /// </summary>
        /// <param name="path">The path to search for local git repo.</param>
        /// <param name="sha">The git commit SHA to be searched for.</param>
        /// <returns>
        /// A <seealso cref="GitCommit"/> object that represents the git SHA commit at a local repository.
        /// null if the search is not successful.
        /// </returns>
        public static async Task <GitCommit> FindCommitAsync(string path, string sha)
        {
            string dir = path.ThrowIfNullOrEmpty(nameof(path));

            sha.ThrowIfNullOrEmpty(nameof(sha));
            var gitCommand = await GitRepository.GetGitCommandWrapperForPathAsync(dir);

            if (gitCommand == null)
            {
                return(null);
            }
            return((await gitCommand.ContainsCommitAsync(sha)) ? new GitCommit(gitCommand, sha) : null);
        }
        /// <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));
        }