Skip to content

Commit 7ebf634

Browse files
committed
feat: no-merges
1 parent 1d65196 commit 7ebf634

File tree

18 files changed

+174
-6
lines changed

18 files changed

+174
-6
lines changed

pkg/commands/git_commands/commit_loader.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ type GetCommitsOptions struct {
6868
RefToShowDivergenceFrom string
6969
MainBranches *MainBranches
7070
HashPool *utils.StringPool
71+
// If true, exclude merge commits from the output
72+
HideMerges bool
7173
}
7274

7375
// GetCommits obtains the commits of the current branch
@@ -589,6 +591,7 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) *oscommands.CmdObj {
589591
ArgIf(gitLogOrder != "default", "--"+gitLogOrder).
590592
ArgIf(opts.All, "--all").
591593
Arg("--oneline").
594+
ArgIf(opts.HideMerges, "--no-merges").
592595
Arg(prettyFormat).
593596
Arg("--abbrev=40").
594597
ArgIf(opts.FilterAuthor != "", "--author="+opts.FilterAuthor).

pkg/commands/git_commands/commit_loader_test.go

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,39 @@ func TestGetCommits(t *testing.T) {
6161
expectedCommitOpts: []models.NewCommitOpts{},
6262
expectedError: nil,
6363
},
64+
{
65+
testName: "should hide merge commits when HideMerges is true",
66+
logOrder: "topo-order",
67+
opts: GetCommitsOptions{RefName: "HEAD", RefForPushedStatus: &models.Branch{Name: "mybranch"}, IncludeRebaseCommits: false, HideMerges: true},
68+
runner: oscommands.NewFakeRunner(t).
69+
ExpectGitArgs([]string{"rev-list", "refs/heads/mybranch", "^mybranch@{u}"}, "", nil).
70+
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--no-merges", "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
71+
72+
expectedCommitOpts: []models.NewCommitOpts{},
73+
expectedError: nil,
74+
},
75+
{
76+
testName: "should not hide merge commits when HideMerges is false",
77+
logOrder: "topo-order",
78+
opts: GetCommitsOptions{RefName: "HEAD", RefForPushedStatus: &models.Branch{Name: "mybranch"}, IncludeRebaseCommits: false, HideMerges: false},
79+
runner: oscommands.NewFakeRunner(t).
80+
ExpectGitArgs([]string{"rev-list", "refs/heads/mybranch", "^mybranch@{u}"}, "", nil).
81+
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
82+
83+
expectedCommitOpts: []models.NewCommitOpts{},
84+
expectedError: nil,
85+
},
86+
{
87+
testName: "should hide merge commits when HideMerges is true with other options",
88+
logOrder: "date-order",
89+
opts: GetCommitsOptions{RefName: "HEAD", RefForPushedStatus: &models.Branch{Name: "mybranch"}, IncludeRebaseCommits: false, HideMerges: true, All: true},
90+
runner: oscommands.NewFakeRunner(t).
91+
ExpectGitArgs([]string{"rev-list", "refs/heads/mybranch", "^mybranch@{u}"}, "", nil).
92+
ExpectGitArgs([]string{"log", "HEAD", "--date-order", "--oneline", "--all", "--no-merges", "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
93+
94+
expectedCommitOpts: []models.NewCommitOpts{},
95+
expectedError: nil,
96+
},
6497
{
6598
testName: "should return commits if they are present",
6699
logOrder: "topo-order",
@@ -72,12 +105,12 @@ func TestGetCommits(t *testing.T) {
72105
// here it's actually getting all the commits in a formatted form, one per line
73106
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s", "--abbrev=40", "--no-show-signature", "--"}, commitsOutput, nil).
74107
// here it's testing which of the configured main branches have an upstream
75-
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "master@{u}"}, "refs/remotes/origin/master", nil). // this one does
76-
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "main@{u}"}, "", errors.New("error")). // this one doesn't, so it checks origin instead
77-
ExpectGitArgs([]string{"rev-parse", "--verify", "--quiet", "refs/remotes/origin/main"}, "", nil). // yep, origin/main exists
78-
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "develop@{u}"}, "", errors.New("error")). // this one doesn't, so it checks origin instead
108+
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "master@{u}"}, "refs/remotes/origin/master", nil). // this one does
109+
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "main@{u}"}, "", errors.New("error")). // this one doesn't, so it checks origin instead
110+
ExpectGitArgs([]string{"rev-parse", "--verify", "--quiet", "refs/remotes/origin/main"}, "", nil). // yep, origin/main exists
111+
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "develop@{u}"}, "", errors.New("error")). // this one doesn't, so it checks origin instead
79112
ExpectGitArgs([]string{"rev-parse", "--verify", "--quiet", "refs/remotes/origin/develop"}, "", errors.New("error")). // doesn't exist there, either, so it checks for a local branch
80-
ExpectGitArgs([]string{"rev-parse", "--verify", "--quiet", "refs/heads/develop"}, "", errors.New("error")). // no local branch either
113+
ExpectGitArgs([]string{"rev-parse", "--verify", "--quiet", "refs/heads/develop"}, "", errors.New("error")). // no local branch either
81114
// here it's seeing which of our commits are not on any of the main branches yet
82115
ExpectGitArgs([]string{"rev-list", "HEAD", "^refs/remotes/origin/master", "^refs/remotes/origin/main"},
83116
"0eea75e8c631fba6b58135697835d58ba4c18dbc\nb21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164\ne94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c\nd8084cd558925eb7c9c38afeed5725c21653ab90\n65f910ebd85283b5cce9bf67d03d3f1a9ea3813a\n", nil),

