From 33fa93a952d67006b4f1c85cccefad25a657c124 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Mon, 3 Jun 2024 09:45:57 +0800 Subject: [PATCH] Fix agit checkout command line hint & fix ShowMergeInstructions checking (#31219) (#31222) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport #31219 by @lunny Fix #31135 Before 图片 After 图片 Co-authored-by: Lunny Xiao --- routers/web/repo/issue.go | 15 ++++++++------- .../view_content/pull_merge_instruction.tmpl | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 0c8363a168..6cfc22566a 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1791,6 +1791,7 @@ func ViewIssue(ctx *context.Context) { pull.Issue = issue canDelete := false allowMerge := false + canWriteToHeadRepo := false if ctx.IsSigned { if err := pull.LoadHeadRepo(ctx); err != nil { @@ -1811,7 +1812,7 @@ func ViewIssue(ctx *context.Context) { ctx.Data["DeleteBranchLink"] = issue.Link() + "/cleanup" } } - ctx.Data["CanWriteToHeadRepo"] = true + canWriteToHeadRepo = true } } @@ -1823,6 +1824,9 @@ func ViewIssue(ctx *context.Context) { ctx.ServerError("GetUserRepoPermission", err) return } + if !canWriteToHeadRepo { // maintainers maybe allowed to push to head repo even if they can't write to it + canWriteToHeadRepo = pull.AllowMaintainerEdit && perm.CanWrite(unit.TypeCode) + } allowMerge, err = pull_service.IsUserAllowedToMerge(ctx, pull, perm, ctx.Doer) if err != nil { ctx.ServerError("IsUserAllowedToMerge", err) @@ -1835,6 +1839,8 @@ func ViewIssue(ctx *context.Context) { } } + ctx.Data["CanWriteToHeadRepo"] = canWriteToHeadRepo + ctx.Data["ShowMergeInstructions"] = canWriteToHeadRepo ctx.Data["AllowMerge"] = allowMerge prUnit, err := repo.GetUnit(ctx, unit.TypePullRequests) @@ -1889,13 +1895,9 @@ func ViewIssue(ctx *context.Context) { ctx.ServerError("LoadProtectedBranch", err) return } - ctx.Data["ShowMergeInstructions"] = true + if pb != nil { pb.Repo = pull.BaseRepo - var showMergeInstructions bool - if ctx.Doer != nil { - showMergeInstructions = pb.CanUserPush(ctx, ctx.Doer) - } ctx.Data["ProtectedBranch"] = pb ctx.Data["IsBlockedByApprovals"] = !issues_model.HasEnoughApprovals(ctx, pb, pull) ctx.Data["IsBlockedByRejection"] = issues_model.MergeBlockedByRejectedReview(ctx, pb, pull) @@ -1906,7 +1908,6 @@ func ViewIssue(ctx *context.Context) { ctx.Data["ChangedProtectedFiles"] = pull.ChangedProtectedFiles ctx.Data["IsBlockedByChangedProtectedFiles"] = len(pull.ChangedProtectedFiles) != 0 ctx.Data["ChangedProtectedFilesNum"] = len(pull.ChangedProtectedFiles) - ctx.Data["ShowMergeInstructions"] = showMergeInstructions } ctx.Data["WillSign"] = false if ctx.Doer != nil { diff --git a/templates/repo/issue/view_content/pull_merge_instruction.tmpl b/templates/repo/issue/view_content/pull_merge_instruction.tmpl index d585d36574..bb59b49719 100644 --- a/templates/repo/issue/view_content/pull_merge_instruction.tmpl +++ b/templates/repo/issue/view_content/pull_merge_instruction.tmpl @@ -9,10 +9,10 @@
{{if eq .PullRequest.Flow 0}}
git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}{{else}}origin{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}
-
git checkout {{$localBranch}}
{{else}} -
git fetch -u origin {{.GetGitRefName}}:{{$localBranch}}
+
git fetch -u origin {{.PullRequest.GetGitRefName}}:{{$localBranch}}
{{end}} +
git checkout {{$localBranch}}
{{if .ShowMergeInstructions}}

{{ctx.Locale.Tr "repo.pulls.cmd_instruction_merge_title"}}

{{ctx.Locale.Tr "repo.pulls.cmd_instruction_merge_desc"}}