(remote *cliContext.Remote, pr *api.PullRequest, opts *CheckoutOptions, reuseWorktree bool)
| 197 | } |
| 198 | |
| 199 | func cmdsForExistingRemote(remote *cliContext.Remote, pr *api.PullRequest, opts *CheckoutOptions, reuseWorktree bool) [][]string { |
| 200 | var cmds [][]string |
| 201 | remoteBranch := fmt.Sprintf("%s/%s", remote.Name, pr.HeadRefName) |
| 202 | |
| 203 | refSpec := fmt.Sprintf("+refs/heads/%s", pr.HeadRefName) |
| 204 | if !opts.Detach { |
| 205 | refSpec += fmt.Sprintf(":refs/remotes/%s", remoteBranch) |
| 206 | } |
| 207 | |
| 208 | localBranch := pr.HeadRefName |
| 209 | if opts.BranchName != "" { |
| 210 | localBranch = opts.BranchName |
| 211 | } |
| 212 | |
| 213 | remoteBranchRef := fmt.Sprintf("refs/remotes/%s", remoteBranch) |
| 214 | fetchCmd := []string{"fetch", remote.Name, refSpec, "--no-tags"} |
| 215 | |
| 216 | if opts.Detach { |
| 217 | return append(cmds, detachCmds(fetchCmd, opts.Worktree, reuseWorktree)...) |
| 218 | } |
| 219 | |
| 220 | cmds = append(cmds, fetchCmd) |
| 221 | |
| 222 | switch { |
| 223 | case opts.Worktree != "": |
| 224 | worktreeCmds, branchExists := shared.WorktreeCheckoutCommands( |
| 225 | opts.GitClient, |
| 226 | shared.WorktreeTarget{Path: opts.Worktree, Reuse: reuseWorktree}, |
| 227 | localBranch, |
| 228 | remoteBranch, |
| 229 | ) |
| 230 | cmds = append(cmds, worktreeCmds...) |
| 231 | if branchExists { |
| 232 | cmds = append(cmds, syncBranchCmds(opts.Worktree, remoteBranchRef, opts.Force)...) |
| 233 | } |
| 234 | case opts.GitClient.HasLocalBranch(context.Background(), localBranch): |
| 235 | cmds = append(cmds, []string{"checkout", localBranch}) |
| 236 | cmds = append(cmds, syncBranchCmds("", remoteBranchRef, opts.Force)...) |
| 237 | default: |
| 238 | cmds = append(cmds, []string{"checkout", "-b", localBranch, "--track", remoteBranch}) |
| 239 | } |
| 240 | |
| 241 | return cmds |
| 242 | } |
| 243 | |
| 244 | func cmdsForMissingRemote(pr *api.PullRequest, baseURLOrName, repoHost, defaultBranch, protocol string, opts *CheckoutOptions, reuseWorktree bool) [][]string { |
| 245 | var cmds [][]string |
no test coverage detected