git

package
v0.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRepositoryNotExists indicates the requested path is not inside a git repository.
	ErrRepositoryNotExists = errors.New("repository does not exist")
	// ErrBranchExists indicates the requested branch already exists locally.
	ErrBranchExists = errors.New("branch already exists")
)

Functions

func CurrentBackendName

func CurrentBackendName() string

CurrentBackendName returns the active backend name.

func ParseURL

func ParseURL(rawURL string) (u *url.URL, err error)

ParseURL parses URL string and return URL struct

func RegisterBackend

func RegisterBackend(backend Backend) error

RegisterBackend makes a git backend available for later switching.

func RegisteredBackends

func RegisteredBackends() []string

RegisteredBackends returns all registered backend names.

func UseBackend

func UseBackend(name string) error

UseBackend switches the active git backend implementation.

Types

type AuthMethod

type AuthMethod struct {
	Scheme        string
	Username      string
	Password      string
	KeyFile       string
	KeyPassphrase string
}

AuthMethod carries backend-agnostic authentication information for git operations.

func GetAuthForURL

func GetAuthForURL(remoteURL *url.URL, authToken, keyFile string, passwordCallback pwCallback) (*AuthMethod, error)

GetAuthForURL returns backend-agnostic auth settings for git network operations.

type Backend

type Backend interface {
	Name() string
	Open(path string) (RepositoryBackend, error)
	Clone(path, remoteURL string, auth *AuthMethod, opts CloneOptions) (RepositoryBackend, error)
}

Backend opens and clones repositories using a concrete git implementation.

type Branch

type Branch struct {
	Name   string
	Remote string
	Merge  ReferenceName
}

Branch stores branch configuration.

func (*Branch) Validate

func (b *Branch) Validate() error

Validate checks whether the branch contains the fields tea needs.

type CloneOptions

type CloneOptions struct {
	Depth    int
	Insecure bool
}

CloneOptions describes repository clone behavior.

type Config

type Config struct {
	Remotes  map[string]*RemoteConfig
	Branches map[string]*Branch
}

Config mirrors the repository config fields tea needs.

type Hash

type Hash string

Hash wraps a git object id.

func (Hash) String

func (h Hash) String() string

type Reference

type Reference struct {
	// contains filtered or unexported fields
}

Reference stores a resolved git ref and its hash.

func (*Reference) Hash

func (r *Reference) Hash() Hash

Hash returns the reference hash.

func (*Reference) Name

func (r *Reference) Name() ReferenceName

Name returns the reference name.

type ReferenceName

type ReferenceName string

ReferenceName identifies a git reference.

func NewBranchReferenceName

func NewBranchReferenceName(name string) ReferenceName

NewBranchReferenceName constructs a local branch ref name.

func NewRemoteReferenceName

func NewRemoteReferenceName(remote, name string) ReferenceName

NewRemoteReferenceName constructs a remote-tracking ref name.

func (ReferenceName) IsBranch

func (r ReferenceName) IsBranch() bool

IsBranch reports whether the reference points to a local branch.

func (ReferenceName) IsRemote

func (r ReferenceName) IsRemote() bool

IsRemote reports whether the reference points to a remote-tracking branch.

func (ReferenceName) IsTag

func (r ReferenceName) IsTag() bool

IsTag reports whether the reference points to a tag.

func (ReferenceName) Short

func (r ReferenceName) Short() string

Short returns the short display name for the reference.

func (ReferenceName) String

func (r ReferenceName) String() string

type Remote

type Remote struct {
	// contains filtered or unexported fields
}

Remote wraps a configured git remote.

func (*Remote) Config

func (r *Remote) Config() *RemoteConfig

Config returns the remote configuration.

type RemoteConfig

type RemoteConfig struct {
	Name string
	URLs []string
}

RemoteConfig stores remote configuration.

type RepositoryBackend

type RepositoryBackend interface {
	WorkTree() string
	Config() (*Config, error)
	Head() (*Reference, error)
	AddRemote(name, remoteURL string) error
	SetBranchUpstream(branchName, remoteName, remoteBranch string) error
	Fetch(remoteName string, refspecs []string, auth *AuthMethod) error
	CreateTrackingBranch(localBranchName, remoteBranchName, remoteName string) error
	Checkout(ref ReferenceName) error
	DeleteLocalBranch(branchName string) error
	DeleteRemoteBranch(remoteName, remoteBranch string, auth *AuthMethod) error
	ListReferences(prefixes ...string) ([]*Reference, error)
	PushToAgitFlowPR(remoteName, head, base, topic string, pushOptions map[string]string, auth *AuthMethod) error
}

RepositoryBackend is the backend abstraction used by TeaRepo.

type TeaRepo

type TeaRepo struct {
	// contains filtered or unexported fields
}

TeaRepo wraps a local git repository behind a swappable backend.

func Clone

func Clone(path, remoteURL string, auth *AuthMethod, depth int, insecure bool) (*TeaRepo, error)

Clone clones a repository using the active backend.

func RepoForWorkdir

