vcs

package
v0.0.0-...-75ec8e3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package vcs provides a version control system abstraction layer. It defines interfaces for common VCS operations, allowing for pluggable implementations.

Index

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

func NewGit(workingDir string) *Git

NewGit creates a new Git VCS instance for the given working directory. The working directory should be within a Git repository.

func (*Git) CreateWorktree

func (g *Git) CreateWorktree(ctx context.Context, sessionName string) (string, error)

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

func (g *Git) CurrentBranch(ctx context.Context) (string, error)

CurrentBranch returns the name of the current branch. Returns an empty string if not in a repository or on a detached HEAD.

func (*Git) IsIgnored

func (g *Git) IsIgnored(ctx context.Context, absPath string) (bool, error)

IsIgnored checks if a file/directory path is ignored by Git. The path should be absolute. Returns false if not in a repository.

func (*Git) RepositoryRoot

func (g *Git) RepositoryRoot(ctx context.Context, dir string) (string, error)

RepositoryRoot returns the root directory of the Git repository containing the current working directory.

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

func (m *MockVCS) CreateWorktree(ctx context.Context, sessionName string) (string, error)

CreateWorktree calls the mock CreateWorktreeFunc if set, otherwise returns empty string.

func (*MockVCS) IsIgnored

func (m *MockVCS) IsIgnored(ctx context.Context, absPath string) (bool, error)

IsIgnored calls the mock IsIgnoredFunc if set, otherwise returns false.

func (*MockVCS) RepositoryRoot

func (m *MockVCS) RepositoryRoot(ctx context.Context, dir string) (string, error)

RepositoryRoot calls the mock RepositoryRootFunc 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.

Jump to

Keyboard shortcuts

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