]> source.dussan.org Git - gitea.git/commitdiff
Exclude default branch from pushed branch hint (#25795)
authorLunny Xiao <xiaolunwen@gmail.com>
Mon, 10 Jul 2023 11:18:55 +0000 (19:18 +0800)
committerGitHub <noreply@github.com>
Mon, 10 Jul 2023 11:18:55 +0000 (11:18 +0000)
When pushing to default branch, no pushing hint should be prompt.
Fix #25778

---------

Co-authored-by: Giteabot <teabot@gitea.io>
models/git/branch.go
routers/web/repo/view.go

index 97891f01ebb405069fdda6dc2f59b4475dc34bcf..d57b72719ce8080674bb4c8d6f39a1da78a20383 100644 (file)
@@ -382,7 +382,8 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str
 }
 
 // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created
-func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64) (BranchList, error) {
+// except the indicate branch
+func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64, excludeBranchName string) (BranchList, error) {
        branches := make(BranchList, 0, 2)
        subQuery := builder.Select("head_branch").From("pull_request").
                InnerJoin("issue", "issue.id = pull_request.issue_id").
@@ -392,6 +393,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64) (B
                })
        err := db.GetEngine(ctx).
                Where("pusher_id=? AND is_deleted=?", userID, false).
+               And("name <> ?", excludeBranchName).
                And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()).
                NotIn("name", subQuery).
                OrderBy("branch.updated_unix DESC").
index acea08d6297ec0765ff7b2e8ac3fb8f2745e9b0d..ece2ec5416a5ce4890556d0706f1f705b3f7fdaf 100644 (file)
@@ -982,7 +982,7 @@ func renderCode(ctx *context.Context) {
                        ctx.ServerError("GetBaseRepo", err)
                        return
                }
-               ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID)
+               ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, ctx.Repo.Repository.DefaultBranch)
                if err != nil {
                        ctx.ServerError("GetRecentlyPushedBranches", err)
                        return