public void GetResult_Feature_Branch_Changes_Version_Resets_On_Merge()
        {
            // Arrange
            using var fixture = new SimpleVersionRepositoryFixture(_serializer);
            var config = fixture.GetConfig();

            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            fixture.BranchTo("feature/other");
            fixture.MakeACommit();

            config.Version = "0.1.1";
            fixture.SetConfig(config);

            fixture.MakeACommit();
            fixture.MakeACommit();

            fixture.Checkout("master");
            fixture.MergeNoFF("feature/other");

            var sut = new GitVersionRepository(fixture.RepositoryPath, _environment, _serializer, Enumerable.Empty <IVersionProcessor>());

            // Act
            var result = sut.GetResult();

            result.Height.Should().Be(1);
        }
        public void GetResult_BranchOverride_AppliesOverride()
        {
            // Arrange
            var expectedLabel = new List <string> {
                "{branchName}"
            };
            var expectedMeta = new List <string> {
                "meta"
            };

            var config = new RepositoryConfiguration
            {
                Version  = "0.1.0",
                Branches =
                {
                    Overrides        =
                    {
                        new BranchOverrideConfiguration
                        {
                            Match    = "feature/other",
                            Label    = expectedLabel,
                            Metadata = expectedMeta
                        }
                    }
                }
            };

            using var fixture = new SimpleVersionRepositoryFixture(config, _serializer);

            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            fixture.BranchTo("feature/other");
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            // Use a processor to capture the configuration during processing.
            var            processor = Substitute.For <IVersionProcessor>();
            VersionContext context   = null;

            processor.When(x => x.Process(Arg.Any <VersionContext>()))
            .Do(call => context = call.Arg <VersionContext>());

            var sut = new GitVersionRepository(fixture.RepositoryPath, _environment, _serializer, new[] { processor });

            // Act
            var result = sut.GetResult();

            context.Configuration.Label.Should().BeEquivalentTo(expectedLabel, options => options.WithStrictOrdering());
            context.Configuration.Metadata.Should().BeEquivalentTo(expectedMeta, options => options.WithStrictOrdering());
        }
예제 #3
0
        public void Override_Branches_Do_Not_Work_If_Asterisk_Used_In_Label()
        {
            // Create the configuration model
            var config = new Model.Configuration
            {
                Version  = "1.0.0",
                Label    = { "r*" },
                Branches =
                {
                    Release       =
                    {
                        "^refs/heads/master$",
                        "^refs/heads/release/.+$",
                        "^refs/heads/feature/.+$"
                    },
                    Overrides     =
                    {
                        new Model.BranchConfiguration
                        {
                            Match = "^refs/heads/feature/.+$",
                            Label = new List <string>{
                                "{shortbranchname}"
                            }
                        }
                    }
                }
            };

            // Arrange
            using (var fixture = new SimpleVersionRepositoryFixture(config))
                using (EnvrionmentContext.NoBuildServer())
                {
                    // Make some extra commits on master
                    fixture.MakeACommit();
                    fixture.MakeACommit();
                    fixture.MakeACommit();

                    // branch to a feature branch
                    fixture.BranchTo("feature/PBI-319594-GitVersionDeprecation");
                    fixture.MakeACommit();
                    fixture.MakeACommit();
                    fixture.MakeACommit();

                    // Act
                    var result  = GetResult(fixture);
                    var semver1 = result.Formats[Semver1FormatProcess.FormatKey];
                    var semver2 = result.Formats[Semver2FormatProcess.FormatKey];

                    // Assert
                    semver1.Should().Be("1.0.0-featurePBI319594GitVersionDeprecation-0007");
                    semver2.Should().Be("1.0.0-featurePBI319594GitVersionDeprecation.7");
                }
        }
        public void GetResult_SetsIsRelease(string branchName, bool isRelease)
        {
            // Arrange
            using var fixture = new SimpleVersionRepositoryFixture(_serializer);
            var sut = new GitVersionRepository(fixture.RepositoryPath, _environment, _serializer, Enumerable.Empty <IVersionProcessor>());

            fixture.BranchTo(branchName);

            // Act
            var result = sut.GetResult();

            // Assert
            result.IsRelease.Should().Be(isRelease);
        }
        public void GetResult_Feature_Branch_Sets_BranchName()
        {
            // Arrange
            using var fixture = new SimpleVersionRepositoryFixture(_serializer);
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            fixture.BranchTo("feature/other");
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            var sut = new GitVersionRepository(fixture.RepositoryPath, _environment, _serializer, Enumerable.Empty <IVersionProcessor>());

            // Act
            var result = sut.GetResult();

            result.BranchName.Should().Be("feature/other");
            result.CanonicalBranchName.Should().Be("refs/heads/feature/other");
        }
        public void GetResult_Feature_Branch_No_Change_Increments_Merge_Once()
        {
            // Arrange
            using var fixture = new SimpleVersionRepositoryFixture(_serializer);
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            fixture.BranchTo("feature/other");
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            fixture.Checkout("master");
            fixture.MergeNoFF("feature/other");

            var sut = new GitVersionRepository(fixture.RepositoryPath, _environment, _serializer, Enumerable.Empty <IVersionProcessor>());

            // Act
            var result = sut.GetResult();

            result.Height.Should().Be(6);
        }
        public void GetResult_AdvancedBranchOverride_AppliesOverride()
        {
            // Arrange
            var expectedLabel = new List <string> {
                "preL1", "preL2", "L1", "insertedL", "L2", "postL1", "postL2"
            };
            var expectedMeta = new List <string> {
                "preM1", "preM2", "M1", "insertedM", "M2", "postM1", "postM2"
            };

            var config = new RepositoryConfiguration
            {
                Version  = "0.1.0",
                Label    = { "L1", "L2" },
                Metadata = { "M1", "M2" },
                Branches =
                {
                    Overrides               =
                    {
                        new BranchOverrideConfiguration
                        {
                        Match       = "feature/other",
                        PrefixLabel = new List <string> {
                            "preL1", "preL2"
                        },
                        PostfixLabel    = new List <string>{
                            "postL1", "postL2"
                        },
                        InsertLabel     = new Dictionary <int,string>{
                            [1] = "insertedL"
                        },
                        PrefixMetadata  = new List <string>{
                            "preM1", "preM2"
                        },
                        PostfixMetadata = new List <string> {
                            "postM1", "postM2"
                        },
                        InsertMetadata  = new Dictionary <int,string> {
                            [1] = "insertedM"
                        }
                        }
                    }
                }
            };

            using var fixture = new SimpleVersionRepositoryFixture(config, _serializer);
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            fixture.BranchTo("feature/other");
            fixture.MakeACommit();
            fixture.MakeACommit();
            fixture.MakeACommit();

            // Use a processor to capture the configuration during processing.
            var            processor = Substitute.For <IVersionProcessor>();
            VersionContext context   = null;

            processor.When(x => x.Process(Arg.Any <VersionContext>()))
            .Do(call => context = call.Arg <VersionContext>());

            var sut = new GitVersionRepository(fixture.RepositoryPath, _environment, _serializer, new[] { processor });

            // Act
            var result = sut.GetResult();

            context.Configuration.Label.Should().BeEquivalentTo(expectedLabel, options => options.WithStrictOrdering());
            context.Configuration.Metadata.Should().BeEquivalentTo(expectedMeta, options => options.WithStrictOrdering());
        }