git

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: Apache-2.0 Imports: 24 Imported by: 38

Documentation

Index

Constants

View Source
const (
	// DefaultGithubOrg is the default GitHub org used for Kubernetes project
	// repos.
	DefaultGithubOrg = "kubernetes"

	// DefaultGithubRepo is the default git repository.
	DefaultGithubRepo = "kubernetes"

	// DefaultGithubReleaseRepo is the default git repository used for
	// SIG Release.
	DefaultGithubReleaseRepo = "sig-release"

	// DefaultRemote is the default git remote name.
	DefaultRemote = "origin"

	// DefaultRef is the default git reference name.
	DefaultRef = "HEAD"

	// DefaultBranch is the default branch name.
	DefaultBranch = "master"

	// DefaultGitUser is the default user name used for commits.
	DefaultGitUser = "Kubernetes Release Robot"

	// DefaultGitEmail is the default email used for commits.
	DefaultGitEmail = "k8s-release-robot@users.noreply.github.com"
)

Variables

This section is empty.

Functions

func ConfigureGlobalCustomUserAndEmail added in v0.11.0

func ConfigureGlobalCustomUserAndEmail(gitUser, gitEmail string) error

ConfigureGlobalCustomUserAndEmail globally configures a custom git user and email.

func ConfigureGlobalDefaultUserAndEmail

func ConfigureGlobalDefaultUserAndEmail() error

ConfigureGlobalDefaultUserAndEmail globally configures the default git user and email.

func GetDefaultKubernetesRepoURL

func GetDefaultKubernetesRepoURL() string

GetDefaultKubernetesRepoURL returns the default HTTPS repo URL for Kubernetes. Expected: https://github.com/kubernetes/kubernetes

func GetKubernetesRepoURL

func GetKubernetesRepoURL(org string, useSSH bool) string

GetKubernetesRepoURL takes a GitHub org and repo, and useSSH as a boolean and returns a repo URL for Kubernetes. Expected result is one of the following: - https://github.com/<org>/kubernetes - git@github.com:<org>/kubernetes.

func GetRepoURL

func GetRepoURL(org, repo string, useSSH bool) (repoURL string)

GetRepoURL takes a GitHub org and repo, and useSSH as a boolean and returns a repo URL for the specified repo. Expected result is one of the following: - https://github.com/<org>/<repo> - git@github.com:<org>/<repo>.

func GetUserEmail

func GetUserEmail() (string, error)

GetUserEmail reads the user's name from git.

func GetUserName

func GetUserName() (string, error)

GetUserName Reads the local user's name from the git configuration.

func IsReleaseBranch

func IsReleaseBranch(branch string) bool

IsReleaseBranch returns true if the provided branch is a Kubernetes release branch.

func LSRemoteExec

func LSRemoteExec(repoURL string, args ...string) (string, error)

func ParseRepoSlug

func ParseRepoSlug(repoSlug string) (org, repo string, err error)

ParseRepoSlug parses a repository string and return the organization and repository name/.

func Remotify

func Remotify(name string) string

Remotify returns the name prepended with the default remote.

Types

type DescribeOptions

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

DescribeOptions is the type for the argument passed to repo.Describe.

func NewDescribeOptions

func NewDescribeOptions() *DescribeOptions

NewDescribeOptions creates new repository describe options.

func (*DescribeOptions) WithAbbrev

func (d *DescribeOptions) WithAbbrev(abbrev uint8) *DescribeOptions

WithAbbrev sets the --abbrev=<parameter> in the DescribeOptions.

func (*DescribeOptions) WithAlways

func (d *DescribeOptions) WithAlways() *DescribeOptions

WithAlways sets always to true in the DescribeOptions.

func (*DescribeOptions) WithDirty

func (d *DescribeOptions) WithDirty() *DescribeOptions

WithDirty sets dirty to true in the DescribeOptions.

func (*DescribeOptions) WithRevision

func (d *DescribeOptions) WithRevision(rev string) *DescribeOptions

WithRevision sets the revision in the DescribeOptions.

func (*DescribeOptions) WithTags

func (d *DescribeOptions) WithTags() *DescribeOptions

WithTags sets tags to true in the DescribeOptions.

type DiscoverResult

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

DiscoverResult is the result of a revision discovery.

func (*DiscoverResult) EndRev

func (d *DiscoverResult) EndRev() string

EndRev returns the end revision for the DiscoverResult.

func (*DiscoverResult) EndSHA

func (d *DiscoverResult) EndSHA() string

EndSHA returns the end SHA for the DiscoverResult.

func (*DiscoverResult) StartRev

