gitclient

package
v3.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultGitUserName default value to use for git "user.name"
	DefaultGitUserName = "jenkins-x-bot"

	// DefaultGitUserEmail default value to use for git "user.email"
	DefaultGitUserEmail = "jenkins-x@googlegroups.com"
)

Variables

This section is empty.

Functions

func Add

func Add(g Interface, dir string, args ...string) error

Add does a git add for all the given arguments

func AddAndCommitFiles

func AddAndCommitFiles(gitter Interface, dir, message string) (bool, error)

AddAndCommitFiles add and commits files

func AddRemote

func AddRemote(g Interface, dir string, name string, url string) error

AddRemote adds a remote repository at the given URL and with the given name

func Branch

func Branch(g Interface, dir string) (string, error)

Branch returns the current branch of the repository located at the given directory

func Checkout

func Checkout(g Interface, dir string, branch string) error

Checkout checks out the given branch

func CheckoutRemoteBranch

func CheckoutRemoteBranch(g Interface, dir string, branch string) error

CheckoutRemoteBranch checks out the given remote tracking branch

func CloneOrPull

func CloneOrPull(g Interface, url string, dir string) error

CloneOrPull performs a clone if the directory is empty otherwise a pull

func CloneToDir

func CloneToDir(g Interface, gitURL, dir string) (string, error)

CloneToDir clones the git repository to either the given directory or create a temporary

func CommitIfChanges

func CommitIfChanges(g Interface, dir string, message string) error

CommiIfChanges does a commit if there are any changes in the repository at the given directory

func CreateBranch

func CreateBranch(gitter Interface, dir string) (string, error)

CreateBranch creates a dynamic branch name and branch

func CreateBranchFrom

func CreateBranchFrom(g Interface, dir string, branchName string, startPoint string) error

CreateBranchFrom creates a new branch called branchName from startPoint

func Describe

func Describe(g Interface, dir string, contains bool, commitish string, abbrev string, fallback bool) (string, string, error)

Describe does a git describe of commitish, optionally adding the abbrev arg if not empty, falling back to just the commit ref if it's untagged

func EnsureUserAndEmailSetup

func EnsureUserAndEmailSetup(gitter Interface, dir string, gitUserName string, gitUserEmail string) (string, string, error)

EnsureUserAndEmailSetup returns the user name and email for the gitter lazily setting them if they are blank either from the given values or if they are empty using environment variables `GIT_AUTHOR_NAME` and `GIT_AUTHOR_EMAIL` or using default values

func FetchBranch

func FetchBranch(g Interface, dir string, repo string, refspecs ...string) error

FetchBranch fetches the refspecs from the repo

func FetchRemoteTags

func FetchRemoteTags(g Interface, dir string, repo string) error

FetchRemoteTags fetches all the tags from a remote repository

func FetchTags

func FetchTags(g Interface, dir string) error

FetchTags fetches all the tags

func FilterTags

func FilterTags(g Interface, dir string, filter string) ([]string, error)

FilterTags returns all tags from the repository at the given directory that match the filter

func FindGitConfigDir

func FindGitConfigDir(dir string) (string, string, error)

FindGitConfigDir tries to find the `.git` directory either in the current directory or in parent directories

func ForcePushBranch

func ForcePushBranch(g Interface, dir string, localBranch string, remoteBranch string) error

ForcePushBranch does a force push of the local branch into the remote branch of the repository at the given directory

func GetCommitPointedToByLatestTag

func GetCommitPointedToByLatestTag(g Interface, dir string) (string, string, error)

GetCommitPointedToByLatestTag return the SHA of the commit pointed to by the latest git tag as well as the tag name for the git repo in dir

func GetLatestCommitAuthor

func GetLatestCommitAuthor(g Interface, dir string) (string, error)

GetLatestCommitAuthor returns the latest git commit author

func GetLatestCommitAuthorEmail

func GetLatestCommitAuthorEmail(g Interface, dir string) (string, error)

GetLatestCommitAuthorEmail returns the latest git commit author email

func GetLatestCommitDate

func GetLatestCommitDate(g Interface, dir string) (string, error)

GetLatestCommitDate returns the latest git commit date in RFC2822 format

func GetLatestCommitMessage

func GetLatestCommitMessage(g Interface, dir string) (string, error)

GetLatestCommitMessage returns the latest git commit message

func GetLatestCommitSha

func GetLatestCommitSha(g Interface, dir string) (string, error)

GetLatestCommitSha returns the latest commit sha

func HasChanges

func HasChanges(g Interface, dir string) (bool, error)

HasChanges indicates if there are any changes in the repository from the given directory

func HasFileChanged

func HasFileChanged(g Interface, dir string, fileName string) (bool, error)

HasFileChanged indicates if there are any changes to a file in the repository from the given directory

func Init

func Init(g Interface, dir string) error

Init inits a git repository into the given directory

func Merge

func Merge(g Interface, dir string, commitish string) error

Merge merges the commitish into the current branch

func NthTag

func NthTag(g Interface, dir string, n int) (string, string, error)

NthTag return the SHA and tag name of nth tag in reverse chronological order from the repository at the given directory. If the nth tag does not exist empty strings without an error are returned.

func Pull

func Pull(g Interface, dir string) error

Pull performs a git pull

func Push

func Push(g Interface, dir string, remote string, force bool, refspec ...string) error

Push pushes the changes from the repository at the given directory

func RefIsBranch

func RefIsBranch(gitter Interface, dir string, ref string) (bool, error)

RefIsBranch looks for remove branches in ORIGIN for the provided directory and returns true if ref is found

func RemoteBranches

func RemoteBranches(gitter Interface, dir string) ([]string, error)

RemoteBranches returns the remote branches

func Remove

func Remove(g Interface, dir, fileName string) error

Remove removes the given file from a Git repository located at the given directory

func SetCredentialHelper

func SetCredentialHelper(gitter Interface, dir string) error

SetCredentialHelper sets the credential store so that we detect the ~/git/credentials file for defaulting access tokens.

If the dir parameter is blank we will use the home dir

func SetUpstreamTo

func SetUpstreamTo(g Interface, dir string, branch string) error

SetUpstreamTo will set the given branch to track the origin branch with the same name

func SetUserAndEmail

func SetUserAndEmail(gitter Interface, dir string, gitUserName string, gitUserEmail string, assumeInCluster bool) (string, string, error)

SetUserAndEmail sets the user and email if they have not been set Uses environment variables `GIT_AUTHOR_NAME` and `GIT_AUTHOR_EMAIL`

func ShallowCloneBranch

func ShallowCloneBranch(g Interface, gitURL string, branch string, dir string) error

ShallowCloneBranch clones a single branch of the given git URL into the given directory

func Status

func Status(g Interface, dir string) (string, error)

Status returns the status of the git repository at the given directory

func Tags

func Tags(g Interface, dir string) ([]string, error)

Tags returns all tags from the repository at the given directory

Types

type Interface

type Interface interface {
	// Command command runs the git sub command such as 'commit' or 'clone'
	// in the given directory with the arguments
	Command(dir string, args ...string) (string, error)
}

Interface a simple interface to performing git commands which is easy to fake for testing

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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