cm

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package cm provides worktree management functionality and error definitions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Git repository errors.
	ErrGitRepositoryNotFound     = errors.New("not a valid Git repository: .git directory not found")
	ErrGitRepositoryNotDirectory = errors.New("not a valid Git repository: .git exists but is not a directory")
	ErrGitRepositoryInvalid      = errors.New("not a valid Git repository")

	// Repository and branch errors.
	ErrRepositoryURLEmpty                   = errors.New("repository URL cannot be empty")
	ErrRepositoryNameEmptyAfterSanitization = errors.New("repository name is empty after sanitization")

	// Workspace errors.
	ErrWorkspaceFileMalformed            = errors.New("invalid .code-workspace file: malformed JSON")
	ErrRepositoryNotFoundInWorkspace     = errors.New("repository not found in workspace")
	ErrInvalidRepositoryInWorkspace      = errors.New("invalid repository in workspace")
	ErrInvalidRepositoryInWorkspaceNoGit = errors.New("invalid repository in workspace - .git directory not found")
	ErrMultipleWorkspaces                = errors.New("failed to handle multiple workspaces")
	ErrWorkspaceFileRead                 = errors.New("failed to parse workspace file")
	ErrWorkspaceFileReadError            = errors.New("failed to read workspace file")
	ErrWorkspaceDetection                = errors.New("failed to detect workspace mode")
	ErrWorkspaceEmptyFolders             = errors.New("workspace file must contain non-empty folders array")

	// Worktree creation errors.
	ErrWorktreeExists     = errors.New("worktree already exists for this branch")
	ErrRepositoryNotClean = errors.New("repository is not in a clean state")
	ErrDirectoryExists    = errors.New("worktree directory already exists")

	// Worktree deletion errors.
	ErrWorktreeNotInStatus      = errors.New("worktree not found in status file")
	ErrDeletionCancelled        = errors.New("deletion cancelled by user")
	ErrWorktreeValidationFailed = errors.New("worktree validation failed")

	// Load branch errors.
	ErrInvalidArgumentFormat   = errors.New("invalid argument format")
	ErrEmptyRemoteSource       = errors.New("empty remote source")
	ErrEmptyBranchName         = errors.New("empty branch name")
	ErrBranchNameContainsColon = errors.New("branch name contains invalid character ':'")
	ErrOriginRemoteNotFound    = errors.New("origin remote not found or invalid")
	ErrOriginRemoteInvalidURL  = errors.New("origin remote URL is not a valid Git hosting service URL")

	// Initialization errors.
	ErrAlreadyInitialized     = errors.New("CM is already initialized")
	ErrNotInitialized         = errors.New("CM is not initialized")
	ErrFailedToExpandBasePath = errors.New("failed to expand base path")

	// Project detection errors.
	ErrNoGitRepositoryOrWorkspaceFound = errors.New("no Git repository or workspace found")
	ErrWorkspaceModeNotSupported       = errors.New("workspace mode not yet supported for load command")

	// Clone errors.
	ErrRepositoryExists = errors.New("repository already exists")
)

Error definitions for cm package.

Functions

This section is empty.

Types

type CM

type CM interface {
	// CreateWorkTree executes the main application logic.
	CreateWorkTree(branch string, opts ...CreateWorkTreeOpts) error
	// DeleteWorkTree deletes a worktree for the specified branch.
	DeleteWorkTree(branch string, force bool) error
	// OpenWorktree opens an existing worktree in the specified IDE.
	OpenWorktree(worktreeName, ideName string) error
	// ListWorktrees lists worktrees for the current project with mode detection.
	ListWorktrees(force bool) ([]status.WorktreeInfo, ProjectType, error)
	// LoadWorktree loads a branch from a remote source and creates a worktree.
	LoadWorktree(branchArg string, opts ...LoadWorktreeOpts) error
	// Init initializes CM configuration.
	Init(opts InitOpts) error
	// Clone clones a repository and initializes it in CM.
	Clone(repoURL string, opts ...CloneOpts) error
	// ListRepositories lists all repositories from the status file with base path validation.
	ListRepositories() ([]RepositoryInfo, error)
	// SetVerbose enables or disables verbose mode.
	SetVerbose(verbose bool)
	// Hook management methods
	RegisterHook(operation string, hook hooks.Hook) error
	UnregisterHook(operation, hookName string) error
}

CM interface provides Git repository detection functionality.

func NewCM

func NewCM(cfg *config.Config) (CM, error)

NewCM creates a new CM instance.

func NewCMWithDependencies

func NewCMWithDependencies(params NewCMParams) CM

NewCMWithDependencies creates a new CM instance with custom repository and workspace dependencies. This is primarily used for testing with mocked dependencies.

type CloneOpts

type CloneOpts struct {
	Recursive bool // defaults to true
}

CloneOpts contains optional parameters for Clone.

type CreateWorkTreeOpts

type CreateWorkTreeOpts struct {
	IDEName  string
	IssueRef string
	Force    bool
}

CreateWorkTreeOpts contains optional parameters for CreateWorkTree.

type InitOpts

type InitOpts struct {
	Force          bool
	Reset          bool
	BasePath       string
	NonInteractive bool
}

InitOpts contains optional parameters for Init.

type LoadWorktreeOpts

type LoadWorktreeOpts struct {
	IDEName string
}

LoadWorktreeOpts contains optional parameters for LoadWorktree.

type NewCMParams

type NewCMParams struct {
	Repository  repository.Repository
	Workspace   workspace.Workspace
	Config      *config.Config
	HookManager hooks.HookManagerInterface // Optional: for testing with mocked hooks
}

NewCMParams contains parameters for creating a new CM instance.

type ProjectType

type ProjectType int

ProjectType represents the type of project detected.

const (
	ProjectTypeNone ProjectType = iota
	ProjectTypeSingleRepo
	ProjectTypeWorkspace
)

Project type constants.

type RepositoryInfo added in v0.16.0

type RepositoryInfo struct {
	Name       string
	Path       string
	InBasePath bool
}

RepositoryInfo contains information about a repository for display purposes.

Directories

Path Synopsis
Package consts provides operation name constants for the hook system.
Package consts provides operation name constants for the hook system.

Jump to

Keyboard shortcuts

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