git

package
v0.0.0-...-61a96ab Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDirtyBranch is returned if the branch is dirty.
	ErrDirtyBranch = errors.New("dirty branch")

	// ErrInvalidBranch is returned if the branch does not exist.
	ErrInvalidBranch = errors.New("invalid branch")
)
View Source
var ErrUninitializedAuth = errors.New("uninitialized auth")

ErrUninitializedAuth is returned if the auth object was not set.

Functions

This section is empty.

Types

type Client

type Client interface {
	// NewFile creates a new file in git workspace.
	NewFile(name string, body []byte) error

	// ReadFile reads a file from a git workspace.
	ReadFile(path string) ([]byte, error)

	// Clone the repository from url.
	Clone(url string, progress io.Writer) (err error)

	// CreateBranch creates a local branch.
	CreateBranch(name string) error

	// DiffCommits compares 2 commits and returns the difference.
	DiffCommits(commitAHash, commitBHash string, files ...string) (bool, string, error)

	// Checkout to a git branch
	Checkout(branch string, create, force bool) error

	// RemoveBranch removes a local branch.
	RemoveBranch(name string) error

	// RemoveRemoteBranch removes a remote branch.
	RemoveRemoteBranch(name string) error

	// PullMaster pulls and checks out to master branch.
	PullMaster() error

	// ReadDir reads the files/dirs in git workspace.
	ReadDir(path string) ([]os.FileInfo, error)

	// OpenFile opens a file from a git workspace.
	OpenFile(path string) (io.ReadCloser, error)

	// Add works like "git add" to add files to a commit.
	Add(path string) error

	// Commit makes a new commit.
	Commit(msg string) (string, string, error)

	// Push branches to remote repo.
	Push(branches ...string) error

	// Clean returns true if the workspace is clean, similar to "git status"
	Clean() (bool, string, error)
}

Client is an interface which describes a git client.

func New

func New(opts ...Option) (Client, error)

New returns a new instance of Git object.

type Git

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

Git represents an abstraction over git.

func (*Git) Add

func (g *Git) Add(path string) error

Add similar to git add.

func (*Git) Checkout

func (g *Git) Checkout(branch string, create, force bool) error

Checkout to a new branch.

func (*Git) Clean

func (g *Git) Clean() (bool, string, error)

Clean returns true if the branch is clean (e.g. git status)

func (*Git) Clone

func (g *Git) Clone(url string, progress io.Writer) (err error)

Clone clones repository from url.

func (*Git) Commit

func (g *Git) Commit(msg string) (string, string, error)

Commit makes a new git commit.

func (*Git) CreateBranch

func (g *Git) CreateBranch(name string) error

CreateBranch creates a new git branch.

func (*Git) DiffCommits

func (g *Git) DiffCommits(commitAHash, commitBHash string, files ...string) (bool, string, error)

DiffCommits commits check the difference between 2 commits. Optionally files can be passed to this function and it will check if the difference was found between commits for specified files. similar to "git diff commitA commitB foo/bar.txt" The function returns 3 values: commitAreTheSame bool, patch string, err error

func (*Git) NewFile

func (g *Git) NewFile(name string, body []byte) error

NewFile creates a new file in git workspace

func (*Git) OpenFile

func (g *Git) OpenFile(path string) (io.ReadCloser, error)

OpenFile opens a new file from git workspace. The caller is responsible for closing it.

func (*Git) PullMaster

func (g *Git) PullMaster() error

PullMaster pulls the latest changes from master branch.

func (*Git) Push

func (g *Git) Push(branches ...string) error

Push to remote repo.

func (*Git) ReadDir

func (g *Git) ReadDir(path string) ([]os.FileInfo, error)

ReadDir reads the directory and returns a list of FileInfos.

func (*Git) ReadFile

func (g *Git) ReadFile(path string) ([]byte, error)

ReadFile reads a file from git workspace

func (*Git) RemoveBranch

func (g *Git) RemoveBranch(name string) error

RemoveBranch removes a git branch.

func (*Git) RemoveRemoteBranch

func (g *Git) RemoveRemoteBranch(name string) error

RemoveRemoteBranch removes the branch from remote git repo.

type Option

type Option func(*Git) error

Option is a functional parameter.

func WithGitUserEmail

func WithGitUserEmail(user, email string) Option

WithGitUserEmail configures user and email for git commits.

func WithIgnoreKnownHosts

func WithIgnoreKnownHosts(ignore bool) Option

WithIgnoreKnownHosts is a functional option used to disable ssh known hosts option.

func WithRSAKey

func WithRSAKey(user, password string, privateKeyBody []byte) Option

WithRSAKey is a option to configure git client with RSA key.

Jump to

Keyboard shortcuts

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