git

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFile

func AddFile(repositoryPath, path string) error

AddFile will add the the path to the staged index.

func CheckoutBranch

func CheckoutBranch(repositoryPath, branch string) error

func CheckoutCommit

func CheckoutCommit(repositoryPath string, commit gitplumbing.Hash) error

func Commit

func Commit(repositoryPath, message string) (gitplumbing.Hash, error)

Commit attempts to commit the repository.

func CreateBranch

func CreateBranch(repositoryPath, branch string, commit gitplumbing.Hash) error

func GetBranchHeadCommit

func GetBranchHeadCommit(repositoryPath, branch string) (gitplumbing.Hash, error)

func Init

func Init(path string) error

func Tag

func Tag(repositoryPath string, commit gitplumbing.Hash, name string) error

Tag attempts to create a lightweight tag referencing the hash.

func WriteAndAddFile

func WriteAndAddFile(repositoryPath, path string, contents []byte, perm os.FileMode) error

func WriteAndCommitFile

func WriteAndCommitFile(
	repositoryPath string,
	path string,
	contents []byte,
	perm os.FileMode,
	message string,
) (gitplumbing.Hash, error)

func WriteFile

func WriteFile(repositoryPath, path string, contents []byte, perm os.FileMode) error

WriteFile will write the contents to the file in the repository. Currently this does not check to ensure that the path does not escape the directory, so it could be used to write files not in the repository.

Types

type CloneError

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

CloneError is returned when there is an error cloning a repository.

func (*CloneError) Error

func (e *CloneError) Error() string

type CommitReference

type CommitReference struct {
	RepositoryURL string `json:"repositoryUrl"`
	Commit        string `json:"commit"`
}

type Context

type Context struct {
	RepositoryURL string
	Options       *Options
}

Context contains information about the current operation being invoked.

type FetchError

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

FetchError is returned when there is an error fetching.

func (*FetchError) Error

func (e *FetchError) Error() string

type FileReference

type FileReference struct {
	CommitReference
	File string `json:"file"`
}

type Options

type Options struct {
	SSHKey []byte
}

Options contains information about how to complete the operation.

type Reference

type Reference struct {
	Commit  *string
	Branch  *string
	Tag     *string
	Version *string
}

Reference is a union type containing a reference to a commit, tag, or branch.

func (*Reference) Validate

func (r *Reference) Validate() error

type Resolver

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

Resolver provides utility methods for manipulating git repositories under a specific working directory on the filesystem.

func NewResolver

func NewResolver(workDirectory string, allowLocalRepos bool) (*Resolver, error)

func (*Resolver) Checkout

func (r *Resolver) Checkout(ctx *Context, ref *Reference) error

Checkout will clone and fetch, then attempt to check out the ref specified in the context.

func (*Resolver) Clone

func (r *Resolver) Clone(ctx *Context) (*git.Repository, error)

Clone will open the repository and return it If the repository specified in the Context has already been cloned, otherwise it will attempt to clone the repository and on success return the cloned repository

func (*Resolver) Fetch

func (r *Resolver) Fetch(ctx *Context) error

Fetch will clone a repository if necessary, then attempt to fetch the repository from origin

func (*Resolver) FileContents

func (r *Resolver) FileContents(ctx *Context, ref *Reference, fileName string) ([]byte, error)

FileContents will clone, fetch, and checkout the proper reference, and if successful will attempt to return the contents of the file at fileName.

func (*Resolver) GetCommit

func (r *Resolver) GetCommit(ctx *Context, ref *Reference) (*gitplumbingobject.Commit, error)

Commit will parse the Ref (i.e. #<ref>) from the git uri and determine if its a branch/tag/commit. Returns the actual commit object for that ref. Defaults to HEAD. GetCommit will first fetch from origin.

func (*Resolver) IsValidRepositoryURI

func (r *Resolver) IsValidRepositoryURI(uri string) bool

IsValidRepositoryURI returns a boolean indicating whether or not the uri is a valid git repository.

func (*Resolver) RepositoryPath

func (r *Resolver) RepositoryPath(url string) string

func (*Resolver) Tags

func (r *Resolver) Tags(ctx *Context) ([]string, error)

Tags will clone and fetch, and if successful will return the repository's tags (annotated + light-weight).

func (*Resolver) Versions

func (r *Resolver) Versions(ctx *Context, semverRange semver.Range) ([]string, error)

Jump to

Keyboard shortcuts

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