private static async Task VerifyPullRequestVersionIsCalculatedProperly(string pullRequestRef, Dictionary <string, string> env)
        {
            using var fixture = new EmptyRepositoryFixture();
            var remoteRepositoryPath = PathHelper.GetTempPath();

            RepositoryFixtureBase.Init(remoteRepositoryPath);
            using (var remoteRepository = new Repository(remoteRepositoryPath))
            {
                remoteRepository.Config.Set("user.name", "Test");
                remoteRepository.Config.Set("user.email", "*****@*****.**");
                fixture.Repository.Network.Remotes.Add("origin", remoteRepositoryPath);
                Console.WriteLine("Created git repository at {0}", remoteRepositoryPath);
                remoteRepository.MakeATaggedCommit("1.0.3");

                var branch = remoteRepository.CreateBranch("FeatureBranch");
                Commands.Checkout(remoteRepository, branch);
                remoteRepository.MakeCommits(2);
                Commands.Checkout(remoteRepository, remoteRepository.Head.Tip.Sha);
                //Emulate merge commit
                var mergeCommitSha = remoteRepository.MakeACommit().Sha;
                Commands.Checkout(remoteRepository, TestBase.MainBranch); // HEAD cannot be pointing at the merge commit
                remoteRepository.Refs.Add(pullRequestRef, new ObjectId(mergeCommitSha));

                // Checkout PR commit
                Commands.Fetch((Repository)fixture.Repository, "origin", new string[0], new FetchOptions(), null);
                Commands.Checkout(fixture.Repository, mergeCommitSha);
            }

            var programFixture = new ProgramFixture(fixture.RepositoryPath);

            programFixture.WithEnv(env.ToArray());

            var result = await programFixture.Run();

            result.ExitCode.ShouldBe(0);
            result.OutputVariables.FullSemVer.ShouldBe("1.0.4-PullRequest0005.3");

            // Cleanup repository files
            DirectoryHelper.DeleteDirectory(remoteRepositoryPath);
        }
Esempio n. 2
0
        private static async Task VerifyTagCheckoutVersionIsCalculatedProperly(Dictionary <string, string> env)
        {
            using var fixture = new EmptyRepositoryFixture();
            var remoteRepositoryPath = PathHelper.GetTempPath();

            RepositoryFixtureBase.Init(remoteRepositoryPath);
            using (var remoteRepository = new Repository(remoteRepositoryPath))
            {
                remoteRepository.Config.Set("user.name", "Test");
                remoteRepository.Config.Set("user.email", "*****@*****.**");
                fixture.Repository.Network.Remotes.Add("origin", remoteRepositoryPath);
                Console.WriteLine("Created git repository at {0}", remoteRepositoryPath);
                remoteRepository.MakeATaggedCommit("0.1.0");
                Commands.Checkout(remoteRepository, remoteRepository.CreateBranch("develop"));
                remoteRepository.MakeACommit();
                Commands.Checkout(remoteRepository, remoteRepository.CreateBranch("release/0.2.0"));
                remoteRepository.MakeACommit();
                Commands.Checkout(remoteRepository, TestBase.MainBranch);
                remoteRepository.MergeNoFF("release/0.2.0", Generate.SignatureNow());
                remoteRepository.MakeATaggedCommit("0.2.0");

                Commands.Fetch((Repository)fixture.Repository, "origin", new string[0], new FetchOptions(), null);
                Commands.Checkout(fixture.Repository, "0.2.0");
            }

            var programFixture = new ProgramFixture(fixture.RepositoryPath);

            programFixture.WithEnv(env.ToArray());

            var result = await programFixture.Run();

            result.ExitCode.ShouldBe(0);
            result.OutputVariables.FullSemVer.ShouldBe("0.2.0");

            // Cleanup repository files
            DirectoryHelper.DeleteDirectory(remoteRepositoryPath);
        }