git

package
v2.46.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotOnAnyBranch = errors.New("git: not on any branch")

ErrNotOnAnyBranch indicates that the user is in detached HEAD state.

Functions

func AddNamedRemote

func AddNamedRemote(url, name, repoDir string, branches []string) error

func CheckoutBranch

func CheckoutBranch(branch string) error

func CheckoutNewBranch

func CheckoutNewBranch(remoteName, branch string) error

func CommitBody

func CommitBody(sha string) (string, error)

func Config

func Config(name string) (string, error)

func CurrentBranch

func CurrentBranch() (string, error)

func DeleteLocalBranch

func DeleteLocalBranch(branch string) error

func GetDirFromPath

func GetDirFromPath(repoDir string) (string, error)

func GitCommand

func GitCommand(args ...string) (*gitCommand, error)

func HasLocalBranch

func HasLocalBranch(branch string) bool

func IsURL

func IsURL(u string) bool

func ParseURL

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

ParseURL normalizes git remote urls

func PathFromRepoRoot

func PathFromRepoRoot() string

func Pull

func Pull(remote, branch string) error

func Push

func Push(remote string, ref string, cmdIn io.ReadCloser, cmdOut, cmdErr io.Writer) error

func RunClone

func RunClone(cloneURL string, args []string) (target string, err error)

func SetRemoteResolution

func SetRemoteResolution(name, resolution string) error

func ToplevelDir

func ToplevelDir() (string, error)

func UncommittedChangeCount

func UncommittedChangeCount() (int, error)

func UpdateRemoteURL

func UpdateRemoteURL(name, url string) error

Types

type BranchConfig

type BranchConfig struct {
	RemoteName string
	RemoteURL  *url.URL
	MergeRef   string
}

func ReadBranchConfig

func ReadBranchConfig(branch string) (cfg BranchConfig)

type Client

type Client struct {
	GhPath  string
	RepoDir string
	GitPath string
	Stderr  io.Writer
	Stdin   io.Reader
	Stdout  io.Writer
	// contains filtered or unexported fields
}

func (*Client) AddRemote

func (c *Client) AddRemote(ctx context.Context, name, urlStr string, trackingBranches []string, mods ...CommandModifier) (*Remote, error)

func (*Client) AuthenticatedCommand

func (c *Client) AuthenticatedCommand(ctx context.Context, args ...string) (*gitCommand, error)

AuthenticatedCommand is a wrapper around Command that included configuration to use gh as the credential helper for git.

func (*Client) CheckoutBranch

func (c *Client) CheckoutBranch(ctx context.Context, branch string) error

func (*Client) CheckoutNewBranch

func (c *Client) CheckoutNewBranch(ctx context.Context, remoteName, branch string) error

func (*Client) Clone

func (c *Client) Clone(ctx context.Context, cloneURL string, args []string, mods ...CommandModifier) (string, error)

func (*Client) Command

func (c *Client) Command(ctx context.Context, args ...string) (*gitCommand, error)

func (*Client) CommitBody

func (c *Client) CommitBody(ctx context.Context, sha string) (string, error)

func (*Client) Commits

func (c *Client) Commits(ctx context.Context, baseRef, headRef string) ([]*Commit, error)

func (*Client) Config

func (c *Client) Config(ctx context.Context, name string) (string, error)

func (*Client) CurrentBranch

func (c *Client) CurrentBranch(ctx context.Context) (string, error)

CurrentBranch reads the checked-out branch for the git repository.

func (*Client) DeleteLocalBranch

func (c *Client) DeleteLocalBranch(ctx context.Context, branch string) error

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, remote string, refspec string, mods ...CommandModifier) error

func (*Client) GitDir

func (c *Client) GitDir(ctx context.Context) (string, error)

func (*Client) HasLocalBranch

func (c *Client) HasLocalBranch(ctx context.Context, branch string) bool

func (*Client) LastCommit

func (c *Client) LastCommit(ctx context.Context) (*Commit, error)

func (*Client) PathFromRoot

func (c *Client) PathFromRoot(ctx context.Context) string

Show current directory relative to the top-level directory of repository.

func (*Client) Pull

func (c *Client) Pull(ctx context.Context, remote, branch string, mods ...CommandModifier) error

func (*Client) Push

func (c *Client) Push(ctx context.Context, remote string, ref string, mods ...CommandModifier) error

func (*Client) ReadBranchConfig

func (c *Client) ReadBranchConfig(ctx context.Context, branch string) (cfg BranchConfig)

ReadBranchConfig parses the `branch.BRANCH.(remote|merge)` part of git config.

func (*Client) Remotes

func (c *Client) Remotes(ctx context.Context) (RemoteSet, error)

func (*Client) SetRemoteResolution

func (c *Client) SetRemoteResolution(ctx context.Context, name, resolution string) error

func (*Client) ShowRefs

func (c *Client) ShowRefs(ctx context.Context, refs []string) ([]Ref, error)

ShowRefs resolves fully-qualified refs to commit hashes.

func (*Client) ToplevelDir

func (c *Client) ToplevelDir(ctx context.Context) (string, error)

ToplevelDir returns the top-level directory path of the current repository.

func (*Client) UncommittedChangeCount

func (c *Client) UncommittedChangeCount(ctx context.Context) (int, error)

func (*Client) UpdateRemoteURL

func (c *Client) UpdateRemoteURL(ctx context.Context, name, url string) error

type CommandModifier

type CommandModifier func(*gitCommand)

Allow individual commands to be modified from the default client options.

func WithRepoDir

func WithRepoDir(repoDir string) CommandModifier

func WithStderr

func WithStderr(stderr io.Writer) CommandModifier

func WithStdin

func WithStdin(stdin io.Reader) CommandModifier

func WithStdout

func WithStdout(stdout io.Writer) CommandModifier

type Commit

type Commit struct {
	Sha   string
	Title string
}

func Commits

func Commits(baseRef, headRef string) ([]*Commit, error)

func LastCommit

func LastCommit() (*Commit, error)

type GitError

type GitError struct {
	ExitCode int
	Stderr   string
	// contains filtered or unexported fields
}

func (*GitError) Error

func (ge *GitError) Error() string

func (*GitError) Unwrap

func (ge *GitError) Unwrap() error

type NotInstalled

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

func (*NotInstalled) Error

func (e *NotInstalled) Error() string

func (*NotInstalled) Unwrap

func (e *NotInstalled) Unwrap() error

type Ref

type Ref struct {
	Hash string
	Name string
}

Ref represents a git commit reference.

func ShowRefs

func ShowRefs(ref ...string) ([]Ref, error)

type Remote

type Remote struct {
	Name     string
	Resolved string
	FetchURL *url.URL
	PushURL  *url.URL
}

Remote is a parsed git remote.

func AddRemote

func AddRemote(name, url string) (*Remote, error)

func NewRemote

func NewRemote(name string, u string) *Remote

func (*Remote) String

func (r *Remote) String() string

type RemoteSet

type RemoteSet []*Remote

RemoteSet is a slice of git remotes.

func Remotes

func Remotes() (RemoteSet, error)

func RemotesForPath

func RemotesForPath(repoDir string) (RemoteSet, error)

func (RemoteSet) Len

func (r RemoteSet) Len() int

func (RemoteSet) Less

func (r RemoteSet) Less(i, j int) bool

func (RemoteSet) Swap

func (r RemoteSet) Swap(i, j int)

type TrackingRef

type TrackingRef struct {
	RemoteName string
	BranchName string
}

TrackingRef represents a ref for a remote tracking branch.

func (TrackingRef) String

func (r TrackingRef) String() string

Jump to

Keyboard shortcuts

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