Hide closed pull requests on main branches (#5501)

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.
This commit is contained in:
Stefan Haller
2026-04-13 21:59:03 +02:00
committed by GitHub
2 changed files with 14 additions and 2 deletions
+3 -1
View File
@@ -11,6 +11,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
@@ -205,7 +206,8 @@ func (self *BranchesController) GetOnRenderToMain() func() {
ptyTask := types.NewRunPtyTask(cmdObj.GetCmd())
task = ptyTask
if pr, ok := self.c.Model().PullRequestsMap[branch.Name]; ok {
pr, ok := self.c.Model().PullRequestsMap[branch.Name]
if ok && presentation.ShouldShowPrForBranch(pr, branch.Name, self.c.UserConfig()) {
icon := lo.Ternary(icons.IsIconEnabled(), icons.IconForRemoteUrl(pr.Url)+" ", "")
ptyTask.Prefix = style.PrintHyperlink(fmt.Sprintf("%s%s %s %s\n",
icon,
+11 -1
View File
@@ -141,7 +141,7 @@ func getBranchDisplayStrings(
var coloredPrIcon string
pr, hasPr := prs[b.Name]
if hasPr {
if hasPr && ShouldShowPrForBranch(pr, b.Name, userConfig) {
var prIcon string
if icons.IsIconEnabled() {
prIcon = icons.IconForRemoteUrl(pr.Url)
@@ -285,3 +285,13 @@ func prColor(state string) style.TextStyle {
return style.FgDefault
}
}
func ShouldShowPrForBranch(pr *models.GithubPullRequest, branchName string, userConfig *config.UserConfig) bool {
if !lo.Contains(userConfig.Git.MainBranches, branchName) {
return true
}
// For main branches we only want to show the PR if it's open (or draft), on the assumption that a
// closed PR for a main branch is always a mistake.
return pr.State != "CLOSED" && pr.State != "MERGED"
}