mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-10-18 08:08:31 +00:00
[GITEA] Don't consider orphan branches as recently pushed
When displaying the recently pushed branches banner, don't display
branches that have no common history with the default branch. These
branches are usually not meant to be merged, so the banner is just noise
in this case.
Refs: https://codeberg.org/forgejo/forgejo/pulls/2196
Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
(cherry picked from commit e1fba517f4
)
This commit is contained in:
parent
b4509aa4c7
commit
2d3c81d4f2
2 changed files with 95 additions and 1 deletions
|
@ -1053,7 +1053,43 @@ func renderCode(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.Data["RecentlyPushedNewBranches"] = branches
|
||||
// Filter out branches that have no relation to the default branch of
|
||||
// the repository.
|
||||
var filteredBranches []*git_model.Branch
|
||||
for _, branch := range branches {
|
||||
repo, err := branch.GetRepo(ctx)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
head, err := gitRepo.GetCommit(branch.CommitID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
defaultBranch, err := gitRepo.GetDefaultBranch()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
defaultBranchHead, err := gitRepo.GetCommit(defaultBranch)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
hasMergeBase, err := head.HasPreviousCommit(defaultBranchHead.ID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if hasMergeBase {
|
||||
filteredBranches = append(filteredBranches, branch)
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["RecentlyPushedNewBranches"] = filteredBranches
|
||||
}
|
||||
|
||||
PostRecentBranchCheck:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue