From 7a286e47532a31ed6abcde3a45da4bad1653a42e Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 25 Oct 2023 17:01:31 +0200 Subject: [PATCH] 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. --- options/locale/locale_en-US.ini | 11 ++--- templates/repo/issue/view_content/pull.tmpl | 4 +- .../view_content/pull_merge_instruction.tmpl | 46 +++++++++++++++---- .../js/components/PullRequestMergeForm.vue | 4 ++ 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index e3f2fcdd839b..8dcce73b7d84 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -110,9 +110,6 @@ write = Write preview = Preview loading = Loading… -step1 = Step 1: -step2 = Step 2: - error = Error error404 = The page you are trying to reach either does not exist or you are not authorized to view it. go_back = Go Back @@ -1797,9 +1794,11 @@ pulls.outdated_with_base_branch = This branch is out-of-date with the base branc pulls.close = Close Pull Request pulls.closed_at = `closed this pull request %[2]s` pulls.reopened_at = `reopened this pull request %[2]s` -pulls.merge_instruction_hint = `You can also view command line instructions.` -pulls.merge_instruction_step1_desc = From your project repository, check out a new branch and test the changes. -pulls.merge_instruction_step2_desc = Merge the changes and update on Gitea. +pulls.cmd_instruction_hint = `View command line instructions.` +pulls.cmd_instruction_checkout_title = Checkout +pulls.cmd_instruction_checkout_desc = From your project repository, check out a new branch and test the changes. +pulls.cmd_instruction_merge_title = Merge +pulls.cmd_instruction_merge_desc = Merge the changes and update on Gitea. pulls.clear_merge_message = Clear merge message 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 …". diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index a4f7ede74d06..2fed5848d5b1 100644 --- a/templates/repo/issue/view_content/pull.tmpl +++ b/templates/repo/issue/view_content/pull.tmpl @@ -372,8 +372,8 @@ {{end}} - {{if and .ShowMergeInstructions .Issue.PullRequest.HeadRepo (not .Issue.PullRequest.HasMerged) (not .Issue.IsClosed)}} - {{template "repo/issue/view_content/pull_merge_instruction" .Issue.PullRequest}} + {{if and .Issue.PullRequest.HeadRepo (not .Issue.PullRequest.HasMerged) (not .Issue.IsClosed)}} + {{template "repo/issue/view_content/pull_merge_instruction" dict "PullRequest" .Issue.PullRequest "ShowMergeInstructions" .ShowMergeInstructions}} {{end}} diff --git a/templates/repo/issue/view_content/pull_merge_instruction.tmpl b/templates/repo/issue/view_content/pull_merge_instruction.tmpl index b1b52645e056..3dab44710eaf 100644 --- a/templates/repo/issue/view_content/pull_merge_instruction.tmpl +++ b/templates/repo/issue/view_content/pull_merge_instruction.tmpl @@ -1,19 +1,45 @@
-
{{ctx.Locale.Tr "repo.pulls.merge_instruction_hint" | Safe}}
+
{{ctx.Locale.Tr "repo.pulls.cmd_instruction_hint" | Safe}}
-

{{ctx.Locale.Tr "step1"}}

{{ctx.Locale.Tr "repo.pulls.merge_instruction_step1_desc"}}
+

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

{{ctx.Locale.Tr "repo.pulls.cmd_instruction_checkout_desc"}}
+ {{$localBranch := .PullRequest.HeadBranch}} + {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}} + {{$localBranch = print .PullRequest.HeadRepo.OwnerName "-" .PullRequest.HeadBranch}} + {{end}}
- {{if eq .Flow 0}} -
git checkout -b {{if ne .HeadRepo.ID .BaseRepo.ID}}{{.HeadRepo.OwnerName}}-{{end}}{{.HeadBranch}} {{.BaseBranch}}
-
git pull {{if ne .HeadRepo.ID .BaseRepo.ID}}{{else}}origin{{end}} {{.HeadBranch}}
+ {{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 origin {{.GetGitRefName}}:{{.HeadBranch}}
+
git fetch -u origin {{.GetGitRefName}}:{{$localBranch}}
{{end}}
-

{{ctx.Locale.Tr "step2"}}

{{ctx.Locale.Tr "repo.pulls.merge_instruction_step2_desc"}}
+ {{if .ShowMergeInstructions}} +

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

{{ctx.Locale.Tr "repo.pulls.cmd_instruction_merge_desc"}}
-
git checkout {{.BaseBranch}}
-
git merge --no-ff {{if ne .HeadRepo.ID .BaseRepo.ID}}{{.HeadRepo.OwnerName}}-{{end}}{{.HeadBranch}}
-
git push origin {{.BaseBranch}}
+
+
git checkout {{.PullRequest.BaseBranch}}
+
git merge --no-ff {{$localBranch}}
+
+
+
git checkout {{.PullRequest.BaseBranch}}
+
git merge --ff-only {{$localBranch}}
+
+
+
git checkout {{$localBranch}}
+
git rebase {{.PullRequest.BaseBranch}}
+
git checkout {{.PullRequest.BaseBranch}}
+
git merge --no-ff {{$localBranch}}
+
+
+
git checkout {{.PullRequest.BaseBranch}}
+
git merge --squash {{$localBranch}}
+
+
+
git checkout {{.PullRequest.BaseBranch}}
+
git merge {{$localBranch}}
+
+
git push origin {{.PullRequest.BaseBranch}}
+ {{end}}
diff --git a/web_src/js/components/PullRequestMergeForm.vue b/web_src/js/components/PullRequestMergeForm.vue index 03d1f99683b2..54dcf9d86065 100644 --- a/web_src/js/components/PullRequestMergeForm.vue +++ b/web_src/js/components/PullRequestMergeForm.vue @@ -1,5 +1,6 @@