Skip to content

Commit b693611

Browse files
authored
Don't show new pr button when page is not compare pull (#26431)
Before: ![image](https://github.com/go-gitea/gitea/assets/18380374/ba69252f-3582-414a-9d62-b2b78d7035dd) After: ![image](https://github.com/go-gitea/gitea/assets/18380374/71b8587c-b96e-48fb-b3e5-1a2a8b5d06fa) (TestOrg:test is a tag not branch) Problem: In the template, we will not add `compare pull` class when `PageIsComparePull` is false. https://github.com/go-gitea/gitea/blob/a370efc13f0e1ea309e324639832832bc14cb6dc/templates/repo/diff/compare.tmpl#L2 But in the js, we are using `.repository.compare.pull` to find the button: https://github.com/go-gitea/gitea/blob/a370efc13f0e1ea309e324639832832bc14cb6dc/web_src/js/features/repo-legacy.js#L552-L563 So, if `PageIsComparePull` is false, the `New Pull Request` button will be there, but has no response when we click it.
1 parent 5d09023 commit b693611

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,7 @@ pulls.select_commit_hold_shift_for_range = Select commit. Hold shift + click to
17141714
pulls.review_only_possible_for_full_diff = Review is only possible when viewing the full diff
17151715
pulls.filter_changes_by_commit = Filter by commit
17161716
pulls.nothing_to_compare = These branches are equal. There is no need to create a pull request.
1717+
pulls.nothing_to_compare_have_tag = The selected branch/tag are equal.
17171718
pulls.nothing_to_compare_and_allow_empty_pr = These branches are equal. This PR will be empty.
17181719
pulls.has_pull_request = `A pull request between these branches already exists: <a href="%[1]s">%[2]s#%[3]d</a>`
17191720
pulls.create = Create Pull Request

templates/repo/diff/compare.tmpl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,18 @@
177177
</div>
178178

179179
{{if .IsNothingToCompare}}
180-
{{if and $.IsSigned $.AllowEmptyPr (not .Repository.IsArchived)}}
180+
{{if and $.IsSigned $.AllowEmptyPr (not .Repository.IsArchived) .PageIsComparePull}}
181181
<div class="ui segment">{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_and_allow_empty_pr"}}</div>
182182
<div class="ui info message show-form-container {{if .Flash}}gt-hidden{{end}}">
183183
<button class="ui button primary show-form">{{ctx.Locale.Tr "repo.pulls.new"}}</button>
184184
</div>
185185
<div class="pullrequest-form {{if not .Flash}}gt-hidden{{end}}">
186186
{{template "repo/issue/new_form" .}}
187187
</div>
188-
{{else}}
188+
{{else if and .HeadIsBranch .BaseIsBranch}}
189189
<div class="ui segment">{{ctx.Locale.Tr "repo.pulls.nothing_to_compare"}}</div>
190+
{{else}}
191+
<div class="ui segment">{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_have_tag"}}</div>
190192
{{end}}
191193
{{else if and .PageIsComparePull (gt .CommitCount 0)}}
192194
{{if .HasPullRequest}}
@@ -229,7 +231,7 @@
229231
{{end}}
230232
{{$showDiffBox = true}}
231233
{{end}}
232-
{{else}}
234+
{{else if not .IsNothingToCompare}}
233235
{{$showDiffBox = true}}
234236
{{end}}
235237
</div>

0 commit comments

Comments
 (0)