Skip to content

feature commits filter by date range #4241

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/commands/git_commands/commit_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type GetCommitsOptions struct {
// If non-empty, show divergence from this ref (left-right log)
RefToShowDivergenceFrom string
MainBranches *MainBranches
Since string
Until string
}

// GetCommits obtains the commits of the current branch
Expand Down Expand Up @@ -517,6 +519,8 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
ArgIf(opts.FilterPath != "", "--follow").
Arg("--no-show-signature").
ArgIf(opts.RefToShowDivergenceFrom != "", "--left-right").
ArgIf(opts.Since != "", "--since="+opts.Since). // Date filtering (start date)
ArgIf(opts.Until != "", "--until="+opts.Until). // Date filtering (end date)
Arg("--").
ArgIf(opts.FilterPath != "", opts.FilterPath).
ToArgv()
Expand Down
28 changes: 28 additions & 0 deletions pkg/gui/controllers/filtering_menu_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ func (self *FilteringMenuAction) Call() error {
Tooltip: tooltip,
})

menuItems = append(menuItems, &types.MenuItem{
Label: self.c.Tr.FilterDateRangeOption,
OnPress: func() error {
self.c.Prompt(types.PromptOpts{
Title: "Enter start date (YYYY-MM-DD)",
HandleConfirm: func(since string) error {
self.c.Prompt(types.PromptOpts{
Title: "Enter end date (YYYY-MM-DD)",
HandleConfirm: func(until string) error {
return self.setFilteringDateRange(strings.TrimSpace(since), strings.TrimSpace(until))
},
})
return nil
},
})

return nil
},
Tooltip: tooltip,
})

if self.c.Modes().Filtering.Active() {
menuItems = append(menuItems, &types.MenuItem{
Label: self.c.Tr.ExitFilterMode,
Expand All @@ -112,6 +133,13 @@ func (self *FilteringMenuAction) setFilteringAuthor(author string) error {
return self.setFiltering()
}

func (self *FilteringMenuAction) setFilteringDateRange(since string, until string) error {
self.c.Modes().Filtering.Reset()
self.c.Modes().Filtering.SetSince(since)
self.c.Modes().Filtering.SetUntil(until)
return self.setFiltering()
}

func (self *FilteringMenuAction) setFiltering() error {
self.c.Modes().Filtering.SetSelectedCommitHash(self.c.Contexts().LocalCommits.GetSelectedCommitHash())

Expand Down
2 changes: 2 additions & 0 deletions pkg/gui/controllers/helpers/refresh_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ func (self *RefreshHelper) refreshCommitsWithLimit() error {
RefForPushedStatus: checkedOutBranchName,
All: self.c.Contexts().LocalCommits.GetShowWholeGitGraph(),
MainBranches: self.c.Model().MainBranches,
Since: self.c.Modes().Filtering.GetSince(),
Until: self.c.Modes().Filtering.GetUntil(),
},
)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions pkg/gui/modes/filtering/filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ type Filtering struct {
path string // the filename that gets passed to git log
author string // the author that gets passed to git log
selectedCommitHash string // the commit that was selected before we entered filtering mode
since string
until string
}

func New(path string, author string) Filtering {
Expand Down Expand Up @@ -42,3 +44,19 @@ func (m *Filtering) SetSelectedCommitHash(hash string) {
func (m *Filtering) GetSelectedCommitHash() string {
return m.selectedCommitHash
}

func (m *Filtering) SetSince(since string) {
m.since = since
}

func (m *Filtering) SetUntil(until string) {
m.until = until
}

func (m *Filtering) GetSince() string {
return m.since
}

func (m *Filtering) GetUntil() string {
return m.until
}
3 changes: 2 additions & 1 deletion pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ type TranslationSet struct {
BreakingChangesTitle string
BreakingChangesMessage string
BreakingChangesByVersion map[string]string
FilterDateRangeOption string
}

type Bisect struct {
Expand Down Expand Up @@ -1870,7 +1871,7 @@ func EnglishTranslationSet() *TranslationSet {
RangeSelectNotSupportedForSubmodules: "Range select not supported for submodules",
OldCherryPickKeyWarning: "The 'c' key is no longer the default key for copying commits to cherry pick. Please use `{{.copy}}` instead (and `{{.paste}}` to paste). The reason for this change is that the 'v' key for selecting a range of lines when staging is now also used for selecting a range of lines in any list view, meaning that we needed to find a new key for pasting commits, and if we're going to now use `{{.paste}}` for pasting commits, we may as well use `{{.copy}}` for copying them. If you want to configure the keybindings to get the old behaviour, set the following in your config:\n\nkeybinding:\n universal:\n toggleRangeSelect: <something other than v>\n commits:\n cherryPickCopy: 'c'\n pasteCommits: 'v'",
CommandDoesNotSupportOpeningInEditor: "This command doesn't support switching to the editor",

FilterDateRangeOption: "Filter Date Range",
Actions: Actions{
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
CheckoutCommit: "Checkout commit",
Expand Down