cm

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: GPL-3.0 Imports: 23 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 ':'")
	ErrArgumentEmpty            = errors.New("argument cannot be empty")
	ErrOriginRemoteNotFound     = errors.New("origin remote not found or invalid")
	ErrOriginRemoteInvalidURL   = errors.New("origin remote URL is not a valid Git hosting service URL")
	ErrFailedToLoadRepositories = errors.New("failed to load repositories from status file")

	// Initialization errors.
	ErrAlreadyInitialized            = errors.New("CM is already initialized")
	ErrNotInitialized                = errors.New("CM is not initialized")
	ErrFailedToExpandRepositoriesDir = errors.New("failed to expand repositories directory")

	// 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")
	ErrUnsupportedRepositoryURLFormat = errors.New("unsupported repository URL format")

	// Clone operation errors.
	ErrFailedToDetectDefaultBranch  = errors.New("failed to detect default branch")
	ErrFailedToCloneRepository      = errors.New("failed to clone repository")
	ErrFailedToInitializeRepository = errors.New("failed to initialize repository in CM")

	// Workspace creation errors.
	ErrInvalidWorkspaceName   = errors.New("invalid workspace name")
	ErrRepositoryNotFound     = errors.New("repository not found")
	ErrInvalidRepository      = errors.New("invalid repository")
	ErrDuplicateRepository    = errors.New("duplicate repository")
	ErrWorkspaceAlreadyExists = errors.New("workspace already exists")
	ErrStatusUpdate           = errors.New("status file update failed")
	ErrRepositoryAddition     = errors.New("failed to add repository to status file")
	ErrPathResolution         = errors.New("path resolution failed")
)

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
	// DeleteWorkTrees deletes multiple worktrees for the specified branches.
	DeleteWorkTrees(branches []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, mode.Mode, 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)
	// CreateWorkspace creates a new workspace with repository selection.
	CreateWorkspace(params CreateWorkspaceParams) error
	// SetLogger sets the logger for this CM instance.
	SetLogger(logger logger.Logger)
	// 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(params NewCMParams) (CM, error)

NewCM creates a new CM instance.

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
	WorkspaceName string
	Force         bool
}

CreateWorkTreeOpts contains optional parameters for CreateWorkTree.

type CreateWorkspaceParams added in v0.22.0

type CreateWorkspaceParams struct {
	WorkspaceName string   // Name of the workspace
	Repositories  []string // Repository identifiers (names, paths, URLs)
}

CreateWorkspaceParams contains parameters for CreateWorkspace.

type InitOpts

type InitOpts struct {
	Force           bool
	Reset           bool
	RepositoriesDir string
	WorkspacesDir   string
	StatusFile      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 {
	RepositoryProvider RepositoryProvider
	WorkspaceProvider  WorkspaceProvider
	Config             config.Config
	Hooks              hooks.HookManagerInterface
	Status             status.Manager
	FS                 fs.FS
	Git                git.Git
	Logger             logger.Logger
	Prompt             prompt.Prompter
}

NewCMParams contains parameters for creating a new CM instance.

type RepositoryInfo added in v0.16.0

type RepositoryInfo struct {
	Name              string
	Path              string
	InRepositoriesDir bool
}

RepositoryInfo contains information about a repository for display purposes.

type RepositoryProvider added in v0.22.0

type RepositoryProvider func(params repository.NewRepositoryParams) repository.Repository

RepositoryProvider is a function type that creates repository instances.

type WorkspaceProvider added in v0.22.0

type WorkspaceProvider func(params workspace.NewWorkspaceParams) workspace.Workspace

WorkspaceProvider is a function type that creates workspace instances.

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