git

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 16 Imported by: 20

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) (*exec.Cmd, error) {
	gitExe, err := safeexec.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 exec.Command(gitExe, args...), nil
}

Functions

func AddUpstreamRemote added in v0.11.1

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

func CheckoutBranch added in v0.9.0

func CheckoutBranch(branch string) error

func CommitBody added in v0.6.2

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 added in v0.9.0

func DeleteLocalBranch(branch string) error

func HasLocalBranch added in v0.9.0

func HasLocalBranch(branch string) bool

func IsURL added in v0.12.0

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 added in v0.11.1

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

func SetRemoteResolution added in v1.0.0

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 added in v0.6.2

type Commit struct {
	Sha   string
	Title string
}

func Commits added in v0.6.2

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

func LastCommit added in v1.6.0

func LastCommit() (*Commit, error)

type Ref added in v0.6.3

type Ref struct {
	Hash string
	Name string
}

Ref represents a git commit reference

func ShowRefs added in v0.6.3

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 added in v0.12.0

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 SSHAliasMap

type SSHAliasMap map[string]string

SSHAliasMap encapsulates the translation of SSH hostname aliases

func ParseSSHConfig

func ParseSSHConfig() SSHAliasMap

ParseSSHConfig constructs a map of SSH hostname aliases based on user and system configuration files

func (SSHAliasMap) Translator

func (m SSHAliasMap) Translator() func(*url.URL) *url.URL

Translator returns a function that applies hostname aliases to URLs

type TrackingRef added in v0.6.3

type TrackingRef struct {
	RemoteName string
	BranchName string
}

TrackingRef represents a ref for a remote tracking branch

func (TrackingRef) String added in v0.6.3

func (r TrackingRef) String() string

Jump to

Keyboard shortcuts

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