示例#1
0
        public override IRepository Clone(string remotePathOrUrl, string workingDirectory, SecureCredentials credentials = null)
        {
            try
            {
                var name = GetProjectNameFromDirectory(remotePathOrUrl);

                if (credentials == null)
                {
                    LibGit2Sharp.Repository.Clone(remotePathOrUrl, workingDirectory);
                }
                else
                {
                    var credentialsHandler = new CredentialsHandler((url, usernameFromUrl, types) => new SecureUsernamePasswordCredentials
                    {
                        Username = credentials.Username,
                        Password = credentials.Password
                    });

                    var options = new CloneOptions {
                        CredentialsProvider = credentialsHandler
                    };
                    LibGit2Sharp.Repository.Clone(remotePathOrUrl, workingDirectory, options);
                }

                return(new Repository(name, workingDirectory, remotePathOrUrl));
            }
            catch (LibGit2SharpException ex)
            {
                throw new SourceControlException(SourceControlText.GitRepoNotCloned, ex);
            }
        }
 public abstract IRepository Clone(string remotePathOrUrl, string workingDirectory, SecureCredentials credentials = null);