(repo *git.Repository, worktree *git.Worktree, authMethod transport.AuthMethod)
| 613 | } |
| 614 | |
| 615 | func (s *GitTokenStore) checkoutConfiguredBranch(repo *git.Repository, worktree *git.Worktree, authMethod transport.AuthMethod) error { |
| 616 | branchRefName := plumbing.NewBranchReferenceName(s.branch) |
| 617 | headRef, errHead := repo.Head() |
| 618 | switch { |
| 619 | case errHead == nil && headRef.Name() == branchRefName: |
| 620 | return nil |
| 621 | case errHead != nil && !errors.Is(errHead, plumbing.ErrReferenceNotFound): |
| 622 | return fmt.Errorf("git token store: get head: %w", errHead) |
| 623 | } |
| 624 | |
| 625 | if err := worktree.Checkout(&git.CheckoutOptions{Branch: branchRefName}); err == nil { |
| 626 | return nil |
| 627 | } else if _, errRef := repo.Reference(branchRefName, true); errRef == nil { |
| 628 | return fmt.Errorf("git token store: checkout branch %s: %w", s.branch, err) |
| 629 | } else if !errors.Is(errRef, plumbing.ErrReferenceNotFound) { |
| 630 | return fmt.Errorf("git token store: inspect branch %s: %w", s.branch, errRef) |
| 631 | } else if err := s.checkoutConfiguredRemoteTrackingBranch(repo, worktree, branchRefName, authMethod); err != nil { |
| 632 | return fmt.Errorf("git token store: checkout branch %s: %w", s.branch, err) |
| 633 | } |
| 634 | |
| 635 | return nil |
| 636 | } |
| 637 | |
| 638 | func (s *GitTokenStore) checkoutConfiguredRemoteTrackingBranch(repo *git.Repository, worktree *git.Worktree, branchRefName plumbing.ReferenceName, authMethod transport.AuthMethod) error { |
| 639 | remoteRefName := plumbing.ReferenceName("refs/remotes/origin/" + s.branch) |
no test coverage detected