git

package
v1.43.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultRemote = "origin"

Variables

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 SetRemoteConfig(name, "glab-resolved", resolution)
}
View Source
var StackLocation = filepath.Join(".git", "stacked")
View Source
var ToplevelDir = func() (string, error) {
	showCmd := exec.Command("git", "rev-parse", "--show-toplevel")
	output, err := run.PrepareCmd(showCmd).Output()
	return firstLine(output), err
}

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

Functions

func AddStackRefDir added in v1.42.0

func AddStackRefDir(dir string) (string, error)

func AddStackRefFile added in v1.42.0

func AddStackRefFile(title string, stackRef StackRef) error

func AddUpstreamRemote

func AddUpstreamRemote(upstreamURL, cloneDir string) error

func CheckoutBranch

func CheckoutBranch(branch string) error

func CheckoutNewBranch added in v1.42.0

func CheckoutNewBranch(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 DeleteStackRefFile added in v1.42.0

func DeleteStackRefFile(title string, stackRef StackRef) error

func DescribeByTags added in v1.30.0

func DescribeByTags() (string, error)

DescribeByTags gives a description of the current object. Non-annotated tags are considered. Reference: https://git-scm.com/docs/git-describe

func GetAllConfig added in v1.32.0

func GetAllConfig(key string) ([]byte, error)

GetConfig returns the local config value associated with the provided key. If there are multiple values associated with the key, they are all returned.

func GetCurrentStackTitle added in v1.42.0

func GetCurrentStackTitle() (title string, err 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 GitUserName added in v1.42.0

func GitUserName() ([]byte, error)

func HasLocalBranch

func HasLocalBranch(branch string) bool

func InitGitRepo added in v1.41.0

func InitGitRepo(t *testing.T) string

func InitGitRepoWithCommit added in v1.41.0

func InitGitRepoWithCommit(t *testing.T) string

func IsValidURL

func IsValidURL(u string) bool

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

func ListTags added in v1.30.0

func ListTags() ([]string, error)

ListTags gives a slice of tags from the current repository.

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(key, value string) error

func SetLocalConfig added in v1.42.0

func SetLocalConfig(key, value string) error

func SetRemoteConfig added in v1.32.0

func SetRemoteConfig(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 StackRootDir added in v1.42.0

func StackRootDir(title string) (string, error)

func UncommittedChangeCount

func UncommittedChangeCount() (int, error)

func UpdateStackRefFile added in v1.42.0

func UpdateStackRefFile(title string, s StackRef) 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 LatestCommit

func LatestCommit(ref string) (*Commit, error)

type GitRunner added in v1.42.0

type GitRunner interface {
	Git(args ...string) (string, 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 Stack added in v1.42.0

type Stack struct {
	Title string
	Refs  map[string]StackRef
}

func GatherStackRefs added in v1.42.0

func GatherStackRefs(title string) (Stack, error)

func (Stack) Empty added in v1.42.0

func (s Stack) Empty() bool

func (*Stack) First added in v1.42.0

func (s *Stack) First() (StackRef, error)

func (*Stack) Last added in v1.42.0

func (s *Stack) Last() (StackRef, error)

func (*Stack) RemoveBranch added in v1.42.0

func (s *Stack) RemoveBranch(ref StackRef) error

func (*Stack) RemoveRef added in v1.42.0

func (s *Stack) RemoveRef(ref StackRef) error

type StackRef added in v1.42.0

type StackRef struct {
	Prev        string `json:"prev"`
	Branch      string `json:"branch"`
	SHA         string `json:"sha"`
	Next        string `json:"next"`
	MR          string `json:"mr"`
	Description string `json:"description"`
}

func CurrentStackRefFromBranch added in v1.42.0

func CurrentStackRefFromBranch(title string) (StackRef, error)

type StandardGitCommand added in v1.42.0

type StandardGitCommand struct{}

func (StandardGitCommand) Git added in v1.42.0

func (gitc StandardGitCommand) Git(args ...string) (string, error)

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