diff options
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git_commands/commit_loader.go | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/reflog_commit_loader.go | 3 | ||||
-rw-r--r-- | pkg/commands/git_commands/reflog_commit_loader_test.go | 28 |
3 files changed, 31 insertions, 2 deletions
diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index 7c385d2fa..2acde9da5 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -64,6 +64,7 @@ func NewCommitLoader( type GetCommitsOptions struct { Limit bool FilterPath string + FilterAuthor string IncludeRebaseCommits bool RefName string // e.g. "HEAD" or "my_branch" RefForPushedStatus string // the ref to use for determining pushed/unpushed status @@ -664,6 +665,7 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj { Arg("--oneline"). Arg(prettyFormat). Arg("--abbrev=40"). + ArgIf(opts.FilterAuthor != "", "--author="+opts.FilterAuthor). ArgIf(opts.Limit, "-300"). ArgIf(opts.FilterPath != "", "--follow"). Arg("--no-show-signature"). diff --git a/pkg/commands/git_commands/reflog_commit_loader.go b/pkg/commands/git_commands/reflog_commit_loader.go index 1160839d6..b8682241a 100644 --- a/pkg/commands/git_commands/reflog_commit_loader.go +++ b/pkg/commands/git_commands/reflog_commit_loader.go @@ -23,7 +23,7 @@ func NewReflogCommitLoader(common *common.Common, cmd oscommands.ICmdObjBuilder) // GetReflogCommits only returns the new reflog commits since the given lastReflogCommit // if none is passed (i.e. it's value is nil) then we get all the reflog commits -func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit, filterPath string) ([]*models.Commit, bool, error) { +func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit, filterPath string, filterAuthor string) ([]*models.Commit, bool, error) { commits := make([]*models.Commit, 0) cmdArgs := NewGitCmd("log"). @@ -31,6 +31,7 @@ func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit Arg("-g"). Arg("--abbrev=40"). Arg("--format=%h%x00%ct%x00%gs%x00%p"). + ArgIf(filterAuthor != "", "--author="+filterAuthor). ArgIf(filterPath != "", "--follow", "--", filterPath). ToArgv() diff --git a/pkg/commands/git_commands/reflog_commit_loader_test.go b/pkg/commands/git_commands/reflog_commit_loader_test.go index c17f7e2ba..a8a249588 100644 --- a/pkg/commands/git_commands/reflog_commit_loader_test.go +++ b/pkg/commands/git_commands/reflog_commit_loader_test.go @@ -25,6 +25,7 @@ func TestGetReflogCommits(t *testing.T) { runner *oscommands.FakeCmdObjRunner lastReflogCommit *models.Commit filterPath string + filterAuthor string expectedCommits []*models.Commit expectedOnlyObtainedNew bool expectedError error @@ -137,6 +138,31 @@ func TestGetReflogCommits(t *testing.T) { expectedError: nil, }, { + testName: "when passing filterAuthor", + runner: oscommands.NewFakeRunner(t). + ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p", "--author=John Doe <john@doe.com>"}, reflogOutput, nil), + + lastReflogCommit: &models.Commit{ + Sha: "c3c4b66b64c97ffeecde", + Name: "checkout: moving from B to A", + Status: models.StatusReflog, + UnixTimestamp: 1643150483, + Parents: []string{"51baa8c1"}, + }, + filterAuthor: "John Doe <john@doe.com>", + expectedCommits: []*models.Commit{ + { + Sha: "c3c4b66b64c97ffeecde", + Name: "checkout: moving from A to B", + Status: models.StatusReflog, + UnixTimestamp: 1643150483, + Parents: []string{"51baa8c1"}, + }, + }, + expectedOnlyObtainedNew: true, + expectedError: nil, + }, + { testName: "when command returns error", runner: oscommands.NewFakeRunner(t). ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p"}, "", errors.New("haha")), @@ -157,7 +183,7 @@ func TestGetReflogCommits(t *testing.T) { cmd: oscommands.NewDummyCmdObjBuilder(scenario.runner), } - commits, onlyObtainednew, err := builder.GetReflogCommits(scenario.lastReflogCommit, scenario.filterPath) + commits, onlyObtainednew, err := builder.GetReflogCommits(scenario.lastReflogCommit, scenario.filterPath, scenario.filterAuthor) assert.Equal(t, scenario.expectedOnlyObtainedNew, onlyObtainednew) assert.Equal(t, scenario.expectedError, err) t.Logf("actual commits: \n%s", litter.Sdump(commits)) |