api

package module
v0.0.0-...-ad7ab41 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(vcs VersionControlSystem)

Register registers a VCS for use by tmux-vcs-sync.

Types

type Repository

type Repository interface {
	// VCS is a reference to the VCS that owns this repository.
	VCS() VersionControlSystem
	// Name returns the name of the repository.
	// e.g. tmux-vcs-sync
	Name() string
	// RootDir returns the root directory of the repository.
	RootDir() string

	// Current returns the name of the current work unit.
	Current(context.Context) (string, error)
	// List returns all of the work units in this repository that start with the
	// given prefix.
	List(ctx context.Context, prefix string) ([]string, error)
	// Sort orders the given work units topologically.
	Sort(ctx context.Context, workUnits []string) error

	// New creates a new work unit with the given name on top of the repository's
	// trunk.
	// e.g. Create a new branch on main.
	New(ctx context.Context, workUnitName string) error
	// Commit creates a new work unit with the given name on top of the repository's
	// current work unit.
	// e.g. Create a new branch based on the current branch.
	// n.b. Commit is the same as New if the current branch is main.
	Commit(ctx context.Context, workUnitName string) error
	// Rename the current work unit's name to the given name.
	Rename(ctx context.Context, workUnitName string) error
	// Exists determines whether a work unit with the given name exists in this
	// repository.
	Exists(ctx context.Context, workUnitName string) (bool, error)
	// Update the state of this repository so that the given work unit is
	// "active".
	// e.g. Check out the named branch.
	Update(ctx context.Context, workUnitName string) error
}

A Repository is a particular instance of a Version Control System over some folder hierarchy.

func MaybeFindRepository

func MaybeFindRepository[T any](ctx context.Context, elems []T, fn func(T) (Repository, error)) (Repository, error)

MaybeFindRepository attempts to find the single Repository that fn yields for all elems. Returns an error if fn yields a Repository more than once as we test it against each element in elems. Returns nil, nil if fn never yields a Repository (or an error).

type VersionControlSystem

type VersionControlSystem interface {
	// Name returns the name of the VCS.
	// e.g. git
	Name() string
	// WorkUnitName returns a human-friendly name for work units.
	// e.g. branch
	WorkUnitName() string
	// Repository determines if a repository instance of this VCS exists for the
	// given directory.
	// If no such instance exists, return nil, nil.
	Repository(ctx context.Context, dir string) (Repository, error)
}

A VersionControlSystem/VCS is a tool that tracks changes to files over time.

type VersionControlSystems

type VersionControlSystems []VersionControlSystem

func Registered

func Registered() VersionControlSystems

Registered is all of the VersionControlSystems added via Register.

func (VersionControlSystems) CurrentRepository

func (all VersionControlSystems) CurrentRepository(ctx context.Context) (Repository, error)

CurrentRepository returns a Repository for the current working directory, or an error if one cannot be found.

func (VersionControlSystems) MaybeCurrentRepository

func (all VersionControlSystems) MaybeCurrentRepository(ctx context.Context) (Repository, error)

func (VersionControlSystems) MaybeFindRepository

func (all VersionControlSystems) MaybeFindRepository(ctx context.Context, dir string) (Repository, error)

MaybeFindRepository attempts to find an Repository for the given directory. Returns an error if multiple Repositories claim to exist in the given directory. Returns nil, nil if no such Repository can be found.

Directories

Path Synopsis
magefiles
repotest implements a fake implementation of api.VersionControlSystem.
repotest implements a fake implementation of api.VersionControlSystem.

Jump to

Keyboard shortcuts

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