worktree

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: 7 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) Create

func (c *CLIOperations) Create(ctx context.Context, repoPath, worktreePath, branch, baseBranch string) error

Create implements Operations.Create.

func (*CLIOperations) CreateFromExisting

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

CreateFromExisting implements Operations.CreateFromExisting.

func (*CLIOperations) ExistsPath

func (c *CLIOperations) ExistsPath(worktreePath string) bool

ExistsPath implements Operations.ExistsPath.

func (*CLIOperations) List

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

List implements Operations.List.

func (*CLIOperations) RemoveForce

func (c *CLIOperations) RemoveForce(ctx context.Context, repoPath, worktreePath string) error

RemoveForce implements Operations.RemoveForce.

type Operations

type Operations interface {
	// Create creates a new worktree at worktreePath from repoPath with a new branch.
	Create(ctx context.Context, repoPath, worktreePath, branch, baseBranch string) error
	// CreateFromExisting creates a worktree at worktreePath for an existing branch.
	CreateFromExisting(ctx context.Context, repoPath, worktreePath, branch string) error
	// RemoveForce forcefully removes a worktree even if it has uncommitted changes.
	RemoveForce(ctx context.Context, repoPath, worktreePath string) error
	// List returns all worktrees for the given repository.
	List(ctx context.Context, repoPath string) ([]Worktree, error)
	// ExistsPath checks if the worktree path exists on disk.
	ExistsPath(worktreePath string) bool
}

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

func NewOperations

func NewOperations() Operations

NewOperations creates a new Operations implementation using the git CLI.

type Worktree

type Worktree struct {
	Path   string // Absolute path to the worktree
	HEAD   string // Current HEAD commit SHA
	Branch string // Branch name (empty if detached)
}

Worktree represents a git worktree.

type WorktreeOperationsMock

type WorktreeOperationsMock struct {
	// CreateFunc mocks the Create method.
	CreateFunc func(ctx context.Context, repoPath string, worktreePath string, branch string, baseBranch string) error

	// CreateFromExistingFunc mocks the CreateFromExisting method.
	CreateFromExistingFunc func(ctx context.Context, repoPath string, worktreePath string, branch string) error

	// ExistsPathFunc mocks the ExistsPath method.
	ExistsPathFunc func(worktreePath string) bool

	// ListFunc mocks the List method.
	ListFunc func(ctx context.Context, repoPath string) ([]Worktree, error)

	// RemoveForceFunc mocks the RemoveForce method.
	RemoveForceFunc func(ctx context.Context, repoPath string, worktreePath string) error
	// contains filtered or unexported fields
}

WorktreeOperationsMock is a mock implementation of Operations.

func TestSomethingThatUsesOperations(t *testing.T) {

	// make and configure a mocked Operations
	mockedOperations := &WorktreeOperationsMock{
		CreateFunc: func(ctx context.Context, repoPath string, worktreePath string, branch string, baseBranch string) error {
			panic("mock out the Create method")
		},
		CreateFromExistingFunc: func(ctx context.Context, repoPath string, worktreePath string, branch string) error {
			panic("mock out the CreateFromExisting method")
		},
		ExistsPathFunc: func(worktreePath string) bool {
			panic("mock out the ExistsPath method")
		},
		ListFunc: func(ctx context.Context, repoPath string) ([]Worktree, error) {
			panic("mock out the List method")
		},
		RemoveForceFunc: func(ctx context.Context, repoPath string, worktreePath string) error {
			panic("mock out the RemoveForce method")
		},
	}

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

}

func (*WorktreeOperationsMock) Create

func (mock *WorktreeOperationsMock) Create(ctx context.Context, repoPath string, worktreePath string, branch string, baseBranch string) error

Create calls CreateFunc.

func (*WorktreeOperationsMock) CreateCalls

func (mock *WorktreeOperationsMock) CreateCalls() []struct {
	Ctx          context.Context
	RepoPath     string
	WorktreePath string
	Branch       string
	BaseBranch   string
}

CreateCalls gets all the calls that were made to Create. Check the length with:

len(mockedOperations.CreateCalls())

func (*WorktreeOperationsMock) CreateFromExisting

func (mock *WorktreeOperationsMock) CreateFromExisting(ctx context.Context, repoPath string, worktreePath string, branch string) error

CreateFromExisting calls CreateFromExistingFunc.

func (*WorktreeOperationsMock) CreateFromExistingCalls

func (mock *WorktreeOperationsMock) CreateFromExistingCalls() []struct {
	Ctx          context.Context
	RepoPath     string
	WorktreePath string
	Branch       string
}

CreateFromExistingCalls gets all the calls that were made to CreateFromExisting. Check the length with:

len(mockedOperations.CreateFromExistingCalls())

func (*WorktreeOperationsMock) ExistsPath

func (mock *WorktreeOperationsMock) ExistsPath(worktreePath string) bool

ExistsPath calls ExistsPathFunc.

func (*WorktreeOperationsMock) ExistsPathCalls

func (mock *WorktreeOperationsMock) ExistsPathCalls() []struct {
	WorktreePath string
}

ExistsPathCalls gets all the calls that were made to ExistsPath. Check the length with:

len(mockedOperations.ExistsPathCalls())

func (*WorktreeOperationsMock) List

func (mock *WorktreeOperationsMock) List(ctx context.Context, repoPath string) ([]Worktree, error)

List calls ListFunc.

func (*WorktreeOperationsMock) ListCalls

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

ListCalls gets all the calls that were made to List. Check the length with:

len(mockedOperations.ListCalls())

func (*WorktreeOperationsMock) RemoveForce

func (mock *WorktreeOperationsMock) RemoveForce(ctx context.Context, repoPath string, worktreePath string) error

RemoveForce calls RemoveForceFunc.

func (*WorktreeOperationsMock) RemoveForceCalls

func (mock *WorktreeOperationsMock) RemoveForceCalls() []struct {
	Ctx          context.Context
	RepoPath     string
	WorktreePath string
}

RemoveForceCalls gets all the calls that were made to RemoveForce. Check the length with:

len(mockedOperations.RemoveForceCalls())

Jump to

Keyboard shortcuts

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