示例#1
0
        private void Run(TagPickerTestCase testCase)
        {
            INode MockNode(string hash, DateTimeOffset?date)
            {
                ICommit commit = new CommitStub(hash, date ?? DateTimeOffset.MinValue);
                INode   node   = new NodeStub(commit);

                return(node);
            }

            IBranch MockBranch(string name)
            {
                if (string.IsNullOrWhiteSpace(name))
                {
                    return(null);
                }

                return(new Branch(name, null));
            }

            ITagPickingOptions tpo = TagPickingOptions.Set(
                testCase.Mode,
                testCase.TakeCount,
                testCase.IncludeOrphanedTags);
            TagPicker p = new TagPicker(tpo);

            ITag ta = new Tag(testCase.TagAName, null);
            ITag tb = new Tag(testCase.TagBName, null);
            ITag tc = new Tag(testCase.TagCName, null);

            INode na = MockNode("na", testCase.CommitADate);
            INode nb = MockNode("nb", testCase.CommitBDate);
            INode nc = MockNode("nc", testCase.CommitCDate);

            IBranch ba = MockBranch(testCase.BranchAName);
            IBranch bb = MockBranch(testCase.BranchBName);
            IBranch bc = MockBranch(testCase.BranchCName);

            var tagInfos = new[]
            {
                new TagInfo(ta, na, ba),
                new TagInfo(tb, nb, bb),
                new TagInfo(tc, nc, bc)
            };

            p.PreProcessAllTags(tagInfos);

            Assert.Equal(testCase.ExpectedTagAPicked, p.CheckIfTagShouldBePicked(ta));
            Assert.Equal(testCase.ExpectedTagBPicked, p.CheckIfTagShouldBePicked(tb));
            Assert.Equal(testCase.ExpectedTagCPicked, p.CheckIfTagShouldBePicked(tc));
        }
示例#2
0
        protected override void RunInternal()
        {
            // Get the immutable repository information.

            IRepositoryData repositoryData = _loader.LoadFrom(_repositoryDir.FullName);

            // Pick the remote to work on.
            IRemote remoteToUse = _remoteHelper.PickRemote(repositoryData, Options.RemoteToUse);

            // Create the tree.
            IBranchingStrategy strategy = _strategyProvider.GetStrategy(Options.LesserBranchesRegex);

            IBranch[]          allBranches       = repositoryData.Branches.GetFor(remoteToUse).ToArray();
            IBranchesKnowledge branchesKnowledge = strategy.CreateKnowledge(allBranches);

            // Options for building the tree.
            ITagPickingOptions tagPickingOptions = TagPickingOptions.Set(
                Options.TagPickingMode,
                Options.TagCount,
                Options.IncludeOrphanedTags);
            IBranchPickingOptions branchPickingOptions = BranchPickingOptions.Set(
                Options.IncludeBranchesRegices,
                Options.ExcludeBranchesRegices);

            ITree tree = _treeBuilder.Build(
                repositoryData,
                remoteToUse,
                branchesKnowledge,
                branchPickingOptions,
                tagPickingOptions);

            SimplifyTree(tree);

            string tempPath = _fileSystem.Path.GetTempFileName();

            tempPath = _fileSystem.Path.ChangeExtension(tempPath, "gv");

            // Rendering options.
            TreeRenderingOptions renderingOptions = TreeRenderingOptions.Default;

            renderingOptions.ForceTreatAsGitHub = Options.ForceTreatAsGitHub;

            // ReSharper disable once AssignNullToNotNullAttribute
            using (IFileStream fileStream = _fileSystem.File.OpenWrite(tempPath))
            {
                using (IStreamWriter textWriter = _textWriterFactory.CreateStreamWriter(fileStream))
                {
                    IGraphVizWriter graphVizWriter = _graphVizFactory.CreateGraphVizWriter(textWriter);

                    ITreeRenderer treeRenderer = _treeRendererFactory.CreateRenderer(graphVizWriter);
                    treeRenderer.Render(tree, remoteToUse, branchesKnowledge, renderingOptions);
                }
            }

            string targetPath = PrepareTargetPath();

            string graphVizCommand = _appPathProvider.GetProperAppPath(ExternalApp.GraphViz);
            string graphVizArgs    = $@"""{tempPath}"" -T{_outputFormat} -o""{targetPath}""";

            Log.Debug($"Starting GraphViz with arguments: [{graphVizArgs}].");
            int code = _processRunner.Execute(graphVizCommand, graphVizArgs);

            if (code != 0)
            {
                Log.Fatal("GraphViz execution failed.");
            }
            else
            {
                Log.Info("GraphViz execution succeeded.");
                Log.Info($"Saved to {targetPath}.");
            }
        }