vcs

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	Hash    string `json:"hash"`
	Author  string `json:"author"`
	Date    string `json:"date"`
	Message string `json:"message"`
}

Commit represents a VCS commit.

type Driver

type Driver interface {
	// Name returns the driver name ("git" or "sl").
	Name() string

	// Clone clones a repository to the given path.
	Clone(ctx context.Context, url, path, branch string) error

	// Pull pulls the current branch from the remote.
	Pull(ctx context.Context, path string) error

	// Push pushes the current branch to the remote.
	Push(ctx context.Context, path string) error

	// Fetch fetches from the remote without merging.
	Fetch(ctx context.Context, path string) error

	// Checkout switches to the given branch.
	// If create is true, creates the branch first.
	Checkout(ctx context.Context, path, branch string, create bool) error

	// Status returns the current status of the repository.
	Status(ctx context.Context, path string) (*RepoStatus, error)

	// Commit creates a commit with the given message.
	// If all is true, stages all modified files first.
	Commit(ctx context.Context, path, message string, all bool) error

	// CurrentBranch returns the name of the current branch.
	CurrentBranch(ctx context.Context, path string) (string, error)

	// Log returns the last n commits.
	Log(ctx context.Context, path string, limit int) ([]Commit, error)

	// Diff returns the diff of uncommitted changes.
	Diff(ctx context.Context, path string) (string, error)

	// Grep searches for a pattern in the repository.
	Grep(ctx context.Context, path, pattern string) ([]GrepResult, error)

	// WorktreeAdd creates a new worktree.
	// Returns the path to the new worktree.
	WorktreeAdd(ctx context.Context, path, name, branch string) (string, error)

	// WorktreeList lists all worktrees.
	WorktreeList(ctx context.Context, path string) ([]Worktree, error)

	// WorktreeRemove removes a worktree.
	WorktreeRemove(ctx context.Context, path, name string) error
}

Driver is the interface for VCS operations. Both git and Sapling implement this interface.

func Detect

func Detect(path string) (Driver, error)

Detect auto-detects the VCS driver for a repository path by checking for .git or .sl directories.

func DetectOrDefault

func DetectOrDefault(path, defaultVCS string) (Driver, error)

DetectOrDefault tries to detect the VCS, falling back to the given default.

func DriverByName

func DriverByName(name string) (Driver, error)

DriverByName returns a driver by name.

type GitDriver

type GitDriver struct{}

GitDriver implements Driver for git.

func NewGitDriver

func NewGitDriver() *GitDriver

func (*GitDriver) Checkout

func (g *GitDriver) Checkout(ctx context.Context, path, branch string, create bool) error

func (*GitDriver) Clone

func (g *GitDriver) Clone(ctx context.Context, url, path, branch string) error

func (*GitDriver) Commit

func (g *GitDriver) Commit(ctx context.Context, path, message string, all bool) error

func (*GitDriver) CurrentBranch

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

func (*GitDriver) Diff

func (g *GitDriver) Diff(ctx context.Context, path string) (string, error)

func (*GitDriver) Fetch

func (g *GitDriver) Fetch(ctx context.Context, path string) error

func (*GitDriver) Grep

func (g *GitDriver) Grep(ctx context.Context, path, pattern string) ([]GrepResult, error)

func (*GitDriver) Log

func (g *GitDriver) Log(ctx context.Context, path string, limit int) ([]Commit, error)

func (*GitDriver) Name

func (g *GitDriver) Name() string

func (*GitDriver) Pull

func (g *GitDriver) Pull(ctx context.Context, path string) error

func (*GitDriver) Push

func (g *GitDriver) Push(ctx context.Context, path string) error

func (*GitDriver) Status

func (g *GitDriver) Status(ctx context.Context, path string) (*RepoStatus, error)

func (*GitDriver) WorktreeAdd

func (g *GitDriver) WorktreeAdd(ctx context.Context, path, name, branch string) (string, error)

func (*GitDriver) WorktreeList

func (g *GitDriver) WorktreeList(ctx context.Context, path string) ([]Worktree, error)

func (*GitDriver) WorktreeRemove

func (g *GitDriver) WorktreeRemove(ctx context.Context, path, name string) error

type GrepResult

type GrepResult struct {
	File    string `json:"file"`
	Line    int    `json:"line"`
	Content string `json:"content"`
}

GrepResult represents a single grep match.

type RepoStatus

type RepoStatus struct {
	Branch    string   `json:"branch"`
	Dirty     bool     `json:"dirty"`
	Ahead     int      `json:"ahead"`
	Behind    int      `json:"behind"`
	Modified  []string `json:"modified,omitempty"`
	Untracked []string `json:"untracked,omitempty"`
	Staged    []string `json:"staged,omitempty"`
}

RepoStatus represents the VCS status of a repository.

type SaplingDriver

type SaplingDriver struct{}

SaplingDriver implements Driver for Sapling (sl).

func NewSaplingDriver

func NewSaplingDriver() *SaplingDriver

func (*SaplingDriver) Checkout

func (s *SaplingDriver) Checkout(ctx context.Context, path, branch string, create bool) error

func (*SaplingDriver) Clone

func (s *SaplingDriver) Clone(ctx context.Context, url, path, branch string) error

func (*SaplingDriver) Commit

func (s *SaplingDriver) Commit(ctx context.Context, path, message string, all bool) error

func (*SaplingDriver) CurrentBranch

func (s *SaplingDriver) CurrentBranch(ctx context.Context, path string) (string, error)

func (*SaplingDriver) Diff

func (s *SaplingDriver) Diff(ctx context.Context, path string) (string, error)

func (*SaplingDriver) Fetch

func (s *SaplingDriver) Fetch(ctx context.Context, path string) error

func (*SaplingDriver) Grep

func (s *SaplingDriver) Grep(ctx context.Context, path, pattern string) ([]GrepResult, error)

func (*SaplingDriver) Log

func (s *SaplingDriver) Log(ctx context.Context, path string, limit int) ([]Commit, error)

func (*SaplingDriver) Name

func (s *SaplingDriver) Name() string

func (*SaplingDriver) Pull

func (s *SaplingDriver) Pull(ctx context.Context, path string) error

func (*SaplingDriver) Push

func (s *SaplingDriver) Push(ctx context.Context, path string) error

func (*SaplingDriver) Status

func (s *SaplingDriver) Status(ctx context.Context, path string) (*RepoStatus, error)

func (*SaplingDriver) WorktreeAdd

func (s *SaplingDriver) WorktreeAdd(ctx context.Context, path, name, branch string) (string, error)

WorktreeAdd for Sapling falls back to cloning since sl doesn't support worktrees.

func (*SaplingDriver) WorktreeList

func (s *SaplingDriver) WorktreeList(ctx context.Context, path string) ([]Worktree, error)

func (*SaplingDriver) WorktreeRemove

func (s *SaplingDriver) WorktreeRemove(ctx context.Context, path, name string) error

type Worktree

type Worktree struct {
	Name   string `json:"name"`
	Path   string `json:"path"`
	Branch string `json:"branch"`
}

Worktree represents a VCS worktree.

Jump to

Keyboard shortcuts

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