func (d *DiscoverResult) StartRev() string

StartRev returns the start revision for the DiscoverResult.

func (*DiscoverResult) StartSHA

func (d *DiscoverResult) StartSHA() string

StartSHA returns the start SHA for the DiscoverResult.

type NetworkError

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

NetworkError is a wrapper for the error class.

func NewNetworkError

func NewNetworkError(err error) NetworkError

NewNetworkError creates a new NetworkError.

func (NetworkError) CanRetry

func (e NetworkError) CanRetry() bool

CanRetry tells if an error can be retried.

type Remote

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

Remote is a representation of a git remote location.

func NewRemote

func NewRemote(name string, urls []string) *Remote

NewRemote creates a new remote for the provided name and URLs.

func (*Remote) Name

func (r *Remote) Name() string

Name returns the name of the remote.

func (*Remote) URLs

func (r *Remote) URLs() []string

URLs returns all available URLs of the remote.

type Repo

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

Repo is a wrapper for a Kubernetes repository instance.

func CleanCloneGitHubRepo

func CleanCloneGitHubRepo(owner, repo string, useSSH, updateRepo bool, opts *git.CloneOptions) (*Repo, error)

CleanCloneGitHubRepo creates a guaranteed fresh checkout of a given repository. The returned *Repo has a Cleanup() method that should be used to delete the repository on-disk afterwards.

func CloneOrOpenDefaultGitHubRepoSSH

func CloneOrOpenDefaultGitHubRepoSSH(repoPath string) (*Repo, error)

CloneOrOpenDefaultGitHubRepoSSH clones the default Kubernetes GitHub repository via SSH if the repoPath is empty, otherwise updates it at the expected repoPath.

func CloneOrOpenGitHubRepo

func CloneOrOpenGitHubRepo(repoPath, owner, repo string, useSSH bool) (*Repo, error)

CloneOrOpenGitHubRepo works with a repository in the given directory, or creates one if the directory is empty. The repo uses the provided GitHub repository via the owner and repo. If useSSH is true, then it will clone the repository using the defaultGithubAuthRoot.

func CloneOrOpenRepo

func CloneOrOpenRepo(repoPath, repoURL string, useSSH, updateRepo bool, opts *git.CloneOptions) (*Repo, error)

CloneOrOpenRepo creates a temp directory containing the provided GitHub repository via the url.

If a repoPath is given, then the function tries to update the repository.

The function returns the repository if cloning or updating of the repository was successful, otherwise an error.

func OpenRepo

func OpenRepo(repoPath string) (*Repo, error)

OpenRepo tries to open the provided repoPath.

func ShallowCleanCloneGitHubRepo added in v0.11.0

func ShallowCleanCloneGitHubRepo(owner, repo string, useSSH bool) (*Repo, error)

ShallowCleanCloneGitHubRepo creates a guaranteed fresh checkout of a GitHub repository. The returned *Repo has a Cleanup() method that should be used to delete the repository on-disk after it is no longer needed.

func ShallowCloneOrOpenGitHubRepo added in v0.11.0

func ShallowCloneOrOpenGitHubRepo(owner, repoPath string, useSSH bool) (*Repo, error)

ShallowCloneOrOpenGitHubRepo this is the *GitHub* counterpart of ShallowCloneOrOpenRepo. It works exactly the same but it takes a GitHub org and repo instead of a URL.

func ShallowCloneOrOpenRepo added in v0.11.0

func ShallowCloneOrOpenRepo(repoPath, repoURL string, useSSH bool) (*Repo, error)

ShallowCloneOrOpenRepo clones performs a shallow clone of a repository (a clone of depth 1). It is almost identical to CloneOrOpenRepo. If a repository already exists in repoPath, then no clone is done and the function returns the existing repository.

func (*Repo) Add

func (r *Repo) Add(filename string) error

Add adds a file to the staging area of the repo.

func (*Repo) AddRemote

func (r *Repo) AddRemote(name, owner, repo string, useSSH bool) error

AddRemote adds a new remote to the current working tree.

func (*Repo) Branch

func (r *Repo) Branch(args ...string) (string, error)

Branch can be used to run `git branch` with the provided args on the repository.

func (*Repo) Checkout

func (r *Repo) Checkout(rev string, args ...string) error

Checkout can be used to checkout any revision inside the repository.

func (*Repo) Cleanup

func (r *Repo) Cleanup() error

func (*Repo) Commit

func (r *Repo) Commit(msg string) error

Commit commits the current repository state.

func (*Repo) CommitEmpty

func (r *Repo) CommitEmpty(msg string) error