func RepoForWorkdir() (*TeaRepo, error)

RepoForWorkdir tries to open the git repository in the local directory for reading or modification.

func RepoFromPath

func RepoFromPath(path string) (*TeaRepo, error)

RepoFromPath tries to open the git repository by path.

func (TeaRepo) AddRemote

func (r TeaRepo) AddRemote(name, remoteURL string) error

AddRemote adds a new remote to the repository.

func (TeaRepo) Config

func (r TeaRepo) Config() (*Config, error)

Config returns the repository config values tea needs.

func (TeaRepo) Fetch

func (r TeaRepo) Fetch(remoteName string, refspecs []string, auth *AuthMethod) error

Fetch fetches updates from the named remote.

func (TeaRepo) GetOrCreateRemote

func (r TeaRepo) GetOrCreateRemote(remoteURL, newRemoteName string) (*Remote, error)

GetOrCreateRemote tries to match a Remote of the repo via the given URL. If no match is found, a new Remote with `newRemoteName` is created. Matching is based on the normalized URL, accepting different protocols.

func (TeaRepo) GetRemote

func (r TeaRepo) GetRemote(remoteURL string) (*Remote, error)

GetRemote tries to match a Remote of the repo via the given URL. Matching is based on the normalized URL, accepting different protocols.

func (TeaRepo) Head

func (r TeaRepo) Head() (*Reference, error)

Head returns the currently checked out ref.

func (TeaRepo) PushToCreatAgitFlowPR

func (r TeaRepo) PushToCreatAgitFlowPR(remoteName, head, base, topic, title, description string, auth *AuthMethod) error

PushToCreatAgitFlowPR pushes the given head to the refs/for/<base>/<topic> ref on the remote to create an agit flow PR.

func (TeaRepo) Remote

func (r TeaRepo) Remote(remoteName string) (*Remote, error)

Remote returns the configured remote by name.

func (TeaRepo) RemoteURL

func (r TeaRepo) RemoteURL(remoteName string) (*url.URL, error)

RemoteURL returns the URL of the given remote.

func (TeaRepo) Remotes

func (r TeaRepo) Remotes() ([]*Remote, error)

Remotes returns all configured remotes sorted by name.

func (TeaRepo) SetBranchUpstream

func (r TeaRepo) SetBranchUpstream(branchName, remoteName, remoteBranch string) error

SetBranchUpstream configures the branch's upstream remote.

func (TeaRepo) TeaCheckout

func (r TeaRepo) TeaCheckout(ref ReferenceName) error

TeaCheckout checks out the given branch in the worktree.

func (TeaRepo) TeaCreateBranch

func (r TeaRepo) TeaCreateBranch(localBranchName, remoteBranchName, remoteName string) error

TeaCreateBranch creates a new branch in the repo, tracking from another branch.

func (TeaRepo) TeaDeleteLocalBranch

func (r TeaRepo) TeaDeleteLocalBranch(branch *Branch) error

TeaDeleteLocalBranch removes the given branch locally.

func (TeaRepo) TeaDeleteRemoteBranch

func (r TeaRepo) TeaDeleteRemoteBranch(remoteName, remoteBranch string, auth *AuthMethod) error

TeaDeleteRemoteBranch removes the given branch on the given remote via git protocol.

func (TeaRepo) TeaFindBranchByName

func (r TeaRepo) TeaFindBranchByName(branchName, repoURL string) (b *Branch, err error)

TeaFindBranchByName returns a branch that is at the the given local and remote names and syncs to the given remote repo. This method is less precise than TeaFindBranchBySha(), but may be desirable if local and remote branch have diverged.

func (TeaRepo) TeaFindBranchBySha

func (r TeaRepo) TeaFindBranchBySha(sha, repoURL string) (b *Branch, err error)

TeaFindBranchBySha returns a branch that is at the the given SHA and syncs to the given remote repo.

func (TeaRepo) TeaFindBranchRemote

func (r TeaRepo) TeaFindBranchRemote(branchName, hash string) (*Remote, error)

TeaFindBranchRemote gives the first remote that has a branch with the same name or sha, depending on what is passed in. This function is needed, as git does not always define branches in .git/config with remote entries. Priority order is: first match of sha and branch -> first match of branch -> first match of sha.

func (TeaRepo) TeaGetCurrentBranchNameAndSHA

func (r TeaRepo) TeaGetCurrentBranchNameAndSHA() (string, string, error)

TeaGetCurrentBranchNameAndSHA return the name and sha of the branch witch is currently active.

func (TeaRepo) TeaRemoteURL

func (r TeaRepo) TeaRemoteURL(name string) (auth *url.URL, err error)

TeaRemoteURL returns the first url entry for the given remote name.

func (TeaRepo) WorkTree

func (r TeaRepo) WorkTree() string

WorkTree returns the repository work tree path.

type URLParser

type URLParser struct{}

URLParser represents a git URL parser

func (*URLParser) Parse

func (p *URLParser) Parse(rawURL string) (u *url.URL, err error)

Parse parses the git URL

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL