git

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 13 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

View Source
var GitCommand = func(args ...string) (*execlog.Cmd, error) {
	gitExe, err := execlog.LookPath("git")
	if err != nil {
		programName := "git"
		if runtime.GOOS == "windows" {
			programName = "Git for Windows"
		}
		return nil, fmt.Errorf("unable to find git executable in PATH; please install %s before retrying", programName)
	}
	return execlog.Command(gitExe, args...), nil
}

Functions

func AddUpstreamRemote

func AddUpstreamRemote(upstreamURL, cloneDir string, branches []string) error

func CheckoutBranch

func CheckoutBranch(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)

CurrentBranch reads the checked-out branch for the git repository

func DeleteLocalBranch

func DeleteLocalBranch(branch string) 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 Push

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

Push publishes a git ref to a remote and sets up upstream configuration

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)

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

func UncommittedChangeCount

func UncommittedChangeCount() (int, error)

Types

type BranchConfig

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

func ReadBranchConfig

func ReadBranchConfig(branch string) (cfg BranchConfig)

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

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 Ref

type Ref struct {
	Hash string
	Name string
}

Ref represents a git commit reference

func ShowRefs

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

ShowRefs resolves fully-qualified refs to commit hashes

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, u string) (*Remote, error)

AddRemote adds a new git remote and auto-fetches objects from it

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)

Remotes gets the git remotes set for the current repo

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