git

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLIOperations

type CLIOperations struct{}

CLIOperations implements Operations using the git CLI.

func (*CLIOperations) BranchExists

func (c *CLIOperations) BranchExists(ctx context.Context, repoPath, branchName string) bool

BranchExists implements Operations.BranchExists.

func (*CLIOperations) Clone

func (c *CLIOperations) Clone(ctx context.Context, source, dest string) error

Clone implements Operations.Clone.

func (*CLIOperations) FetchBranch

func (c *CLIOperations) FetchBranch(ctx context.Context, repoPath, branch string) error

FetchBranch implements Operations.FetchBranch.

func (*CLIOperations) FetchPRRef

func (c *CLIOperations) FetchPRRef(ctx context.Context, repoPath string, prNumber int, localBranch string) error

FetchPRRef implements Operations.FetchPRRef. This fetches a PR's head ref using GitHub's special refs/pull/<n>/head ref and creates or updates a local branch pointing to it.

func (*CLIOperations) ListBranches

func (c *CLIOperations) ListBranches(ctx context.Context, repoPath string) ([]string, error)

ListBranches implements Operations.ListBranches.

func (*CLIOperations) Pull

func (c *CLIOperations) Pull(ctx context.Context, dir string) error

Pull implements Operations.Pull.

func (*CLIOperations) PushSetUpstream

func (c *CLIOperations) PushSetUpstream(ctx context.Context, branch, dir string) error

PushSetUpstream implements Operations.PushSetUpstream.

func (*CLIOperations) ValidateExistingBranch

func (c *CLIOperations) ValidateExistingBranch(ctx context.Context, repoPath, branchName string) (bool, bool, error)

ValidateExistingBranch implements Operations.ValidateExistingBranch.

type GitOperationsMock

type GitOperationsMock struct {
	// BranchExistsFunc mocks the BranchExists method.
	BranchExistsFunc func(ctx context.Context, repoPath string, branchName string) bool

	// CloneFunc mocks the Clone method.
	CloneFunc func(ctx context.Context, source string, dest string) error

	// FetchBranchFunc mocks the FetchBranch method.
	FetchBranchFunc func(ctx context.Context, repoPath string, branch string) error

	// FetchPRRefFunc mocks the FetchPRRef method.
	FetchPRRefFunc func(ctx context.Context, repoPath string, prNumber int, localBranch string) error

	// ListBranchesFunc mocks the ListBranches method.
	ListBranchesFunc func(ctx context.Context, repoPath string) ([]string, error)

	// PullFunc mocks the Pull method.
	PullFunc func(ctx context.Context, dir string) error

	// PushSetUpstreamFunc mocks the PushSetUpstream method.
	PushSetUpstreamFunc func(ctx context.Context, branch string, dir string) error

	// ValidateExistingBranchFunc mocks the ValidateExistingBranch method.
	ValidateExistingBranchFunc func(ctx context.Context, repoPath string, branchName string) (bool, bool, error)
	// contains filtered or unexported fields
}

GitOperationsMock is a mock implementation of Operations.

func TestSomethingThatUsesOperations(t *testing.T) {

	// make and configure a mocked Operations
	mockedOperations := &GitOperationsMock{
		BranchExistsFunc: func(ctx context.Context, repoPath string, branchName string) bool {
			panic("mock out the BranchExists method")
		},
		CloneFunc: func(ctx context.Context, source string, dest string) error {
			panic("mock out the Clone method")
		},
		FetchBranchFunc: func(ctx context.Context, repoPath string, branch string) error {
			panic("mock out the FetchBranch method")
		},
		FetchPRRefFunc: func(ctx context.Context, repoPath string, prNumber int, localBranch string) error {
			panic("mock out the FetchPRRef method")
		},
		ListBranchesFunc: func(ctx context.Context, repoPath string) ([]string, error) {
			panic("mock out the ListBranches method")
		},
		PullFunc: func(ctx context.Context, dir string) error {
			panic("mock out the Pull method")
		},
		PushSetUpstreamFunc: func(ctx context.Context, branch string, dir string) error {
			panic("mock out the PushSetUpstream method")
		},
		ValidateExistingBranchFunc: func(ctx context.Context, repoPath string, branchName string) (bool, bool, error) {
			panic("mock out the ValidateExistingBranch method")
		},
	}

	// use mockedOperations in code that requires Operations
	// and then make assertions.

}

func (*GitOperationsMock) BranchExists

func (mock *GitOperationsMock) BranchExists(ctx context.Context, repoPath string, branchName string) bool

BranchExists calls BranchExistsFunc.

func (*GitOperationsMock) BranchExistsCalls

func (mock *GitOperationsMock) BranchExistsCalls() []struct {
	Ctx        context.Context
	RepoPath   string
	BranchName string
}

BranchExistsCalls gets all the calls that were made to BranchExists. Check the length with:

len(mockedOperations.BranchExistsCalls())

func (*GitOperationsMock) Clone

func (mock *GitOperationsMock) Clone(ctx context.Context, source string, dest string) error

