Skip to content

Commit 874375f

Browse files
committed
💅 pr checkout --force
1 parent a89fa1e commit 874375f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pkg/cmd/pr/checkout/checkout.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ func NewCmdCheckout(f *cmdutil.Factory, runF func(*CheckoutOptions) error) *cobr
6161
},
6262
}
6363

64-
cmd.Flags().BoolVarP(&opts.RecurseSubmodules, "recurse-submodules", "", false, "Update all active submodules (recursively)")
65-
cmd.Flags().BoolVarP(&opts.Force, "force", "f", false, "Force merge into local branch")
64+
cmd.Flags().BoolVarP(&opts.RecurseSubmodules, "recurse-submodules", "", false, "Update all submodules after checkout")
65+
cmd.Flags().BoolVarP(&opts.Force, "force", "f", false, "Reset the existing local branch to the latest state of the pull request")
6666

6767
return cmd
6868
}
@@ -118,10 +118,10 @@ func checkoutRun(opts *CheckoutOptions) error {
118118
// local branch already exists
119119
if _, err := git.ShowRefs("refs/heads/" + newBranchName); err == nil {
120120
cmdQueue = append(cmdQueue, []string{"git", "checkout", newBranchName})
121-
// If forced reset to remote
122121
if opts.Force {
123122
cmdQueue = append(cmdQueue, []string{"git", "reset", "--hard", fmt.Sprintf("refs/remotes/%s", remoteBranch)})
124123
} else {
124+
// TODO: check if non-fast-forward and suggest to use `--force`
125125
cmdQueue = append(cmdQueue, []string{"git", "merge", "--ff-only", fmt.Sprintf("refs/remotes/%s", remoteBranch)})
126126
}
127127
} else {
@@ -149,19 +149,19 @@ func checkoutRun(opts *CheckoutOptions) error {
149149

150150
cmdQueue = append(cmdQueue, []string{"git", "fetch", baseURLOrName, ref})
151151

152-
// If forced reset to remote
153152
if opts.Force {
154153
cmdQueue = append(cmdQueue, []string{"git", "reset", "--hard", "FETCH_HEAD"})
155154
} else {
155+
// TODO: check if non-fast-forward and suggest to use `--force`
156156
cmdQueue = append(cmdQueue, []string{"git", "merge", "--ff-only", "FETCH_HEAD"})
157157
}
158158
} else {
159159
// create a new branch
160160

161-
// If forced reset to remote
162161
if opts.Force {
163162
cmdQueue = append(cmdQueue, []string{"git", "fetch", baseURLOrName, fmt.Sprintf("%s:%s", ref, newBranchName), "--force"})
164163
} else {
164+
// TODO: check if non-fast-forward and suggest to use `--force`
165165
cmdQueue = append(cmdQueue, []string{"git", "fetch", baseURLOrName, fmt.Sprintf("%s:%s", ref, newBranchName)})
166166
}
167167
cmdQueue = append(cmdQueue, []string{"git", "checkout", newBranchName})

0 commit comments

Comments
 (0)