From 874375f01e1fdf48da484f2f5bb923e4afd5281f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 22 Jan 2021 22:29:14 +0100 Subject: [PATCH] :nail_care: `pr checkout --force` --- pkg/cmd/pr/checkout/checkout.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/pr/checkout/checkout.go b/pkg/cmd/pr/checkout/checkout.go index fc5002b0f..1b939e724 100644 --- a/pkg/cmd/pr/checkout/checkout.go +++ b/pkg/cmd/pr/checkout/checkout.go @@ -61,8 +61,8 @@ func NewCmdCheckout(f *cmdutil.Factory, runF func(*CheckoutOptions) error) *cobr }, } - cmd.Flags().BoolVarP(&opts.RecurseSubmodules, "recurse-submodules", "", false, "Update all active submodules (recursively)") - cmd.Flags().BoolVarP(&opts.Force, "force", "f", false, "Force merge into local branch") + cmd.Flags().BoolVarP(&opts.RecurseSubmodules, "recurse-submodules", "", false, "Update all submodules after checkout") + cmd.Flags().BoolVarP(&opts.Force, "force", "f", false, "Reset the existing local branch to the latest state of the pull request") return cmd } @@ -118,10 +118,10 @@ func checkoutRun(opts *CheckoutOptions) error { // local branch already exists if _, err := git.ShowRefs("refs/heads/" + newBranchName); err == nil { cmdQueue = append(cmdQueue, []string{"git", "checkout", newBranchName}) - // If forced reset to remote if opts.Force { cmdQueue = append(cmdQueue, []string{"git", "reset", "--hard", fmt.Sprintf("refs/remotes/%s", remoteBranch)}) } else { + // TODO: check if non-fast-forward and suggest to use `--force` cmdQueue = append(cmdQueue, []string{"git", "merge", "--ff-only", fmt.Sprintf("refs/remotes/%s", remoteBranch)}) } } else { @@ -149,19 +149,19 @@ func checkoutRun(opts *CheckoutOptions) error { cmdQueue = append(cmdQueue, []string{"git", "fetch", baseURLOrName, ref}) - // If forced reset to remote if opts.Force { cmdQueue = append(cmdQueue, []string{"git", "reset", "--hard", "FETCH_HEAD"}) } else { + // TODO: check if non-fast-forward and suggest to use `--force` cmdQueue = append(cmdQueue, []string{"git", "merge", "--ff-only", "FETCH_HEAD"}) } } else { // create a new branch - // If forced reset to remote if opts.Force { cmdQueue = append(cmdQueue, []string{"git", "fetch", baseURLOrName, fmt.Sprintf("%s:%s", ref, newBranchName), "--force"}) } else { + // TODO: check if non-fast-forward and suggest to use `--force` cmdQueue = append(cmdQueue, []string{"git", "fetch", baseURLOrName, fmt.Sprintf("%s:%s", ref, newBranchName)}) } cmdQueue = append(cmdQueue, []string{"git", "checkout", newBranchName})