Skip to content

Commit 1f4cbad

Browse files
committed
Hide closed pull requests on main branches
The assumption is that if a pull request exists on a main branch, it was usually created by mistake and then closed, and showing it serves no purpose and is only distracting. We keep showing open pull requests for main branches though, because this allows you to notice that there is one that you probably want to close. This only affects the display (in the branches list and in the main view); opening the PR in the browser using shift-G is still possible, as is copying its URL to the clipboard.
1 parent 38dd035 commit 1f4cbad

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pkg/gui/controllers/branches_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/jesseduffield/lazygit/pkg/commands/models"
1212
"github.com/jesseduffield/lazygit/pkg/gui/context"
1313
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
14+
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
1415
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
1516
"github.com/jesseduffield/lazygit/pkg/gui/style"
1617
"github.com/jesseduffield/lazygit/pkg/gui/types"
@@ -205,7 +206,8 @@ func (self *BranchesController) GetOnRenderToMain() func() {
205206
ptyTask := types.NewRunPtyTask(cmdObj.GetCmd())
206207
task = ptyTask
207208

208-
if pr, ok := self.c.Model().PullRequestsMap[branch.Name]; ok {
209+
pr, ok := self.c.Model().PullRequestsMap[branch.Name]
210+
if ok && presentation.ShouldShowPrForBranch(pr, branch.Name, self.c.UserConfig()) {
209211
icon := lo.Ternary(icons.IsIconEnabled(), icons.IconForRemoteUrl(pr.Url)+" ", "")
210212
ptyTask.Prefix = style.PrintHyperlink(fmt.Sprintf("%s%s %s %s\n",
211213
icon,

pkg/gui/presentation/branches.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func getBranchDisplayStrings(
141141

142142
var coloredPrIcon string
143143
pr, hasPr := prs[b.Name]
144-
if hasPr {
144+
if hasPr && ShouldShowPrForBranch(pr, b.Name, userConfig) {
145145
var prIcon string
146146
if icons.IsIconEnabled() {
147147
prIcon = icons.IconForRemoteUrl(pr.Url)
@@ -285,3 +285,13 @@ func prColor(state string) style.TextStyle {
285285
return style.FgDefault
286286
}
287287
}
288+
289+
func ShouldShowPrForBranch(pr *models.GithubPullRequest, branchName string, userConfig *config.UserConfig) bool {
290+
if !lo.Contains(userConfig.Git.MainBranches, branchName) {
291+
return true
292+
}
293+
294+
// For main branches we only want to show the PR if it's open (or draft), on the assumption that a
295+
// closed PR for a main branch is always a mistake.
296+
return pr.State != "CLOSED" && pr.State != "MERGED"
297+
}

0 commit comments

Comments
 (0)