Clone calls CloneFunc.

func (*GitOperationsMock) CloneCalls

func (mock *GitOperationsMock) CloneCalls() []struct {
	Ctx    context.Context
	Source string
	Dest   string
}

CloneCalls gets all the calls that were made to Clone. Check the length with:

len(mockedOperations.CloneCalls())

func (*GitOperationsMock) FetchBranch

func (mock *GitOperationsMock) FetchBranch(ctx context.Context, repoPath string, branch string) error

FetchBranch calls FetchBranchFunc.

func (*GitOperationsMock) FetchBranchCalls

func (mock *GitOperationsMock) FetchBranchCalls() []struct {
	Ctx      context.Context
	RepoPath string
	Branch   string
}

FetchBranchCalls gets all the calls that were made to FetchBranch. Check the length with:

len(mockedOperations.FetchBranchCalls())

func (*GitOperationsMock) FetchPRRef

func (mock *GitOperationsMock) FetchPRRef(ctx context.Context, repoPath string, prNumber int, localBranch string) error

FetchPRRef calls FetchPRRefFunc.

func (*GitOperationsMock) FetchPRRefCalls

func (mock *GitOperationsMock) FetchPRRefCalls() []struct {
	Ctx         context.Context
	RepoPath    string
	PrNumber    int
	LocalBranch string
}

FetchPRRefCalls gets all the calls that were made to FetchPRRef. Check the length with:

len(mockedOperations.FetchPRRefCalls())

func (*GitOperationsMock) ListBranches

func (mock *GitOperationsMock) ListBranches(ctx context.Context, repoPath string) ([]string, error)

ListBranches calls ListBranchesFunc.

func (*GitOperationsMock) ListBranchesCalls

func (mock *GitOperationsMock) ListBranchesCalls() []struct {
	Ctx      context.Context
	RepoPath string
}

ListBranchesCalls gets all the calls that were made to ListBranches. Check the length with:

len(mockedOperations.ListBranchesCalls())

func (*GitOperationsMock) Pull

func (mock *GitOperationsMock) Pull(ctx context.Context, dir string) error

Pull calls PullFunc.

func (*GitOperationsMock) PullCalls

func (mock *GitOperationsMock) PullCalls() []struct {
	Ctx context.Context
	Dir string
}

PullCalls gets all the calls that were made to Pull. Check the length with:

len(mockedOperations.PullCalls())

func (*GitOperationsMock) PushSetUpstream

func (mock *GitOperationsMock) PushSetUpstream(ctx context.Context, branch string, dir string) error

PushSetUpstream calls PushSetUpstreamFunc.

func (*GitOperationsMock) PushSetUpstreamCalls

func (mock *GitOperationsMock) PushSetUpstreamCalls() []struct {
	Ctx    context.Context
	Branch string
	Dir    string
}

PushSetUpstreamCalls gets all the calls that were made to PushSetUpstream. Check the length with:

len(mockedOperations.PushSetUpstreamCalls())

func (*GitOperationsMock) ValidateExistingBranch

func (mock *GitOperationsMock) ValidateExistingBranch(ctx context.Context, repoPath string, branchName string) (bool, bool, error)

ValidateExistingBranch calls ValidateExistingBranchFunc.

func (*GitOperationsMock) ValidateExistingBranchCalls

func (mock *GitOperationsMock) ValidateExistingBranchCalls() []struct {
	Ctx        context.Context
	RepoPath   string
	BranchName string
}

ValidateExistingBranchCalls gets all the calls that were made to ValidateExistingBranch. Check the length with:

len(mockedOperations.ValidateExistingBranchCalls())

type Operations

type Operations interface {
	// PushSetUpstream pushes the specified branch and sets upstream tracking.
	PushSetUpstream(ctx context.Context, branch, dir string) error
	// Pull pulls the latest changes in a specific directory.
	Pull(ctx context.Context, dir string) error
	// Clone clones a repository from source to dest.
	Clone(ctx context.Context, source, dest string) error
	// FetchBranch fetches a specific branch from origin.
	FetchBranch(ctx context.Context, repoPath, branch string) error
	// FetchPRRef fetches a PR's head ref and creates/updates a local branch.
	// This handles both same-repo PRs and fork PRs via GitHub's pull/<n>/head refs.
	FetchPRRef(ctx context.Context, repoPath string, prNumber int, localBranch string) error
	// BranchExists checks if a branch exists locally or remotely.
	BranchExists(ctx context.Context, repoPath, branchName string) bool
	// ValidateExistingBranch checks if a branch exists locally, remotely, or both.
	ValidateExistingBranch(ctx context.Context, repoPath, branchName string) (existsLocal, existsRemote bool, err error)
	// ListBranches returns a deduplicated list of all branches (local and remote).
	ListBranches(ctx context.Context, repoPath string) ([]string, error)
}

Operations defines the interface for git operations. This abstraction enables testing without actual git commands.

func NewOperations

func NewOperations() Operations

NewOperations creates a new Operations implementation using the git CLI.

Jump to

Keyboard shortcuts

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