MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / checkoutConfiguredBranch

Method checkoutConfiguredBranch

internal/store/gitstore.go:615–636  ·  view source on GitHub ↗
(repo *git.Repository, worktree *git.Worktree, authMethod transport.AuthMethod)

Source from the content-addressed store, hash-verified

613}
614
615func (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
638func (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)

Callers 1

EnsureRepositoryMethod · 0.95

Calls 2

NameMethod · 0.65

Tested by

no test coverage detected