Exemple #1
0
        public Task <int> Intercept(
            InterceptorExecutionDelegate next,
            RepoAppOptions options,
            IConsole console)
        {
            _console = console;
            _writer  = new IndentableStreamWriter(console.Out);
            _writeln = _writer.WriteLine;

            _repo = new Repo(options.RepoDir, options.Branch);
            return(next());
        }
Exemple #2
0
        private void WriteCommitsAndFiles(IndentableStreamWriter writer, Project project, TagInfo tagInfo,
                                          CommitsAndFilesArgs args, CancellationToken cancellationToken)
        {
            var nextTagInfo = tagInfo.Next;
            var target      = tagInfo.Tag.Target;
            var nextTarget  = nextTagInfo?.Tag.Target ?? project.Tip;

            // https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection  #Commit Ranges
            var commitRange = $"{tagInfo.FriendlyName}...{nextTagInfo?.FriendlyName ?? project.Branch.FriendlyName}";

            //https://github.com/bilal-fazlani/commanddotnet/compare/CommandDotNet_3.5.0...CommandDotNet_3.5.1
            writer.WriteLine($"{_repo.GetOriginRepoUrl().HttpsUrl}/compare/{commitRange}".Theme_GitLinks());

            if (args.ShowCommits)
            {
                writer.WriteLine($"git log --graph {commitRange} -- {project.Directory}".Theme_GitLinks());
                writer.WriteLine($"git log --oneline --graph {commitRange} -- {project.Directory}".Theme_GitLinks());

                foreach (var commit in project
                         .GetCommitsBetween(target, nextTarget, cancellationToken)
                         .TakeUntil(_ => cancellationToken.IsCancellationRequested))
                {
                    writer.WriteLine(
                        $"{commit.ShortSha()} {commit.Author.Theme_WhenDateTime()} {commit.MessageShort.Theme_GitMessage()}");
                }
            }

            if (args.ShowFiles)
            {
                // https://stackoverflow.com/questions/1552340/how-to-list-only-the-file-names-that-changed-between-two-commits/6827937

                writer.WriteLine($"git diff {commitRange} -- {project.Directory}".Theme_GitLinks());
                writer.WriteLine($"git diff --name-status {commitRange} -- {project.Directory}".Theme_GitLinks());

                foreach (var file in project.GetFilesChangedBetween(target, nextTarget))
                {
                    writer.WriteLine($"{file.Theme_FileChange()}");
                }
            }
        }