コード例 #1
0
        public static DirectoryPath GitClone(
            this ICakeContext context,
            string sourceUrl,
            DirectoryPath workDirectoryPath,
            string username,
            string password,
            GitCloneSettings cloneSettings
            )
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrWhiteSpace(sourceUrl))
            {
                throw new ArgumentNullException(nameof(sourceUrl));
            }

            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException(nameof(username));
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException(nameof(password));
            }

            if (workDirectoryPath == null)
            {
                throw new ArgumentNullException(nameof(workDirectoryPath));
            }

            cloneSettings = cloneSettings ?? new GitCloneSettings();

            var workFullDirectoryPath = workDirectoryPath.MakeAbsolute(context.Environment);

            if (!context.FileSystem.Exist(workFullDirectoryPath))
            {
                throw new DirectoryNotFoundException($"Failed to find workDirectoryPath: {workFullDirectoryPath}");
            }

            var options = cloneSettings.ToCloneOptions();

            options.CredentialsProvider =
                (url, user, cred) => new UsernamePasswordCredentials {
                Username = username, Password = password
            };

            return(Repository.Clone(sourceUrl, workFullDirectoryPath.FullPath, options));
        }
コード例 #2
0
        public static DirectoryPath GitClone(
            this ICakeContext context,
            string sourceUrl,
            DirectoryPath workDirectoryPath,
            GitCloneSettings cloneSettings
            )
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrWhiteSpace(sourceUrl))
            {
                throw new ArgumentNullException(nameof(sourceUrl));
            }

            if (workDirectoryPath == null)
            {
                throw new ArgumentNullException(nameof(workDirectoryPath));
            }

            cloneSettings = cloneSettings ?? new GitCloneSettings();

            var workFullDirectoryPath   = workDirectoryPath.MakeAbsolute(context.Environment);
            var parentFullDirectoryPath = workFullDirectoryPath.Combine("../").Collapse();

            if (!context.FileSystem.Exist(parentFullDirectoryPath))
            {
                throw new DirectoryNotFoundException($"Failed to find {nameof(parentFullDirectoryPath)}: {parentFullDirectoryPath}");
            }

            if (context.FileSystem.Exist(workFullDirectoryPath))
            {
                throw new IOException($"{nameof(workFullDirectoryPath)} already exists: {workFullDirectoryPath}");
            }

            context.FileSystem.GetDirectory(workFullDirectoryPath).Create();

            return(Repository.Clone(sourceUrl, workFullDirectoryPath.FullPath, cloneSettings.ToCloneOptions()));
        }