Ejemplo n.º 1
0
        /// <summary>
        /// Generates a series of commits.
        /// </summary>
        /// <param name="numberCommits">The number of commits to generate.</param>
        /// <param name="directory">The directory of the repository.</param>
        /// <param name="local">The repository manager for the repository.</param>
        /// <param name="branchName">The branch name to add the commits into.</param>
        /// <returns>A task to monitor the progress.</returns>
        private static async Task <IList <string> > GenerateCommits(
            int numberCommits,
            string directory,
            IGitProcessManager local,
            string branchName)
        {
            WriteLine("Executing " + nameof(GenerateCommits));
            if (branchName != "master")
            {
                await local.RunGit(new[] { $"branch {branchName}" }).ObserveOn(ImmediateScheduler.Instance).LastOrDefaultAsync();
            }

            try
            {
                await local.RunGit(new[] { $"checkout {branchName}" }).ObserveOn(ImmediateScheduler.Instance).LastOrDefaultAsync();
            }
            catch (GitProcessException)
            {
                // Ignored
            }

            var commitNames = Enumerable.Range(0, numberCommits).Select(i => branchName + " Hello World " + i).ToList();

            foreach (var commitName in commitNames)
            {
                File.WriteAllText(Path.Combine(directory, Path.GetRandomFileName()), commitName);
                await local.RunGit(new[] { "add -A" }).ObserveOn(ImmediateScheduler.Instance).LastOrDefaultAsync();

                await local.RunGit(new[] { $"commit -m \"{commitName}\"" }).ObserveOn(ImmediateScheduler.Instance).LastOrDefaultAsync();
            }

            return(commitNames);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates a series of commits.
        /// </summary>
        /// <param name="numberCommits">The number of commits to generate.</param>
        /// <param name="directory">The directory of the repository.</param>
        /// <param name="local">The repository manager for the repository.</param>
        /// <param name="branchName">The branch name to add the commits into.</param>
        /// <param name="commitMessages">A optional output list which is populated with the commit messages.</param>
        private static void GenerateCommits(
            int numberCommits,
            string directory,
            IGitProcessManager local,
            string branchName,
            IList <string> commitMessages = null)
        {
            if (branchName != "master")
            {
                local.RunGit(new[] { $"branch {branchName}" }).FirstOrDefaultAsync().Wait();
            }

            try
            {
                local.RunGit(new[] { $"checkout {branchName}" }).Wait();
            }
            catch (GitProcessException)
            {
                // Ignored
            }

            for (var i = 0; i < numberCommits; ++i)
            {
                File.WriteAllText(Path.Combine(directory, Path.GetRandomFileName()), @"Hello World" + i);
                local.RunGit(new[] { "add -A" }).FirstOrDefaultAsync().Wait();
                commitMessages?.Add($"Commit {branchName}-{i}");
                local.RunGit(new[] { $"commit -m \"Commit {branchName}-{i}\"" }).FirstOrDefaultAsync().Wait();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a repository.
        /// </summary>
        /// <param name="directoryPath">The path to the new repository.</param>
        /// <param name="scheduler">The scheduler to use when creating the repository.</param>
        /// <returns>An observable monitoring the action.</returns>
        public IObservable <Unit> CreateRepository(string directoryPath, IScheduler scheduler = null)
        {
            return(Observable.Create <Unit>(
                       observer =>
            {
                if (Directory.Exists(directoryPath) == false)
                {
                    throw new GitProcessException("Cannot find directory");
                }

                if (FileHelper.IsDirectoryEmpty(directoryPath) == false)
                {
                    throw new GitProcessException("The directory is not empty.");
                }

                IGitProcessManager gitProcess = this.processManagerFunc(directoryPath);
                IDisposable disposable = gitProcess.RunGit(new[] { "init" }, showInOutput: true, scheduler: scheduler).Subscribe(
                    _ => { },
                    observer.OnError,
                    () =>
                {
                    observer.OnNext(Unit.Default);
                    observer.OnCompleted();
                });

                return disposable;
            }));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GitObjectManager" /> class.
        /// </summary>
        /// <param name="gitProcessManager">The git process to use.</param>
        public GitObjectManager(IGitProcessManager gitProcessManager)
        {
            if (gitProcessManager == null)
            {
                throw new ArgumentNullException(nameof(gitProcessManager));
            }

            this.gitProcessManager = gitProcessManager;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Generates a GIT repository with the specified process manager.
        /// </summary>
        /// <param name="local">The process manager to use.</param>
        /// <returns>The location of the GIT repository.</returns>
        private static string GenerateGitRepository(out IGitProcessManager local)
        {
            string tempDirectory = Path.Combine(
                Path.GetTempPath(),
                Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));

            Directory.CreateDirectory(tempDirectory);

            local = new GitProcessManager(tempDirectory);

            local.RunGit(new[] { "init" }).Wait();
            return(tempDirectory);
        }
        private async Task GenerateCommits(int numberCommits, string directory, IGitProcessManager local, string branchName)
        {
            GitCommandResponse result;

            if (branchName != "master")
            {
                result = await local.RunGit($"branch {branchName}", CancellationToken.None);

                result.Success.Should().Be(true, $"Must be able create branch {branchName}");
            }

            await local.RunGit($"checkout {branchName}", CancellationToken.None);

            for (int i = 0; i < numberCommits; ++i)
            {
                File.WriteAllText(Path.Combine(directory, Path.GetRandomFileName()), @"Hello World" + i);
                result = await local.RunGit("add -A", CancellationToken.None);

                result.Success.Should().Be(true, "Must be able to add");
                result = await local.RunGit($"commit -m \"Commit {branchName}-{i}\"", CancellationToken.None);

                result.Success.Should().Be(true, "Must be able to commit");
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GitSquashWrapper" /> class.
 /// </summary>
 /// <param name="repoDirectory">The directory where the repository is located</param>
 /// <param name="logger">The output logger to output GIT transactions.</param>
 /// <param name="gitProcess">The GIT process to use.</param>
 public GitSquashWrapper(string repoDirectory, IOutputLogger logger, IGitProcessManager gitProcess = null)
 {
     this.repoDirectory = repoDirectory;
     this.gitProcess    = gitProcess ?? new GitProcessManager(repoDirectory, logger);
     this.branchManager = new BranchManager(this.repoDirectory, null);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BranchManager" /> class.
 /// </summary>
 /// <param name="gitProcessManager">The git process to use.</param>
 public BranchManager(IGitProcessManager gitProcessManager)
 {
     this.gitProcessManager = gitProcessManager;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TagManager"/> class.
 /// </summary>
 /// <param name="processManager">The git process manager which will invoke git commands.</param>
 public TagManager(IGitProcessManager processManager)
 {
     _processManager = processManager;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GitObjectManager" /> class.
 /// </summary>
 /// <param name="gitProcessManager">The git process to use.</param>
 public GitObjectManager(IGitProcessManager gitProcessManager)
 {
     _gitProcessManager = gitProcessManager ?? throw new ArgumentNullException(nameof(gitProcessManager));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RebaseManager" /> class.
 /// </summary>
 /// <param name="processManager">The process manager which invokes GIT commands.</param>
 /// <param name="branchManager">The branch manager which will get's GIT branch information.</param>
 public RebaseManager(IGitProcessManager processManager, IBranchManager branchManager)
 {
     this.gitProcess    = processManager;
     this.branchManager = branchManager;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RefLogManager" /> class.
 /// </summary>
 /// <param name="gitProcessManager">The git process to use.</param>
 public RefLogManager(IGitProcessManager gitProcessManager)
 {
     this.gitProcessManager = gitProcessManager;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TagManager"/> class.
 /// </summary>
 /// <param name="processManager">The git process manager which will invoke git commands.</param>
 public TagManager(IGitProcessManager processManager)
 {
     this.processManager = processManager;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RebaseManager" /> class.
 /// </summary>
 /// <param name="processManager">The process manager which invokes GIT commands.</param>
 /// <param name="branchManager">The branch manager which will get's GIT branch information.</param>
 public RebaseManager(IGitProcessManager processManager, IBranchManager branchManager)
 {
     _gitProcess    = processManager;
     _branchManager = branchManager;
 }