CommitEmpty commits an empty commit into the repository.

func (*Repo) CommitWithOptions

func (r *Repo) CommitWithOptions(msg string, options *git.CommitOptions) error

CommitWithOptions commits the current repository state.

func (*Repo) CurrentBranch

func (r *Repo) CurrentBranch() (branch string, err error)

CurrentBranch returns the current branch of the repository or an error in case of any failure.

func (*Repo) Describe

func (r *Repo) Describe(opts *DescribeOptions) (string, error)

Describe runs `git describe` with the provided arguments.

func (*Repo) Dir

func (r *Repo) Dir() string

Dir returns the directory where the repository is stored on disk.

func (*Repo) FetchRemote

func (r *Repo) FetchRemote(remoteName string) (bool, error)

FetchRemote gets the objects from the specified remote. It returns true as first argument if something has been fetched remotely.

func (*Repo) HasBranch

func (r *Repo) HasBranch(branch string) (branchExists bool, err error)

HasBranch checks if a branch exists in the repo.

func (*Repo) HasRemote

func (r *Repo) HasRemote(name, expectedURL string) bool

HasRemote checks if the provided remote `name` is available and matches the expected `url`.

func (*Repo) HasRemoteBranch

func (r *Repo) HasRemoteBranch(branch string) (branchExists bool, err error)

HasRemoteBranch takes a branch string and verifies that it exists on the default remote.

func (*Repo) HasRemoteTag

func (r *Repo) HasRemoteTag(tag string) (hasTag bool, err error)

HasRemoteTag Checks if the default remote already has a tag.

func (*Repo) Head

func (r *Repo) Head() (string, error)

Head retrieves the current repository HEAD as a string.

func (*Repo) IsDirty

func (r *Repo) IsDirty() (bool, error)

IsDirty returns true if the worktree status is not clean. It can also error if the worktree status is not retrievable.

func (*Repo) LastCommitSha

func (r *Repo) LastCommitSha() (string, error)

LastCommitSha returns the sha of the last commit in the repository.

func (*Repo) LatestNonPatchFinalToMinor

func (r *Repo) LatestNonPatchFinalToMinor() (DiscoverResult, error)

func (*Repo) LatestPatchToLatest

func (r *Repo) LatestPatchToLatest(branch string) (DiscoverResult, error)

LatestPatchToLatest tries to discover the start (latest v1.x.x]) and end (release-1.x or DefaultBranch) revision inside the repository for the specified release branch.

func (*Repo) LatestPatchToPatch

func (r *Repo) LatestPatchToPatch(branch string) (DiscoverResult, error)

LatestPatchToPatch tries to discover the start (latest v1.x.[x-1]) and end (latest v1.x.x) revision inside the repository for the specified release branch.

func (*Repo) LatestReleaseBranch added in v0.6.0

func (r *Repo) LatestReleaseBranch() (string, error)

LatestReleaseBranch determines the latest release-x.y branch of the repo.

func (*Repo) LatestReleaseBranchMergeBaseToLatest

func (r *Repo) LatestReleaseBranchMergeBaseToLatest() (DiscoverResult, error)

LatestReleaseBranchMergeBaseToLatest tries to discover the start (latest v1.x.0 merge base) and end (release-1.(x+1) or DefaultBranch) revision inside the repository.

func (*Repo) LatestTagForBranch

func (r *Repo) LatestTagForBranch(branch string) (tag semver.Version, err error)

LatestTagForBranch returns the latest available semver tag for a given branch.

func (*Repo) LsRemote

func (r *Repo) LsRemote(args ...string) (output string, err error)

LsRemote can be used to run `git ls-remote` with the provided args on the repository.

func (*Repo) Merge

func (r *Repo) Merge(from string) error

Merge does a git merge into the current branch from the provided one.

func (*Repo) MergeBase

func (r *Repo) MergeBase(from, to string) (string, error)

func (*Repo) NextCommit added in v0.12.0

func (r *Repo) NextCommit(rev, branch string) (string, error)

NextCommit determines the next child commit for the provided rev and branch.

func (*Repo) PreviousTag

func (r *Repo) PreviousTag(tag, branch string) (string, error)

PreviousTag tries to find the previous tag for a provided branch and errors on any failure.

func (*Repo) Push

func (r *Repo) Push(remoteBranch string) (err error)

Push does push the specified branch to the default remote, but only if the repository is not in dry run mode.

func (*Repo) PushToRemote

func (r *Repo) PushToRemote(remote, remoteBranch string) error

PushToRemote push the current branch to a specified remote, but only if the repository is not in dry run mode.

