git

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package git provides functionality for interacting with local and remote git repositories.

Index

Constants

This section is empty.

Variables

View Source
var (
	// CommandRunnerImpl exists for testing purposes.
	CommandRunnerImpl cmd.CommandRunner = cmd.RealCommandRunner{}
)

Functions

func AddRemote

func AddRemote(gitRepo, remote, remoteLocation string) error

AddRemote adds a remote.

func Checkout

func Checkout(gitRepo, branch string) error

Checkout checkouts a branch.

func Clone

func Clone(remote, dir string, opts ...cloneOpt) error

Clone clones the remote into the specified dir.

func CommitAll

func CommitAll(gitRepo, commitMsg string) (string, error)

CommitAll adds all local changes and commits them. Returns the sha1 of the commit.

func CommitEmpty

func CommitEmpty(gitRepo, commitMsg string) (string, error)

CommitEmpty makes an empty commit (assuming nothing is staged). Returns the sha1 of the commit.

func CreateBranch

func CreateBranch(gitRepo, branch string) error

CreateBranch creates a branch.

func CreateTrackingBranch

func CreateTrackingBranch(gitRepo, branch string, remoteRef RemoteRef) error

CreateTrackingBranch creates a tracking branch.

func DeleteBranch

func DeleteBranch(gitRepo, branch string, force bool) error

DeleteBranch checks out to master and then deletes the current branch.

func Fetch

func Fetch(gitRepo, remote, refspec string, opts ...fetchOpt) error

Fetch fetches refspec in gitRepo.

func GetCurrentBranch

func GetCurrentBranch(cwd string) string

GetCurrentBranch returns current branch of a repo, and an empty string if repo is on detached HEAD.

func GetGitRepoRevision

func GetGitRepoRevision(cwd, branch string) (string, error)

GetGitRepoRevision finds and returns the revision of a branch.

func GetRemotes

func GetRemotes(gitRepo string) ([]string, error)

GetRemotes returns the remotes for a repository.

func Init

func Init(gitRepo string, bare bool) error

Init initializes a repo.

func IsReachable

func IsReachable(cwd, toRef, fromRef string) (bool, error)

IsReachable determines whether one commit ref is reachable from another.

func IsSHA

func IsSHA(ref string) bool

IsSHA checks whether or not the given ref is a SHA.

func MatchBranchName

func MatchBranchName(gitRepo string, pattern *regexp.Regexp) ([]string, error)

MatchBranchName returns the names of branches who match the specified regular expression.

func MatchBranchNameWithNamespace

func MatchBranchNameWithNamespace(gitRepo string, pattern, namespace *regexp.Regexp) ([]string, error)

MatchBranchNameWithNamespace returns the names of branches who match the specified pattern and start with the specified namespace.

func NormalizeRef

func NormalizeRef(ref string) string

NormalizeRef converts git branch refs into fully qualified form.

func PushRef

func PushRef(gitRepo, localRef string, pushTo RemoteRef, opts ...pushRefOpt) error

PushRef pushes the specified local ref to the specified remote ref.

func Refs

func Refs(gitRepo string) (map[string]string, error)

Refs returns all of the refs in a repository, mapped to the corresponding SHAs.

func RemoteBranches

func RemoteBranches(gitRepo, remote string) ([]string, error)

RemoteBranches returns a list of branches on the specified remote.

func RemoteHasBranch

func RemoteHasBranch(gitRepo, remote, branch string) (bool, error)

RemoteHasBranch checks whether or not a branch exists on a remote.

func ResolveRemoteSymbolicRef

func ResolveRemoteSymbolicRef(gitRepo, remote string, ref string) (string, error)

ResolveRemoteSymbolicRef resolves the target of a symbolic ref.

func RunGitIgnoreOutput

func RunGitIgnoreOutput(gitRepo string, cmd []string) error

RunGitIgnoreOutput runs the specified git command in the specified repo a and returns only an error, not the command output.

func StripRefs

func StripRefs(ref string) string

StripRefs removes leading 'refs/heads/', 'refs/remotes/[^/]+/' from a ref name.

func StripRefsHead

func StripRefsHead(ref string) string

StripRefsHead removes leading 'refs/heads/' from a ref name.

Types

type BranchOpt

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

func Branch

func Branch(val string) *BranchOpt

Branch specifies the branch to clone from. Must be used in conjunction with SingleBranch

type CommandOutput

type CommandOutput struct {
	Stdout string
	Stderr string
}

CommandOutput contains stdout/stderr for a command.

func RunGit

func RunGit(gitRepo string, cmd []string) (CommandOutput, error)

RunGit the specified git command in the specified repo. It returns stdout and stderr.

type DepthOpt

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

func Depth

func Depth(val int) *DepthOpt

Depth creates a shallow clone, and limits fetches in a repository created by a shallow clone.

type DryRunOpt

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

func DryRun

func DryRun() *DryRunOpt

DryRun shows what a command would do without actually running it.

func DryRunIf

func DryRunIf(enabled bool) *DryRunOpt

DryRun shows what a command would do without actually running it.

type ForceOpt

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

func Force

func Force() *ForceOpt

Force overrides checks that a command might run before modifying state, see individual command documentation for exact behavior.

func ForceIf

func ForceIf(enabled bool) *ForceOpt

Force overrides checks that a command might run before modifying state, see individual command documentation for exact behavior.

type NoTagsOpt

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

func NoTags

func NoTags() *NoTagsOpt

NoTags disables downloading tags during fetch or clone commands.

func NoTagsIf

func NoTagsIf(enabled bool) *NoTagsOpt

NoTags disables downloading tags during fetch or clone commands.

type RemoteRef

type RemoteRef struct {
	Remote string
	Ref    string
}

RemoteRef is a strcut representing a remote ref.

type SingleBranchOpt

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

func SingleBranch

func SingleBranch() *SingleBranchOpt

SingleBranch clones only a single branch

func SingleBranchIf

func SingleBranchIf(enabled bool) *SingleBranchOpt

SingleBranch clones only a single branch

Directories

Path Synopsis
Generates options.go, which implements git options.
Generates options.go, which implements git options.

Jump to

Keyboard shortcuts

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