Skip to content

Commit 2788a7c

Browse files
authored
Fix agit checkout command line hint & fix ShowMergeInstructions checking (#31219)
1 parent 98a6104 commit 2788a7c

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
@@ -1794,6 +1794,7 @@ func ViewIssue(ctx *context.Context) {
17941794
pull.Issue = issue
17951795
canDelete := false
17961796
allowMerge := false
1797+
canWriteToHeadRepo := false
17971798

17981799
if ctx.IsSigned {
17991800
if err := pull.LoadHeadRepo(ctx); err != nil {
@@ -1814,7 +1815,7 @@ func ViewIssue(ctx *context.Context) {
18141815
ctx.Data["DeleteBranchLink"] = issue.Link() + "/cleanup"
18151816
}
18161817
}
1817-
ctx.Data["CanWriteToHeadRepo"] = true
1818+
canWriteToHeadRepo = true
18181819
}
18191820
}
18201821

@@ -1826,6 +1827,9 @@ func ViewIssue(ctx *context.Context) {
18261827
ctx.ServerError("GetUserRepoPermission", err)
18271828
return
18281829
}
1830+
if !canWriteToHeadRepo { // maintainers maybe allowed to push to head repo even if they can't write to it
1831+
canWriteToHeadRepo = pull.AllowMaintainerEdit && perm.CanWrite(unit.TypeCode)
1832+
}
18291833
allowMerge, err = pull_service.IsUserAllowedToMerge(ctx, pull, perm, ctx.Doer)
18301834
if err != nil {
18311835
ctx.ServerError("IsUserAllowedToMerge", err)
@@ -1838,6 +1842,8 @@ func ViewIssue(ctx *context.Context) {
18381842
}
18391843
}
18401844

1845+
ctx.Data["CanWriteToHeadRepo"] = canWriteToHeadRepo
1846+
ctx.Data["ShowMergeInstructions"] = canWriteToHeadRepo
18411847
ctx.Data["AllowMerge"] = allowMerge
18421848

18431849
prUnit, err := repo.GetUnit(ctx, unit.TypePullRequests)
@@ -1892,13 +1898,9 @@ func ViewIssue(ctx *context.Context) {
18921898
ctx.ServerError("LoadProtectedBranch", err)
18931899
return
18941900
}
1895-
ctx.Data["ShowMergeInstructions"] = true
1901+
18961902
if pb != nil {
18971903
pb.Repo = pull.BaseRepo
1898-
var showMergeInstructions bool
1899-
if ctx.Doer != nil {
1900-
showMergeInstructions = pb.CanUserPush(ctx, ctx.Doer)
1901-
}
19021904
ctx.Data["ProtectedBranch"] = pb
19031905
ctx.Data["IsBlockedByApprovals"] = !issues_model.HasEnoughApprovals(ctx, pb, pull)
19041906
ctx.Data["IsBlockedByRejection"] = issues_model.MergeBlockedByRejectedReview(ctx, pb, pull)
@@ -1909,7 +1911,6 @@ func ViewIssue(ctx *context.Context) {
19091911
ctx.Data["ChangedProtectedFiles"] = pull.ChangedProtectedFiles
19101912
ctx.Data["IsBlockedByChangedProtectedFiles"] = len(pull.ChangedProtectedFiles) != 0
19111913
ctx.Data["ChangedProtectedFilesNum"] = len(pull.ChangedProtectedFiles)
1912-
ctx.Data["ShowMergeInstructions"] = showMergeInstructions
19131914
}
19141915
ctx.Data["WillSign"] = false
19151916
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)