(opts *DevelopOptions, branchRepo ghrepo.Interface, checkoutBranch string, worktreeTarget prShared.WorktreeTarget)
| 351 | } |
| 352 | |
| 353 | func checkoutBranch(opts *DevelopOptions, branchRepo ghrepo.Interface, checkoutBranch string, worktreeTarget prShared.WorktreeTarget) (err error) { |
| 354 | remotes, err := opts.Remotes() |
| 355 | if err != nil { |
| 356 | // If the user specified the branch to be checked out and no remotes are found |
| 357 | // display an error. Otherwise bail out silently, likely the command was not |
| 358 | // run from inside a git directory. |
| 359 | if opts.Checkout { |
| 360 | return err |
| 361 | } else { |
| 362 | return nil |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | baseRemote, err := remotes.FindByRepo(branchRepo.RepoOwner(), branchRepo.RepoName()) |
| 367 | if err != nil { |
| 368 | // If the user specified the branch to be checked out and no remote matches the |
| 369 | // base repo, then display an error. Otherwise bail out silently. |
| 370 | if opts.Checkout { |
| 371 | return err |
| 372 | } else { |
| 373 | return nil |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | gc := opts.GitClient |
| 378 | |
| 379 | if err := gc.Fetch(ctx.Background(), baseRemote.Name, fmt.Sprintf("+refs/heads/%[1]s:refs/remotes/%[2]s/%[1]s", checkoutBranch, baseRemote.Name)); err != nil { |
| 380 | return err |
| 381 | } |
| 382 | |
| 383 | if !opts.Checkout { |
| 384 | return nil |
| 385 | } |
| 386 | |
| 387 | if opts.Worktree != "" { |
| 388 | commands, branchExists := prShared.WorktreeCheckoutCommands( |
| 389 | gc, |
| 390 | worktreeTarget, |
| 391 | checkoutBranch, |
| 392 | fmt.Sprintf("%s/%s", baseRemote.Name, checkoutBranch), |
| 393 | ) |
| 394 | if err := runGitCommands(gc, commands); err != nil { |
| 395 | return err |
| 396 | } |
| 397 | if branchExists { |
| 398 | if err := gc.Pull(ctx.Background(), baseRemote.Name, checkoutBranch, git.WithRepoDir(opts.Worktree)); err != nil { |
| 399 | _, _ = fmt.Fprintf(opts.IO.ErrOut, "%s warning: not possible to fast-forward to: %q\n", opts.IO.ColorScheme().WarningIcon(), checkoutBranch) |
| 400 | } |
| 401 | } |
| 402 | return nil |
| 403 | } |
| 404 | |
| 405 | if gc.HasLocalBranch(ctx.Background(), checkoutBranch) { |
| 406 | if err := gc.CheckoutBranch(ctx.Background(), checkoutBranch); err != nil { |
| 407 | return err |
| 408 | } |
| 409 | |
| 410 | if err := gc.Pull(ctx.Background(), baseRemote.Name, checkoutBranch); err != nil { |
no test coverage detected