Documentation
¶
Overview ¶
Package vcs provides a version control system abstraction layer. It defines interfaces for common VCS operations, allowing for pluggable implementations.
Index ¶
- type Git
- func (g *Git) CreateWorktree(ctx context.Context, sessionName string) (string, error)
- func (g *Git) CurrentBranch(ctx context.Context) (string, error)
- func (g *Git) IsIgnored(ctx context.Context, absPath string) (bool, error)
- func (g *Git) RepositoryRoot(ctx context.Context, dir string) (string, error)
- type MockVCS
- type VCS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git implements the VCS interface for Git repositories.
func NewGit ¶
NewGit creates a new Git VCS instance for the given working directory. The working directory should be within a Git repository.
func (*Git) CreateWorktree ¶
CreateWorktree creates a new git worktree with the specified session name. Returns the path to the created worktree. The worktree is created in the parent directory of the repository root, with the naming pattern: {repoName}-{sessionName}.
func (*Git) CurrentBranch ¶
CurrentBranch returns the name of the current branch. Returns an empty string if not in a repository or on a detached HEAD.
type MockVCS ¶
type MockVCS struct {
// RepositoryRootFunc is the mock implementation for RepositoryRoot
RepositoryRootFunc func(ctx context.Context, dir string) (string, error)
// IsIgnoredFunc is the mock implementation for IsIgnored
IsIgnoredFunc func(ctx context.Context, absPath string) (bool, error)
// CreateWorktreeFunc is the mock implementation for CreateWorktree
CreateWorktreeFunc func(ctx context.Context, sessionName string) (string, error)
}
MockVCS is a mock implementation of the VCS interface for testing.
func (*MockVCS) CreateWorktree ¶
CreateWorktree calls the mock CreateWorktreeFunc if set, otherwise returns empty string.
type VCS ¶
type VCS interface {
// RepositoryRoot returns the root directory of the VCS repository
// containing the given directory. Returns an error if not in a repository.
RepositoryRoot(ctx context.Context, dir string) (string, error)
// IsIgnored checks if a file/directory path is ignored by the VCS.
// The path should be absolute. Returns false if not in a repository.
IsIgnored(ctx context.Context, absPath string) (bool, error)
// CreateWorktree creates a new worktree with the specified session name.
// Returns the path to the created worktree.
// Returns an error if worktree creation fails or not in a repository.
CreateWorktree(ctx context.Context, sessionName string) (string, error)
// CurrentBranch returns the name of the current branch.
// Returns an empty string if not in a repository or on a detached HEAD.
CurrentBranch(ctx context.Context) (string, error)
}
VCS represents a version control system. It provides methods for common VCS operations like finding repository roots, checking ignored files, creating worktrees, and getting current branch.