git

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(args ...string) (bytes.Buffer, bytes.Buffer, error)

Exec executes git with args. Note that any errors returned also include stderr text.

func HasCommits

func HasCommits() bool

HasCommits returns true if there are commits in the working dir.

func HasRemote

func HasRemote(name string) bool

HasRemote returns true if name has been configured as a remote.

func IsDirty

func IsDirty() bool

IsDirty returns true if there are uncommitted files.

func IsInitialized

func IsInitialized() bool

IsInitialized returns true if the working dir has been initialized.

func IsInstalled

func IsInstalled() bool

IsInstalled returns true if git is installed.

func StatusLines

func StatusLines() ([]string, error)

StatusLines returns the result of `git status --porcelain`.

Types

type Client

type Client interface {
	// Exec executes git with args.
	Exec(args ...string) (bytes.Buffer, bytes.Buffer, error)
	// HasCommits returns true if there are commits in the working dir.
	HasCommits() bool
	// HasRemote returns true if name has been configured as a remote.
	HasRemote(name string) bool
	// IsDirty returns true if there are uncommitted files.
	IsDirty() bool
	// IsInitialized returns true if the working dir has been initialized.
	IsInitialized() bool
	// IsInstalled returns true if git is installed.
	IsInstalled() bool
	// StatusLines returns the result of `git status --porcelain`.
	StatusLines() ([]string, error)
}

A git CLI client.

var (
	// DefaultClient is the default Git client.
	DefaultClient Client = &systemClient{}
)

type ClientMock

type ClientMock struct {
	// ExecFunc mocks the Exec method.
	ExecFunc func(args ...string) (bytes.Buffer, bytes.Buffer, error)

	// HasCommitsFunc mocks the HasCommits method.
	HasCommitsFunc func() bool

	// HasRemoteFunc mocks the HasRemote method.
	HasRemoteFunc func(name string) bool

	// IsDirtyFunc mocks the IsDirty method.
	IsDirtyFunc func() bool

	// IsInitializedFunc mocks the IsInitialized method.
	IsInitializedFunc func() bool

	// IsInstalledFunc mocks the IsInstalled method.
	IsInstalledFunc func() bool

	// StatusLinesFunc mocks the StatusLines method.
	StatusLinesFunc func() ([]string, error)
	// contains filtered or unexported fields
}

ClientMock is a mock implementation of Client.

func TestSomethingThatUsesClient(t *testing.T) {

	// make and configure a mocked Client
	mockedClient := &ClientMock{
		ExecFunc: func(args ...string) (bytes.Buffer, bytes.Buffer, error) {
			panic("mock out the Exec method")
		},
		HasCommitsFunc: func() bool {
			panic("mock out the HasCommits method")
		},
		HasRemoteFunc: func(name string) bool {
			panic("mock out the HasRemote method")
		},
		IsDirtyFunc: func() bool {
			panic("mock out the IsDirty method")
		},
		IsInitializedFunc: func() bool {
			panic("mock out the IsInitialized method")
		},
		IsInstalledFunc: func() bool {
			panic("mock out the IsInstalled method")
		},
		StatusLinesFunc: func() ([]string, error) {
			panic("mock out the StatusLines method")
		},
	}

	// use mockedClient in code that requires Client
	// and then make assertions.

}

func (*ClientMock) Exec

func (mock *ClientMock) Exec(args ...string) (bytes.Buffer, bytes.Buffer, error)

Exec calls ExecFunc.

func (*ClientMock) ExecCalls

func (mock *ClientMock) ExecCalls() []struct {
	Args []string
}

ExecCalls gets all the calls that were made to Exec. Check the length with:

len(mockedClient.ExecCalls())

func (*ClientMock) HasCommits

func (mock *ClientMock) HasCommits() bool

HasCommits calls HasCommitsFunc.

func (*ClientMock) HasCommitsCalls

func (mock *ClientMock) HasCommitsCalls() []struct {
}

HasCommitsCalls gets all the calls that were made to HasCommits. Check the length with:

len(mockedClient.HasCommitsCalls())

func (*ClientMock) HasRemote

func (mock *ClientMock) HasRemote(name string) bool

HasRemote calls HasRemoteFunc.

func (*ClientMock) HasRemoteCalls

func (mock *ClientMock) HasRemoteCalls() []struct {
	Name string
}

HasRemoteCalls gets all the calls that were made to HasRemote. Check the length with:

len(mockedClient.HasRemoteCalls())

func (*ClientMock) IsDirty

func (mock *ClientMock) IsDirty() bool

IsDirty calls IsDirtyFunc.

func (*ClientMock) IsDirtyCalls

func (mock *ClientMock) IsDirtyCalls() []struct {
}

IsDirtyCalls gets all the calls that were made to IsDirty. Check the length with:

len(mockedClient.IsDirtyCalls())

func (*ClientMock) IsInitialized

func (mock *ClientMock) IsInitialized() bool

IsInitialized calls IsInitializedFunc.

func (*ClientMock) IsInitializedCalls

func (mock *ClientMock) IsInitializedCalls() []struct {
}

IsInitializedCalls gets all the calls that were made to IsInitialized. Check the length with:

len(mockedClient.IsInitializedCalls())

func (*ClientMock) IsInstalled

func (mock *ClientMock) IsInstalled() bool

IsInstalled calls IsInstalledFunc.

func (*ClientMock) IsInstalledCalls

func (mock *ClientMock) IsInstalledCalls() []struct {
}

IsInstalledCalls gets all the calls that were made to IsInstalled. Check the length with:

len(mockedClient.IsInstalledCalls())

func (*ClientMock) StatusLines

func (mock *ClientMock) StatusLines() ([]string, error)

StatusLines calls StatusLinesFunc.

func (*ClientMock) StatusLinesCalls

func (mock *ClientMock) StatusLinesCalls() []struct {
}

StatusLinesCalls gets all the calls that were made to StatusLines. Check the length with:

len(mockedClient.StatusLinesCalls())

Jump to

Keyboard shortcuts

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