git

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package git provides a client to plugins that can do git operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client can clone repos. It keeps a local cache, so successive clones of the same repo should be quick. Create with NewClient. Be sure to clean it up.

func NewClient

func NewClient() (*Client, error)

NewClient returns a client that talks to GitHub. It will fail if git is not in the PATH.

func (*Client) Clean

func (c *Client) Clean() error

Clean removes the local repo cache. The Client is unusable after calling.

func (*Client) Clone

func (c *Client) Clone(repo string) (*Repo, error)

Clone clones a repository. Pass the full repository name, such as "kubernetes/test-infra" as the repo. This function may take a long time if it is the first time cloning the repo. In that case, it must do a full git mirror clone. For large repos, this can take a while. Once that is done, it will do a git fetch instead of a clone, which will usually take at most a few seconds.

func (*Client) SetCredentials

func (c *Client) SetCredentials(user string, tokenGenerator func() []byte)

SetCredentials sets credentials in the client to be used for pushing to or pulling from remote repositories.

func (*Client) SetRemote

func (c *Client) SetRemote(remote string)

SetRemote sets the remote for the client. This is not thread-safe, and is useful for testing. The client will clone from remote/org/repo, and Repo objects spun out of the client will also hit that path.

type Repo

type Repo struct {
	// Dir is the location of the git repo.
	Dir string
	// contains filtered or unexported fields
}

Repo is a clone of a git repository. Create with Client.Clone, and don't forget to clean it up after.

func (*Repo) Am

func (r *Repo) Am(path string) error

Am tries to apply the patch in the given path into the current branch by performing a three-way merge (similar to git cherry-pick). It returns an error if the patch cannot be applied.

func (*Repo) Checkout

func (r *Repo) Checkout(commitlike string) error

Checkout runs git checkout.

func (*Repo) CheckoutNewBranch

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

CheckoutNewBranch creates a new branch and checks it out.

func (*Repo) CheckoutPullRequest

func (r *Repo) CheckoutPullRequest(number int) error

CheckoutPullRequest does exactly that.

func (*Repo) Clean

func (r *Repo) Clean() error

Clean deletes the repo. It is unusable after calling.

func (*Repo) Config

func (r *Repo) Config(key, value string) error

Config runs git config.

func (*Repo) Merge

func (r *Repo) Merge(commitlike string) (bool, error)

Merge attempts to merge commitlike into the current branch. It returns true if the merge completes. It returns an error if the abort fails.

func (*Repo) Push

func (r *Repo) Push(repo, branch string) error

Push pushes over https to the provided owner/repo#branch using a password for basic auth.

func (*Repo) RevParse

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

RevParse runs git rev-parse.

Directories

Path Synopsis
Package localgit creates a local git repo that can be used for testing code that uses a git.Client.
Package localgit creates a local git repo that can be used for testing code that uses a git.Client.

Jump to

Keyboard shortcuts

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