Skip to content

Commit af56065

Browse files
authored
Add author filtering to commit view (#3302)
- **PR Description** This PR introduces a new feature to the commit view, allowing users to filter commits based on the author's name or email address. Similar to the existing path filtering functionality, accessible through `<c-s>`, this feature allows users to filter the commit history by the currently selected commit's author if the commit view is focused, or by typing in the author's name or email address. This feature adds an entry to the filtering menu, to provide users with a familiar and intuitive experience ![filter-by-author](https://github.com/jesseduffield/lazygit/assets/3098462/5b00a716-e432-4204-8568-0e93b1411bc7) - **Please check if the PR fulfils these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [x] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [x] Docs (specifically `docs/Config.md`) have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents 329b434 + 503422a commit af56065

22 files changed

+292
-27
lines changed

docs/keybindings/Keybindings_en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
2323
| `` + `` | Next screen mode (normal/half/fullscreen) | |
2424
| `` _ `` | Prev screen mode | |
2525
| `` ? `` | Open keybindings menu | |
26-
| `` <c-s> `` | View filter-by-path options | View options for filtering the commit log by a file path, so that only commits relating to that path are shown. |
26+
| `` <c-s> `` | View filter options | View options for filtering the commit log, so that only commits matching the filter are shown. |
2727
| `` W `` | View diffing options | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2828
| `` <c-e> `` | View diffing options | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2929
| `` q `` | Quit | |

docs/keybindings/Keybindings_ja.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
2323
| `` + `` | 次のスクリーンモード (normal/half/fullscreen) | |
2424
| `` _ `` | 前のスクリーンモード | |
2525
| `` ? `` | メニューを開く | |
26-
| `` <c-s> `` | View filter-by-path options | View options for filtering the commit log by a file path, so that only commits relating to that path are shown. |
26+
| `` <c-s> `` | View filter options | View options for filtering the commit log, so that only commits matching the filter are shown. |
2727
| `` W `` | 差分メニューを開く | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2828
| `` <c-e> `` | 差分メニューを開く | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2929
| `` q `` | 終了 | |

docs/keybindings/Keybindings_ko.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
2323
| `` + `` | 다음 스크린 모드 (normal/half/fullscreen) | |
2424
| `` _ `` | 이전 스크린 모드 | |
2525
| `` ? `` | 매뉴 열기 | |
26-
| `` <c-s> `` | View filter-by-path options | View options for filtering the commit log by a file path, so that only commits relating to that path are shown. |
26+
| `` <c-s> `` | View filter-by-path options | View options for filtering the commit log, so that only commits matching the filter are shown. |
2727
| `` W `` | Diff 메뉴 열기 | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2828
| `` <c-e> `` | Diff 메뉴 열기 | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2929
| `` q `` | 종료 | |

docs/keybindings/Keybindings_nl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
2323
| `` + `` | Volgende scherm modus (normaal/half/groot) | |
2424
| `` _ `` | Vorige scherm modus | |
2525
| `` ? `` | Open menu | |
26-
| `` <c-s> `` | Bekijk scoping opties | View options for filtering the commit log by a file path, so that only commits relating to that path are shown. |
26+
| `` <c-s> `` | Bekijk scoping opties | View options for filtering the commit log, so that only commits matching the filter are shown. |
2727
| `` W `` | Open diff menu | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2828
| `` <c-e> `` | Open diff menu | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2929
| `` q `` | Quit | |

docs/keybindings/Keybindings_pl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
2323
| `` + `` | Next screen mode (normal/half/fullscreen) | |
2424
| `` _ `` | Prev screen mode | |
2525
| `` ? `` | Open keybindings menu | |
26-
| `` <c-s> `` | View filter-by-path options | View options for filtering the commit log by a file path, so that only commits relating to that path are shown. |
26+
| `` <c-s> `` | View filter options | View options for filtering the commit log, so that only commits matching the filter are shown. |
2727
| `` W `` | View diffing options | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2828
| `` <c-e> `` | View diffing options | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2929
| `` q `` | Quit | |

docs/keybindings/Keybindings_ru.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _Связки клавиш_
2323
| `` + `` | Следующий режим экрана (нормальный/полуэкранный/полноэкранный) | |
2424
| `` _ `` | Предыдущий режим экрана | |
2525
| `` ? `` | Открыть меню | |
26-
| `` <c-s> `` | Просмотреть параметры фильтрации по пути | View options for filtering the commit log by a file path, so that only commits relating to that path are shown. |
26+
| `` <c-s> `` | Просмотреть параметры фильтрации по пути | View options for filtering the commit log, so that only commits matching the filter are shown. |
2727
| `` W `` | Открыть меню сравнении | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2828
| `` <c-e> `` | Открыть меню сравнении | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2929
| `` q `` | Выйти | |

docs/keybindings/Keybindings_zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
2323
| `` + `` | 下一屏模式(正常/半屏/全屏) | |
2424
| `` _ `` | 上一屏模式 | |
2525
| `` ? `` | 打开菜单 | |
26-
| `` <c-s> `` | 查看按路径过滤选项 | View options for filtering the commit log by a file path, so that only commits relating to that path are shown. |
26+
| `` <c-s> `` | 查看按路径过滤选项 | View options for filtering the commit log, so that only commits matching the filter are shown. |
2727
| `` W `` | 打开 diff 菜单 | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2828
| `` <c-e> `` | 打开 diff 菜单 | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2929
| `` q `` | 退出 | |

docs/keybindings/Keybindings_zh-TW.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B_
2323
| `` + `` | 下一個螢幕模式(常規/半螢幕/全螢幕) | |
2424
| `` _ `` | 上一個螢幕模式 | |
2525
| `` ? `` | 開啟選單 | |
26-
| `` <c-s> `` | 檢視篩選路徑選項 | View options for filtering the commit log by a file path, so that only commits relating to that path are shown. |
26+
| `` <c-s> `` | 檢視篩選路徑選項 | View options for filtering the commit log, so that only commits matching the filter are shown. |
2727
| `` W `` | 開啟差異比較選單 | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2828
| `` <c-e> `` | 開啟差異比較選單 | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
2929
| `` q `` | 結束 | |

pkg/commands/git_commands/commit_loader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func NewCommitLoader(
6464
type GetCommitsOptions struct {
6565
Limit bool
6666
FilterPath string
67+
FilterAuthor string
6768
IncludeRebaseCommits bool
6869
RefName string // e.g. "HEAD" or "my_branch"
6970
RefForPushedStatus string // the ref to use for determining pushed/unpushed status
@@ -664,6 +665,7 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
664665
Arg("--oneline").
665666
Arg(prettyFormat).
666667
Arg("--abbrev=40").
668+
ArgIf(opts.FilterAuthor != "", "--author="+opts.FilterAuthor).
667669
ArgIf(opts.Limit, "-300").
668670
ArgIf(opts.FilterPath != "", "--follow").
669671
Arg("--no-show-signature").

pkg/commands/git_commands/reflog_commit_loader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ func NewReflogCommitLoader(common *common.Common, cmd oscommands.ICmdObjBuilder)
2323

2424
// GetReflogCommits only returns the new reflog commits since the given lastReflogCommit
2525
// if none is passed (i.e. it's value is nil) then we get all the reflog commits
26-
func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit, filterPath string) ([]*models.Commit, bool, error) {
26+
func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit, filterPath string, filterAuthor string) ([]*models.Commit, bool, error) {
2727
commits := make([]*models.Commit, 0)
2828

2929
cmdArgs := NewGitCmd("log").
3030
Config("log.showSignature=false").
3131
Arg("-g").
3232
Arg("--abbrev=40").
3333
Arg("--format=%h%x00%ct%x00%gs%x00%p").
34+
ArgIf(filterAuthor != "", "--author="+filterAuthor).
3435
ArgIf(filterPath != "", "--follow", "--", filterPath).
3536
ToArgv()
3637

0 commit comments

Comments
 (0)