Version: v1.22.0 Latest Latest

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 14 Imported by: 0




This section is empty.


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

ErrNotOnAnyBranch indicates that the users is in detached HEAD state

View Source
var GitCommand = func(args ...string) *exec.Cmd {
	return exec.Command("git", args...)
View Source
var SetRemoteResolution = func(name, resolution string) error {
	return SetConfig(name, "glab-resolved", resolution)


func AddUpstreamRemote

func AddUpstreamRemote(upstreamURL, cloneDir 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 GetDefaultBranch

func GetDefaultBranch(remote string) (string, error)

GetDefaultBranch finds and returns the remote's default branch

func GetRemoteURL

func GetRemoteURL(remoteAlias string) (string, error)

func HasLocalBranch

func HasLocalBranch(branch string) bool

func IsValidURL

func IsValidURL(u string) bool

IsValidUrl tests a string to determine if it is a valid Git url or not.

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

func RunClone

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

func RunCmd

func RunCmd(args []string) (err error)

func SetConfig

func SetConfig(remote, key, value string) error

func SetUpstream

func SetUpstream(remote string, branch string, cmdOut, cmdErr io.Writer) error

SetUpstream sets the upstream (tracking) of a branch

func ToplevelDir

func ToplevelDir() (string, error)

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

func UncommittedChangeCount

func UncommittedChangeCount() (int, error)


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 LatestCommit

func LatestCommit(ref string) (*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 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

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