pkg/gui/context/local_commits_context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ func shouldShowGraph(c *ContextCommon) bool {
251251
return false
252252
}
253253

254+
if c.Modes().Filtering.GetHideMerges() {
255+
return false
256+
}
257+
254258
value := c.UserConfig().Git.Log.ShowGraph
255259

256260
switch value {

pkg/gui/controllers/filtering_menu_action.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ func (self *FilteringMenuAction) Call() error {
9191
Tooltip: tooltip,
9292
})
9393

94+
menuItems = append(menuItems, &types.MenuItem{
95+
Label: self.c.Tr.FilterHideMerges,
96+
Tooltip: self.c.Tr.FilterHideMergesTooltip,
97+
Widget: types.MakeMenuCheckBox(self.c.Modes().Filtering.GetHideMerges()),
98+
OnPress: func() error {
99+
currentValue := self.c.Modes().Filtering.GetHideMerges()
100+
self.c.Modes().Filtering.SetHideMerges(!currentValue)
101+
102+
self.c.Refresh(types.RefreshOptions{
103+
Scope: helpers.ScopesToRefreshWhenFilteringModeChanges(),
104+
Then: func() {
105+
self.c.Contexts().LocalCommits.SetSelection(0)
106+
self.c.Contexts().LocalCommits.HandleFocus(types.OnFocusOpts{})
107+
},
108+
})
109+
return nil
110+
},
111+
})
112+
94113
if self.c.Modes().Filtering.Active() {
95114
menuItems = append(menuItems, &types.MenuItem{
96115
Label: self.c.Tr.ExitFilterMode,

pkg/gui/controllers/helpers/refresh_helper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ func (self *RefreshHelper) refreshCommitsWithLimit() error {
330330
All: self.c.Contexts().LocalCommits.GetShowWholeGitGraph(),
331331
MainBranches: self.c.Model().MainBranches,
332332
HashPool: self.c.Model().HashPool,
333+
HideMerges: self.c.Modes().Filtering.GetHideMerges(),
333334
},
334335
)
335336
if err != nil {
@@ -367,6 +368,7 @@ func (self *RefreshHelper) refreshSubCommitsWithLimit() error {
367368
RefForPushedStatus: self.c.Contexts().SubCommits.GetRef(),
368369
MainBranches: self.c.Model().MainBranches,
369370
HashPool: self.c.Model().HashPool,
371+
HideMerges: self.c.Modes().Filtering.GetHideMerges(),
370372
},
371373
)
372374
if err != nil {

pkg/gui/controllers/helpers/sub_commits_helper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
4343
RefToShowDivergenceFrom: opts.RefToShowDivergenceFrom,
4444
MainBranches: self.c.Model().MainBranches,
4545
HashPool: self.c.Model().HashPool,
46+
HideMerges: self.c.Modes().Filtering.GetHideMerges(),
4647
},
4748
)
4849
if err != nil {

pkg/gui/modes/filtering/filtering.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ type Filtering struct {
44
path string // the filename that gets passed to git log
55
author string // the author that gets passed to git log
66
selectedCommitHash string // the commit that was selected before we entered filtering mode
7+
hideMerges bool // whether to hide merge commits
78
}
89

910
func New(path string, author string) Filtering {
10-
return Filtering{path: path, author: author}
11+
return Filtering{path: path, author: author, hideMerges: false}
1112
}
1213

1314
func (m *Filtering) Active() bool {
@@ -17,6 +18,7 @@ func (m *Filtering) Active() bool {
1718
func (m *Filtering) Reset() {
1819
m.path = ""
1920
m.author = ""
21+
m.hideMerges = false
2022
}
2123

2224
func (m *Filtering) SetPath(path string) {
@@ -42,3 +44,11 @@ func (m *Filtering) SetSelectedCommitHash(hash string) {
4244
func (m *Filtering) GetSelectedCommitHash() string {
4345
return m.selectedCommitHash
4446
}
47+
48+
func (m *Filtering) SetHideMerges(hideMerges bool) {
49+
m.hideMerges = hideMerges
50+
}
51+
52+
func (m *Filtering) GetHideMerges() bool {
53+
return m.hideMerges
54+
}

pkg/i18n/english.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@ type TranslationSet struct {
623623
ExitFilterMode string
624624
FilterPathOption string
625625
FilterAuthorOption string
626+
FilterHideMerges string
627+
FilterHideMergesTooltip string
626628
EnterFileName string
627629
EnterAuthor string
628630
FilteringMenuTitle string
@@ -1701,6 +1703,8 @@ func EnglishTranslationSet() *TranslationSet {
17011703
ExitFilterMode: "Stop filtering",
17021704
FilterPathOption: "Enter path to filter by",
17031705
FilterAuthorOption: "Enter author to filter by",
1706+
FilterHideMerges: "Hide merge commits",
1707+
FilterHideMergesTooltip: "Exclude merge commits from the list",
17041708
EnterFileName: "Enter path:",
17051709
EnterAuthor: "Enter author:",
17061710
FilteringMenuTitle: "Filtering",

pkg/i18n/translations/ja.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@
564564
"FilterBy": "フィルター条件",
565565
"ExitFilterMode": "フィルタリングを停止",
566566
"FilterPathOption": "フィルタリングするパスを入力",
567+
"FilterHideMerges": "マージコミットを非表示",
568+
"FilterHideMergesTooltip": "リストからマージコミットを除外",
567569
"FilterAuthorOption": "フィルタリングする作者を入力",
568570
"EnterFileName": "パスを入力:",
569571
"EnterAuthor": "作者を入力:",

pkg/i18n/translations/ko.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@
234234
"GotoBottom": "맨 아래로 스크롤 ",
235235
"ResetInParentheses": "(reset)",
236236
"OpenFilteringMenu": "View filter-by-path options",
237+
"FilterHideMerges": "병합 커밋 숨기기",
238+
"FilterHideMergesTooltip": "목록에서 병합 커밋 제외",
237239
"ExitFilterMode": "Stop filtering by path",
238240
"MustExitFilterModePrompt": "Command not available in filtered mode. Exit filtered mode?",
239241
"EnterRefName": "Ref 입력:",

0 commit comments

Comments
 (0)