Skip to content

Commit 7a286e4

Browse files
authored
Improve pull request command line instructions (#27778)
* Show checkout instructions also when there is no permission to push, for anyone who wants to locally test the changes. * First checkout the branch exactly as is, without immediately having to solve merge conflicts. Leave this to the merge step, since it's often convenient to test a change without worrying about this. * Use `git fetch -u`, so an existing local branch is updated when re-testing the same pull request. But not the more risky `git fetch -f` in to handle force pushes, as we don't want to accidentally overwrite important local changes. * Show different merge command depending on the chosen merge style, interactively updated.
1 parent 1eae2aa commit 7a286e4

File tree

4 files changed

+47
-18
lines changed

4 files changed

+47
-18
lines changed

options/locale/locale_en-US.ini

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ write = Write
110110
preview = Preview
111111
loading = Loading…
112112

113-
step1 = Step 1:
114-
step2 = Step 2:
115-
116113
error = Error
117114
error404 = The page you are trying to reach either <strong>does not exist</strong> or <strong>you are not authorized</strong> to view it.
118115
go_back = Go Back
@@ -1797,9 +1794,11 @@ pulls.outdated_with_base_branch = This branch is out-of-date with the base branc
17971794
pulls.close = Close Pull Request
17981795
pulls.closed_at = `closed this pull request <a id="%[1]s" href="#%[1]s">%[2]s</a>`
17991796
pulls.reopened_at = `reopened this pull request <a id="%[1]s" href="#%[1]s">%[2]s</a>`
1800-
pulls.merge_instruction_hint = `You can also view <a class="show-instruction">command line instructions</a>.`
1801-
pulls.merge_instruction_step1_desc = From your project repository, check out a new branch and test the changes.
1802-
pulls.merge_instruction_step2_desc = Merge the changes and update on Gitea.
1797+
pulls.cmd_instruction_hint = `View <a class="show-instruction">command line instructions</a>.`
1798+
pulls.cmd_instruction_checkout_title = Checkout
1799+
pulls.cmd_instruction_checkout_desc = From your project repository, check out a new branch and test the changes.
1800+
pulls.cmd_instruction_merge_title = Merge
1801+
pulls.cmd_instruction_merge_desc = Merge the changes and update on Gitea.
18031802
pulls.clear_merge_message = Clear merge message
18041803
pulls.clear_merge_message_hint = Clearing the merge message will only remove the commit message content and keep generated git trailers such as "Co-Authored-By …".
18051804

templates/repo/issue/view_content/pull.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@
372372
</div>
373373
{{end}}
374374

375-
{{if and .ShowMergeInstructions .Issue.PullRequest.HeadRepo (not .Issue.PullRequest.HasMerged) (not .Issue.IsClosed)}}
376-
{{template "repo/issue/view_content/pull_merge_instruction" .Issue.PullRequest}}
375+
{{if and .Issue.PullRequest.HeadRepo (not .Issue.PullRequest.HasMerged) (not .Issue.IsClosed)}}
376+
{{template "repo/issue/view_content/pull_merge_instruction" dict "PullRequest" .Issue.PullRequest "ShowMergeInstructions" .ShowMergeInstructions}}
377377
{{end}}
378378
</div>
379379
</div>
Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
11
<div class="divider"></div>
2-
<div class="instruct-toggle"> {{ctx.Locale.Tr "repo.pulls.merge_instruction_hint" | Safe}} </div>
2+
<div class="instruct-toggle"> {{ctx.Locale.Tr "repo.pulls.cmd_instruction_hint" | Safe}} </div>
33
<div class="instruct-content gt-mt-3 gt-hidden">
4-
<div><h3 class="gt-dib">{{ctx.Locale.Tr "step1"}}</h3> {{ctx.Locale.Tr "repo.pulls.merge_instruction_step1_desc"}}</div>
4+
<div><h3>{{ctx.Locale.Tr "repo.pulls.cmd_instruction_checkout_title"}}</h3>{{ctx.Locale.Tr "repo.pulls.cmd_instruction_checkout_desc"}}</div>
5+
{{$localBranch := .PullRequest.HeadBranch}}
6+
{{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}
7+
{{$localBranch = print .PullRequest.HeadRepo.OwnerName "-" .PullRequest.HeadBranch}}
8+
{{end}}
59
<div class="ui secondary segment">
6-
{{if eq .Flow 0}}
7-
<div>git checkout -b {{if ne .HeadRepo.ID .BaseRepo.ID}}{{.HeadRepo.OwnerName}}-{{end}}{{.HeadBranch}} {{.BaseBranch}}</div>
8-
<div>git pull {{if ne .HeadRepo.ID .BaseRepo.ID}}<gitea-origin-url data-url="{{.HeadRepo.Link}}"></gitea-origin-url>{{else}}origin{{end}} {{.HeadBranch}}</div>
10+
{{if eq .PullRequest.Flow 0}}
11+
<div>git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}<gitea-origin-url data-url="{{.PullRequest.HeadRepo.Link}}"></gitea-origin-url>{{else}}origin{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}</div>
12+
<div>git checkout {{$localBranch}}</div>
913
{{else}}
10-
<div>git fetch origin {{.GetGitRefName}}:{{.HeadBranch}}</div>
14+
<div>git fetch -u origin {{.GetGitRefName}}:{{$localBranch}}</div>
1115
{{end}}
1216
</div>
13-
<div><h3 class="gt-dib">{{ctx.Locale.Tr "step2"}}</h3> {{ctx.Locale.Tr "repo.pulls.merge_instruction_step2_desc"}}</div>
17+
{{if .ShowMergeInstructions}}
18+
<div><h3>{{ctx.Locale.Tr "repo.pulls.cmd_instruction_merge_title"}}</h3>{{ctx.Locale.Tr "repo.pulls.cmd_instruction_merge_desc"}}</div>
1419
<div class="ui secondary segment">
15-
<div>git checkout {{.BaseBranch}}</div>
16-
<div>git merge --no-ff {{if ne .HeadRepo.ID .BaseRepo.ID}}{{.HeadRepo.OwnerName}}-{{end}}{{.HeadBranch}}</div>
17-
<div>git push origin {{.BaseBranch}}</div>
20+
<div data-pull-merge-style="merge">
21+
<div>git checkout {{.PullRequest.BaseBranch}}</div>
22+
<div>git merge --no-ff {{$localBranch}}</div>
23+
</div>
24+
<div class="gt-hidden" data-pull-merge-style="rebase">
25+
<div>git checkout {{.PullRequest.BaseBranch}}</div>
26+
<div>git merge --ff-only {{$localBranch}}</div>
27+
</div>
28+
<div class="gt-hidden" data-pull-merge-style="rebase-merge">
29+
<div>git checkout {{$localBranch}}</div>
30+
<div>git rebase {{.PullRequest.BaseBranch}}</div>
31+
<div>git checkout {{.PullRequest.BaseBranch}}</div>
32+
<div>git merge --no-ff {{$localBranch}}</div>
33+
</div>
34+
<div class="gt-hidden" data-pull-merge-style="squash">
35+
<div>git checkout {{.PullRequest.BaseBranch}}</div>
36+
<div>git merge --squash {{$localBranch}}</div>
37+
</div>
38+
<div class="gt-hidden" data-pull-merge-style="manually-merged">
39+
<div>git checkout {{.PullRequest.BaseBranch}}</div>
40+
<div>git merge {{$localBranch}}</div>
41+
</div>
42+
<div>git push origin {{.PullRequest.BaseBranch}}</div>
1843
</div>
44+
{{end}}
1945
</div>

web_src/js/components/PullRequestMergeForm.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
22
import {SvgIcon} from '../svg.js';
3+
import {toggleElem} from '../utils/dom.js';
34
45
const {csrfToken, pageData} = window.config;
56
@@ -39,6 +40,9 @@ export default {
3940
watch: {
4041
mergeStyle(val) {
4142
this.mergeStyleDetail = this.mergeForm.mergeStyles.find((e) => e.name === val);
43+
for (const elem of document.querySelectorAll('[data-pull-merge-style]')) {
44+
toggleElem(elem, elem.getAttribute('data-pull-merge-style') === val);
45+
}
4246
}
4347
},
4448
created() {

0 commit comments

Comments
 (0)