Skip to content

Commit 33fa93a

Browse files
GiteaBotlunny
andauthored
Fix agit checkout command line hint & fix ShowMergeInstructions checking (#31219) (#31222)
Backport #31219 by @lunny Fix #31135 Before <img width="527" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/60c07b55-3db2-4a9a-98f1-0eb72d149df2"> After <img width="664" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/0670ff5d-9e0b-47ac-aba4-9db9131de3b3"> Co-authored-by: Lunny Xiao <[email protected]>
1 parent 68e405c commit 33fa93a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

routers/web/repo/issue.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,7 @@ func ViewIssue(ctx *context.Context) {
17911791
pull.Issue = issue
17921792
canDelete := false
17931793
allowMerge := false
1794+
canWriteToHeadRepo := false
17941795

17951796
if ctx.IsSigned {
17961797
if err := pull.LoadHeadRepo(ctx); err != nil {
@@ -1811,7 +1812,7 @@ func ViewIssue(ctx *context.Context) {
18111812
ctx.Data["DeleteBranchLink"] = issue.Link() + "/cleanup"
18121813
}
18131814
}
1814-
ctx.Data["CanWriteToHeadRepo"] = true
1815+
canWriteToHeadRepo = true
18151816
}
18161817
}
18171818

@@ -1823,6 +1824,9 @@ func ViewIssue(ctx *context.Context) {
18231824
ctx.ServerError("GetUserRepoPermission", err)
18241825
return
18251826
}
1827+
if !canWriteToHeadRepo { // maintainers maybe allowed to push to head repo even if they can't write to it
1828+
canWriteToHeadRepo = pull.AllowMaintainerEdit && perm.CanWrite(unit.TypeCode)
1829+
}
18261830
allowMerge, err = pull_service.IsUserAllowedToMerge(ctx, pull, perm, ctx.Doer)
18271831
if err != nil {
18281832
ctx.ServerError("IsUserAllowedToMerge", err)
@@ -1835,6 +1839,8 @@ func ViewIssue(ctx *context.Context) {
18351839
}
18361840
}
18371841

1842+
ctx.Data["CanWriteToHeadRepo"] = canWriteToHeadRepo
1843+
ctx.Data["ShowMergeInstructions"] = canWriteToHeadRepo
18381844
ctx.Data["AllowMerge"] = allowMerge
18391845

18401846
prUnit, err := repo.GetUnit(ctx, unit.TypePullRequests)
@@ -1889,13 +1895,9 @@ func ViewIssue(ctx *context.Context) {
18891895
ctx.ServerError("LoadProtectedBranch", err)
18901896
return
18911897
}
1892-
ctx.Data["ShowMergeInstructions"] = true
1898+
18931899
if pb != nil {
18941900
pb.Repo = pull.BaseRepo
1895-
var showMergeInstructions bool
1896-
if ctx.Doer != nil {
1897-
showMergeInstructions = pb.CanUserPush(ctx, ctx.Doer)
1898-
}
18991901
ctx.Data["ProtectedBranch"] = pb
19001902
ctx.Data["IsBlockedByApprovals"] = !issues_model.HasEnoughApprovals(ctx, pb, pull)
19011903
ctx.Data["IsBlockedByRejection"] = issues_model.MergeBlockedByRejectedReview(ctx, pb, pull)
@@ -1906,7 +1908,6 @@ func ViewIssue(ctx *context.Context) {
19061908
ctx.Data["ChangedProtectedFiles"] = pull.ChangedProtectedFiles
19071909
ctx.Data["IsBlockedByChangedProtectedFiles"] = len(pull.ChangedProtectedFiles) != 0
19081910
ctx.Data["ChangedProtectedFilesNum"] = len(pull.ChangedProtectedFiles)
1909-
ctx.Data["ShowMergeInstructions"] = showMergeInstructions
19101911
}
19111912
ctx.Data["WillSign"] = false
19121913
if ctx.Doer != nil {

templates/repo/issue/view_content/pull_merge_instruction.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<div class="ui secondary segment">
1010
{{if eq .PullRequest.Flow 0}}
1111
<div>git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}<origin-url data-url="{{.PullRequest.HeadRepo.Link}}"></origin-url>{{else}}origin{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}</div>
12-
<div>git checkout {{$localBranch}}</div>
1312
{{else}}
14-
<div>git fetch -u origin {{.GetGitRefName}}:{{$localBranch}}</div>
13+
<div>git fetch -u origin {{.PullRequest.GetGitRefName}}:{{$localBranch}}</div>
1514
{{end}}
15+
<div>git checkout {{$localBranch}}</div>
1616
</div>
1717
{{if .ShowMergeInstructions}}
1818
<div><h3>{{ctx.Locale.Tr "repo.pulls.cmd_instruction_merge_title"}}</h3>{{ctx.Locale.Tr "repo.pulls.cmd_instruction_merge_desc"}}</div>

0 commit comments

Comments
 (0)