Skip to content

Commit 2f31d2d

Browse files
lunnyGiteaBot
andauthored
Exclude default branch from pushed branch hint (#25795)
When pushing to default branch, no pushing hint should be prompt. Fix #25778 --------- Co-authored-by: Giteabot <[email protected]>
1 parent 0fd1672 commit 2f31d2d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

models/git/branch.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str
382382
}
383383

384384
// FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created
385-
func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64) (BranchList, error) {
385+
// except the indicate branch
386+
func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64, excludeBranchName string) (BranchList, error) {
386387
branches := make(BranchList, 0, 2)
387388
subQuery := builder.Select("head_branch").From("pull_request").
388389
InnerJoin("issue", "issue.id = pull_request.issue_id").
@@ -392,6 +393,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64) (B
392393
})
393394
err := db.GetEngine(ctx).
394395
Where("pusher_id=? AND is_deleted=?", userID, false).
396+
And("name <> ?", excludeBranchName).
395397
And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()).
396398
NotIn("name", subQuery).
397399
OrderBy("branch.updated_unix DESC").

routers/web/repo/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ func renderCode(ctx *context.Context) {
982982
ctx.ServerError("GetBaseRepo", err)
983983
return
984984
}
985-
ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID)
985+
ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, ctx.Repo.Repository.DefaultBranch)
986986
if err != nil {
987987
ctx.ServerError("GetRecentlyPushedBranches", err)
988988
return

0 commit comments

Comments
 (0)