// for now, caching is disabled since the log filters can change the results so much public GitLogCommand(GetGitLog cmdlet) : base(cmdlet.RepositoryDirectories, false) { this.CmdletWriter = cmdlet.CmdletWriter; this.EndOfLineToken = "]|["; this.ValueSplitToken = "|,|"; this.Before = MakeFilterDate(cmdlet.Before); this.After = MakeFilterDate(cmdlet.After); var after = string.IsNullOrEmpty(this.After) ? "" : $" --since=\"{this.After}\""; var before = string.IsNullOrEmpty(this.Before) ? "" : $" --before=\"{this.Before}\""; // format specs: https://git-scm.com/docs/pretty-formats var formatText = string.Format(" --pretty=format:\"%H{1}%ai{1}%ae{1}%cn{1}%ci{1}%s{1}%d{0}\"", EndOfLineToken, ValueSplitToken); var tokenOrder = new GitLogEntryLabels[] { GitLogEntryLabels.Hash, GitLogEntryLabels.AuthorDate, GitLogEntryLabels.AuthorEmail, GitLogEntryLabels.AuthorName, GitLogEntryLabels.CommitDate, GitLogEntryLabels.Subject, GitLogEntryLabels.Refs }; Name = "Log"; CacheName = "log"; Command = $"git log {after}{before}{formatText}"; CacheLinkFiles = new string[] { "index", "FETCH_HEAD", "HEAD", "COMMIT_EDITMSG", "refs/remotes/origin/{branchName}" }; Parser = new GitLogParser(this, tokenOrder); CommandExecFolder = RepositoryDirectories.CurrentPath; CmdletWriter.WriteVerbose($"Command: {Command}"); }
public GivenAGetGitLog() { this.mockCmdlet = new Mock <ICmdlet>(); this.mockCommandLineParser = new Mock <ICommandLineParser>(); mockCommandLineParser.Setup(m => m.ParseCommandLine("git log")).Returns(new Tuple <string, string>("git", "log")); this.mockProcessWrapper = new Mock <IProcessWrapper>(); invokeLines = new List <string>(); mockProcessWrapper.Setup(m => m.Invoke("git", "log", "workingdir")).Returns(new Tuple <int, List <string> >(0, invokeLines)); this.mockGitLogParser = new Mock <IGitLogParser>(); mockGitLogParser.Setup(m => m.Parse(invokeLines)).Returns(new List <GitCommit>()); this.cmdlet = new GetGitLog(); this.cmdlet.GitLogCommand = "git log"; this.cmdlet.WorkingDirectory = "workingdir"; this.cmdlet.InjectDependencies(mockCommandLineParser.Object, mockProcessWrapper.Object, mockGitLogParser.Object, mockCmdlet.Object); }