示例#1
0
        public void AssemblySemFileVerShouldBeWeightedByPreReleaseWeight()
        {
            var config = new Config
            {
                AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
                Branches =
                {
                    { "release", new BranchConfig
                        {
                            PreReleaseWeight = 1000
                        } }
                }
            };

            using (var fixture = new EmptyRepositoryFixture())
            {
                fixture.Repository.MakeATaggedCommit("1.0.3");
                fixture.Repository.MakeCommits(5);
                fixture.Repository.CreateBranch("release-2.0.0");
                fixture.Checkout("release-2.0.0");
                ConfigurationProvider.ApplyDefaultsTo(config);
                var variables = fixture.GetVersion(config);
                Assert.AreEqual(variables.AssemblySemFileVer, "2.0.0.1001");
            }
        }
示例#2
0
        public void CanInheritVersioningMode(VersioningMode mode)
        {
            var config = new Config
            {
                VersioningMode = mode
            };

            ConfigurationProvider.ApplyDefaultsTo(config);

            var mockBranch = new MockBranch("master")
            {
                new MockCommit {
                    CommitterEx = Generate.SignatureNow()
                }
            };
            var mockRepository = new MockRepository
            {
                Branches = new MockBranchCollection
                {
                    mockBranch
                }
            };

            var context = new GitVersionContext(mockRepository, new NullLog(), mockBranch, config);

            context.Configuration.VersioningMode.ShouldBe(mode);
        }
        public GitVersionContext Build()
        {
            var configuration = config ?? new Config();

            ConfigurationProvider.ApplyDefaultsTo(configuration);
            return(new GitVersionContext(repository ?? CreateRepository(), configuration));
        }
示例#4
0
 protected RepositoryFixtureBase(Config configuration, IRepository repository)
 {
     ConfigurationProvider.ApplyDefaultsTo(configuration);
     diagramBuilder = new StringBuilder();
     diagramBuilder.AppendLine("@startuml");
     this.configuration = configuration;
     Repository         = repository;
     Repository.Config.Set("user.name", "Test");
     Repository.Config.Set("user.email", "*****@*****.**");
     IsForTrackedBranchOnly = true;
 }
示例#5
0
        static IOrderedEnumerable <KeyValuePair <string, BranchConfig> > OrderedBranches(Config config)
        {
            var defaultConfig = new Config();

            ConfigurationProvider.ApplyDefaultsTo(defaultConfig);
            var defaultConfigurationBranches = defaultConfig.Branches
                                               .Where(k => !config.Branches.ContainsKey(k.Key))
                                               // Return an empty branch config
                                               .Select(v => new KeyValuePair <string, BranchConfig>(v.Key, null));

            return(config.Branches.Union(defaultConfigurationBranches).OrderBy(b => b.Key));
        }
示例#6
0
 protected RepositoryFixtureBase(Func <string, IRepository> repoBuilder, Config configuration)
 {
     ConfigurationProvider.ApplyDefaultsTo(configuration);
     diagramBuilder = new StringBuilder();
     diagramBuilder.AppendLine("@startuml");
     this.configuration = configuration;
     RepositoryPath     = PathHelper.GetTempPath();
     Repository         = repoBuilder(RepositoryPath);
     Repository.Config.Set("user.name", "Test");
     Repository.Config.Set("user.email", "*****@*****.**");
     IsForTrackedBranchOnly = true;
 }
示例#7
0
        public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true)
        {
            ConfigurationProvider.ApplyDefaultsTo(configuration);
            var gitVersionContext = new GitVersionContext(repository ?? fixture.Repository, configuration, isForTrackedBranchOnly, commitId);
            var executeGitVersion = ExecuteGitVersion(gitVersionContext);
            var variables         = VariableProvider.GetVariablesFor(executeGitVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged);

            try
            {
                return(variables);
            }
            catch (Exception)
            {
                Console.WriteLine("Test failing, dumping repository graph");
                gitVersionContext.Repository.DumpGraph();
                throw;
            }
        }
        public static void AssertFullSemver(this RepositoryFixtureBase fixture, Config configuration, string fullSemver, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true)
        {
            ConfigurationProvider.ApplyDefaultsTo(configuration);
            Console.WriteLine("---------");

            try
            {
                var variables = fixture.GetVersion(configuration, repository, commitId, isForTrackedBranchOnly);
                variables.FullSemVer.ShouldBe(fullSemver);
            }
            catch (Exception)
            {
                (repository ?? fixture.Repository).DumpGraph();
                throw;
            }
            if (commitId == null)
            {
                fixture.SequenceDiagram.NoteOver(fullSemver, fixture.Repository.Head.FriendlyName, color: "#D3D3D3");
            }
        }
示例#9
0
        public void UsesBranchSpecificConfigOverTopLevelDefaults()
        {
            var config = new Config
            {
                VersioningMode = VersioningMode.ContinuousDelivery,
                Branches       =
                {
                    {
                        "develop", new BranchConfig
                        {
                            VersioningMode = VersioningMode.ContinuousDeployment,
                            Tag            = "alpha"
                        }
                    }
                }
            };

            ConfigurationProvider.ApplyDefaultsTo(config);
            var develop = new MockBranch("develop")
            {
                new MockCommit {
                    CommitterEx = Generate.SignatureNow()
                }
            };
            var mockRepository = new MockRepository
            {
                Branches = new MockBranchCollection
                {
                    new MockBranch("master")
                    {
                        new MockCommit {
                            CommitterEx = Generate.SignatureNow()
                        }
                    },
                    develop
                }
            };
            var context = new GitVersionContext(mockRepository, new NullLog(), develop, config);

            context.Configuration.Tag.ShouldBe("alpha");
        }
示例#10
0
        public void CanInheritIncrement(IncrementStrategy increment, IncrementStrategy?alternateExpected)
        {
            // Dummy branch name to make sure that no default config exists.
            const string dummyBranchName = "dummy";

            var config = new Config
            {
                Increment = increment
            };

            ConfigurationProvider.ApplyDefaultsTo(config);

            using (var fixture = new EmptyRepositoryFixture())
            {
                fixture.MakeACommit();
                fixture.BranchTo(dummyBranchName);
                fixture.MakeACommit();

                var context = new GitVersionContext(fixture.Repository, new NullLog(), fixture.Repository.Branches[dummyBranchName], config);
                context.Configuration.Increment.ShouldBe(alternateExpected ?? increment);
            }
        }
 public static Config ApplyDefaults(this Config config)
 {
     ConfigurationProvider.ApplyDefaultsTo(config);
     return(config);
 }