Beispiel #1
0
        private static int Main(string[] args)
        {
            using var app = new CommandLineApplication
                  {
                      Name = "git-flow-version"
                  };
            app.HelpOption("-?|-h|--help");

            var optionBranch  = app.Option("-b|--branch", "Manually set the branch to use, for determining the branch 'type' and pre-release label. This can be a full or partial name.", CommandOptionType.SingleValue);
            var optionVersion = app.Option("-v|--version", "Returns the currently installed version of git-flow-version.", CommandOptionType.NoValue);
            var optionDebug   = app.Option("-d|--debug", "Adds a debug prerelease label to the version number.", CommandOptionType.NoValue);

            app.OnExecute(() =>
            {
                if (optionVersion.HasValue())
                {
                    WriteGitFlowVersion();
                    return(0);
                }
                try
                {
                    OutputJsonToConsole(VersionNumberGenerator.GenerateVersionNumber(Environment.CurrentDirectory, optionBranch.Value()), optionDebug.HasValue());
                    return(0);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.Message);
                    return(-1);
                }
            });
            return(app.Execute(args));
        }
Beispiel #2
0
        public void VersionNumberReleaseBranchLabelOrdinalStartsAtOne()
        {
            _mock.Setup(f => f.CurrentBranch).Returns(new ReleaseCandidateBranchInfo("release/1.0.0", "1.0.0"));
            _mock.Setup(f => f.HeadCommitHash).Returns("a");

            var version = VersionNumberGenerator.GenerateVersionNumber(_mock.Object);

            version.PreReleaseLabel.Should().NotBeNull();
            version.PreReleaseLabel?.BranchLabel.Ordinal.Equals(1);
        }
Beispiel #3
0
        public void VersionNumberReleaseBranchLabelOrdinalIncrements(
            uint ordinal,
            uint expectedOrdinal)
        {
            _mock.Setup(f => f.CurrentBranch).Returns(new ReleaseCandidateBranchInfo("release/1.0.0", "1.0.0"));
            _mock.Setup(f => f.HeadCommitHash).Returns("a");
            _mock.Setup(f => f.HighestMatchingTagForReleaseCandidate).Returns(new VersionNumber(1, 0, 0, new PreReleaseLabel(new PreReleaseLabelParticle("rc", ordinal))));

            var version = VersionNumberGenerator.GenerateVersionNumber(_mock.Object);

            version.PreReleaseLabel.Should().NotBeNull();
            version.PreReleaseLabel?.BranchLabel.Ordinal.Equals(expectedOrdinal);
        }
Beispiel #4
0
        public void VersionNumberDevelopVersion(
            string highestAnnotatedTag,
            uint commitsSinceAnnotatedTag,
            string hash,
            string expectedVersion)
        {
            _mock.Setup(f => f.CurrentBranch).Returns(BranchInfoFactory.CreateBranchInfo(Constants.DevelopBranchName));
            _mock.Setup(f => f.CurrentCoreVersion).Returns(VersionNumber.Parse(highestAnnotatedTag));
            _mock.Setup(f => f.CommitCountDevelopSinceLastMinorCoreVersion).Returns(commitsSinceAnnotatedTag);
            _mock.Setup(f => f.HeadCommitHash).Returns(hash);

            var version = VersionNumberGenerator.GenerateVersionNumber(_mock.Object);

            version.FullSemVer.Should().Be(expectedVersion);
        }
Beispiel #5
0
        public void VersionNumberFeatureVersion(
            string highestAnnotatedTag,
            string branchName,
            uint commitsOnDevelopSinsLastMinorCoreVersion,
            uint commitsUniqueToFeature,
            string hash,
            string expectedVersion)
        {
            _mock.Setup(f => f.CurrentBranch).Returns(BranchInfoFactory.CreateBranchInfo(branchName));
            _mock.Setup(f => f.CurrentCoreVersion).Returns(VersionNumber.Parse(highestAnnotatedTag));
            _mock.Setup(f => f.CommitCountDevelopSinceLastMinorCoreVersion).Returns(commitsOnDevelopSinsLastMinorCoreVersion);
            _mock.Setup(f => f.CommitCountUniqueToFeature).Returns(commitsUniqueToFeature);
            _mock.Setup(f => f.HeadCommitHash).Returns(hash);

            var version = VersionNumberGenerator.GenerateVersionNumber(_mock.Object);

            version.ToString().Should().Be(expectedVersion);
        }
Beispiel #6
0
 private static VersionNumber GenerateVersionNumber(IGitRepository gitRepository, string branchName = "") =>
 VersionNumberGenerator.GenerateVersionNumber(
     new GitRepoReader(
         gitRepository,
         branchName));