func (*Repo) PushToRemoteWithOptions added in v0.11.0

func (r *Repo) PushToRemoteWithOptions(pushOptions *git.PushOptions) error

PushToRemote push the current branch to a specified remote, but only if the repository is not in dry run mode.

func (*Repo) Rebase

func (r *Repo) Rebase(branch string) error

Rebase calls rebase on the current repo to the specified branch.

func (*Repo) RemoteBranches added in v0.6.0

func (r *Repo) RemoteBranches() (branches []string, err error)

RemoteBranches returns a list of all remotely available branches.

func (*Repo) RemoteTags

func (r *Repo) RemoteTags() (tags []string, err error)

RemoteTags return the tags that currently exist in the.

func (*Repo) Remotes

func (r *Repo) Remotes() (res []*Remote, err error)

Remotes lists the currently available remotes for the repository.

func (*Repo) RevParse

func (r *Repo) RevParse(rev string) (string, error)

RevParse parses a git revision and returns a SHA1 on success, otherwise an error.

func (*Repo) RevParseShort

func (r *Repo) RevParseShort(rev string) (string, error)

RevParseShort parses a git revision and returns a SHA1 trimmed to the length 10 on success, otherwise an error.

func (*Repo) RevParseTag

func (r *Repo) RevParseTag(rev string) (string, error)

RevParseTag parses a git revision and returns a SHA1 on success, otherwise an error. If the revision does not match a tag add the remote origin in the revision.

func (*Repo) RevParseTagShort

func (r *Repo) RevParseTagShort(rev string) (string, error)

RevParseTagShort parses a git revision and returns a SHA1 trimmed to the length 10 on success, otherwise an error. If the revision does not match a tag add the remote origin in the revision.

func (*Repo) Rm

func (r *Repo) Rm(force bool, files ...string) error

Rm removes files from the repository.

func (*Repo) SetDry

func (r *Repo) SetDry()

SetDry sets the repo to dry-run mode, which does not modify any remote locations at all.

func (*Repo) SetInnerRepo

func (r *Repo) SetInnerRepo(repo Repository)

SetInnerRepo can be used to manually set the inner repository.

func (*Repo) SetMaxRetries

func (r *Repo) SetMaxRetries(numRetries int)

SetMaxRetries defines the number of times, the git client will retry some operations when timing out or network failures. Setting it to 0 disables retrying.

func (*Repo) SetURL

func (r *Repo) SetURL(remote, newURL string) error

SetURL can be used to overwrite the URL for a remote.

func (*Repo) SetWorktree

func (r *Repo) SetWorktree(worktree Worktree)

SetWorktree can be used to manually set the repository worktree.

func (*Repo) ShowLastCommit

func (r *Repo) ShowLastCommit() (logData string, err error)

ShowLastCommit is a simple function that runs git show and returns the last commit in the log.

func (*Repo) Status

func (r *Repo) Status() (*git.Status, error)

Status reads and returns the Status object from the repository.

func (*Repo) Tag

func (r *Repo) Tag(name, message string) error

Tag creates a new annotated tag for the provided `name` and `message`.

func (*Repo) Tags

func (r *Repo) Tags() (res []string, err error)

Tags returns a list of tags for the repository.

func (*Repo) TagsForBranch

func (r *Repo) TagsForBranch(branch string) (res []string, err error)

TagsForBranch returns a list of tags for the provided branch sorted by creation date.

func (*Repo) UserCommit

func (r *Repo) UserCommit(msg string) error

UserCommit makes a commit using the local user's config as well as adding the Signed-off-by line to the commit message.

type Repository

type Repository interface {
	CreateTag(string, plumbing.Hash, *git.CreateTagOptions) (*plumbing.Reference, error)
	Branches() (storer.ReferenceIter, error)
	CommitObject(plumbing.Hash) (*object.Commit, error)
	CreateRemote(*config.RemoteConfig) (*git.Remote, error)
	DeleteRemote(name string) error
	Push(o *git.PushOptions) error
	Head() (*plumbing.Reference, error)
	Remote(string) (*git.Remote, error)
	Remotes() ([]*git.Remote, error)
	ResolveRevision(plumbing.Revision) (*plumbing.Hash, error)
	Tags() (storer.ReferenceIter, error)
}

Repository is the main interface to the git.Repository functionality

type Worktree

type Worktree interface {
	Add(string) (plumbing.Hash, error)
	Commit(string, *git.CommitOptions) (plumbing.Hash, error)
	Checkout(*git.CheckoutOptions) error
	Status() (git.Status, error)
}

Worktree is the main interface to the git.Worktree functionality

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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