public async void TestSquashWriter()
        {
            string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));

            Directory.CreateDirectory(tempDirectory);

            GitProcessManager local = new GitProcessManager(tempDirectory, null);

            var result = await local.RunGit("init", CancellationToken.None);

            result.Success.Should().Be(true, "Must be able to init");

            int numberCommits = 10;

            await this.GenerateCommits(numberCommits, tempDirectory, local, "master");

            var branchManager = new BranchManager(tempDirectory, null);

            var commits = await branchManager.GetCommitsForBranch(new GitBranch("master", false), 0, 0, GitLogOptions.None, CancellationToken.None);

            IGitSquashWrapper  squashWrapper = new GitSquashWrapper(tempDirectory, null);
            GitCommandResponse squashOutput  = await squashWrapper.Squash(CancellationToken.None, "Bye Cruel World", commits.Last());

            commits = await branchManager.GetCommitsForBranch(new GitBranch("master", false), 0, 0, GitLogOptions.None, CancellationToken.None);

            commits = commits.ToList();

            commits.Count.Should().Be(2);
            commits[0].MessageLong.Should().BeEquivalentTo("Bye Cruel World");
        }
예제 #2
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);
        }
        public async void TestGitHistoryBranchOnly()
        {
            string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));

            Directory.CreateDirectory(tempDirectory);

            GitProcessManager local = new GitProcessManager(tempDirectory, null);

            var result = await local.RunGit("init", CancellationToken.None);

            result.Success.Should().Be(true, "Must be able to init");

            int numberCommits = 10;

            await this.GenerateCommits(numberCommits, tempDirectory, local, "master");

            BranchManager branchManager = new BranchManager(tempDirectory, null);

            var commits = await branchManager.GetCommitsForBranch(new GitBranch("master", false), 0, 0, GitLogOptions.BranchOnlyAndParent, CancellationToken.None);

            commits.Count.Should().Be(numberCommits, $"We have done {numberCommits} commits");

            using (Repository repository = new Repository(tempDirectory))
            {
                var branch = repository.Branches.FirstOrDefault(x => x.FriendlyName == "master");
                branch.Should().NotBeNull();

                CheckCommits(branch.Commits.ToList(), commits);
            }

            commits.Should().BeInDescendingOrder(x => x.DateTime);

            await GenerateCommits(numberCommits, tempDirectory, local, "test1");

            commits = await branchManager.GetCommitsForBranch(new GitBranch("test1", false), 0, 0, GitLogOptions.BranchOnlyAndParent, CancellationToken.None);

            commits.Count.Should().Be(numberCommits + 1, $"We have done {numberCommits + 1} commits");

            using (Repository repository = new Repository(tempDirectory))
            {
                var branch = repository.Branches.FirstOrDefault(x => x.FriendlyName == "test1");
                branch.Should().NotBeNull();

                CheckCommits(branch.Commits.Take(11).ToList(), commits);
            }
        }
예제 #4
0
        /// <summary>Initializes a new instance of the <see cref="RepositoryDetails"/> class.</summary>
        /// <param name="repositoryPath">The path to the repository.</param>
        public RepositoryDetails(string repositoryPath)
        {
            if (Directory.Exists(repositoryPath) == false)
            {
                throw new ArgumentException(nameof(repositoryPath));
            }

            RepositoryPath = repositoryPath;

            var gitProcessManager = new GitProcessManager(repositoryPath);

            BranchManager     = new BranchManager(gitProcessManager);
            RebaseManager     = new RebaseManager(gitProcessManager, BranchManager);
            RefLogManager     = new RefLogManager(gitProcessManager);
            GitObjectManager  = new GitObjectManager(gitProcessManager);
            TagManager        = new TagManager(gitProcessManager);
            FriendlyName      = Path.GetFileName(repositoryPath);
            RepositoryManager = gitProcessManager;
        }
예제 #5
0
        /// <summary>
        /// Generates a GIT repository with the specified process manager.
        /// </summary>
        /// <returns>The location of the GIT repository.</returns>
        private static async Task <(string tempDirectory, IGitProcessManager processManager)> GenerateGitRepository()
        {
            WriteLine("Executing " + nameof(GenerateGitRepository));
            var tempDirectory = Path.Combine(
                Path.GetTempPath(),
                Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));

            Directory.CreateDirectory(tempDirectory);

            var local = new GitProcessManager(tempDirectory);

            await local.RunGit(new[] { "init" }).ObserveOn(ImmediateScheduler.Instance).LastOrDefaultAsync();

            await local.RunGit(new[] { "config --local commit.gpgsign false" }).ObserveOn(ImmediateScheduler.Instance).LastOrDefaultAsync();

            await local.RunGit(new[] { "config --local user.email [email protected]" }).ObserveOn(ImmediateScheduler.Instance).LastOrDefaultAsync();

            await local.RunGit(new[] { "config --local user.name Name" }).ObserveOn(ImmediateScheduler.Instance).LastOrDefaultAsync();

            return(tempDirectory, local);
        }
        public async void TestFullHistory()
        {
            string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));

            Directory.CreateDirectory(tempDirectory);

            GitProcessManager local = new GitProcessManager(tempDirectory, null);

            var result = await local.RunGit("init", CancellationToken.None);

            result.Success.Should().Be(true, "Must be able to init");

            int numberCommits = 10;

            await this.GenerateCommits(numberCommits, tempDirectory, local, "master");

            BranchManager branchManager = new BranchManager(tempDirectory, null);

            var commits = await branchManager.GetCommitsForBranch(new GitBranch("master", false), 0, 0, GitLogOptions.BranchOnlyAndParent, CancellationToken.None);

            commits.Count.Should().Be(numberCommits, $"We have done {numberCommits} commits");

            commits.Should().BeInDescendingOrder(x => x.DateTime);

            result = await local.RunGit("branch test1", CancellationToken.None);

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

            result = await local.RunGit("checkout test1", CancellationToken.None);

            result.Success.Should().Be(true, "Must be able checkout branch");

            await this.GenerateCommits(numberCommits, tempDirectory, local, "master");

            commits = await branchManager.GetCommitsForBranch(new GitBranch("test1", false), 0, 0, GitLogOptions.None, CancellationToken.None);

            commits.Count.Should().Be(numberCommits * 2, $"We have done {numberCommits + 1} commits");
        }