From 7a286e47532a31ed6abcde3a45da4bad1653a42e Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 25 Oct 2023 17:01:31 +0200 Subject: 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. --- templates/repo/issue/view_content/pull.tmpl | 4 +- .../issue/view_content/pull_merge_instruction.tmpl | 46 +++++++++++++++++----- 2 files changed, 38 insertions(+), 12 deletions(-) (limited to 'templates') diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index a4f7ede74d..2fed5848d5 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 b1b52645e0..3dab44710e 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}}
-- cgit v1.2.3