vcsstate

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

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 8 Imported by: 7

README

vcsstate

Go Reference

Package vcsstate allows getting the state of version control system repositories.

Installation

go get github.com/shurcooL/vcsstate

License

Documentation

Overview

Package vcsstate allows getting the state of version control system repositories.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRemote = errors.New("local repository has no valid remote")

ErrNoRemote is the error used when the local repository doesn't have a valid remote.

Functions

This section is empty.

Types

type NotFoundError

type NotFoundError struct {
	Err error // Underlying error with more details.
}

NotFoundError records an error where the remote repository is not found.

func (NotFoundError) Error

func (e NotFoundError) Error() string

type RemoteVCS

type RemoteVCS interface {
	// RemoteBranchAndRevision returns the name and latest revision of the default branch
	// from the remote. If the remote repository is not found, NotFoundError is returned.
	RemoteBranchAndRevision(remoteURL string) (branch string, revision string, err error)
}

RemoteVCS describes how to use a version control system to get the remote status of a repository with remoteURL.

func NewRemoteVCS

func NewRemoteVCS(vcs *vcs.Cmd) (RemoteVCS, error)

NewRemoteVCS creates a RemoteVCS with same type as vcs.

type VCS

type VCS interface {
	// Status returns the status of working directory.
	// It returns empty string if no outstanding status.
	Status(dir string) (string, error)

	// Branch returns the name of the locally checked out branch.
	Branch(dir string) (string, error)

	// LocalRevision returns current local revision of default branch.
	LocalRevision(dir string, defaultBranch string) (string, error)

	// Stash returns a non-empty string if the repository has a stash.
	Stash(dir string) (string, error)

	// Contains reports whether the local default branch contains
	// the commit specified by revision.
	Contains(dir string, revision string, defaultBranch string) (bool, error)

	// RemoteContains reports whether the remote default branch contains
	// the commit specified by revision.
	RemoteContains(dir string, revision string, defaultBranch string) (bool, error)

	// RemoteURL returns primary remote URL, as set in the local repository.
	// If there's no remote, then ErrNoRemote is returned.
	RemoteURL(dir string) (string, error)

	// RemoteBranchAndRevision returns the name and latest revision of the default branch
	// from the remote. If there's no remote, then ErrNoRemote is returned, and the
	// default branch can be queried with NoRemoteDefaultBranch.
	// If the remote repository is not found, NotFoundError is returned,
	// and the default branch can be queried with NoRemoteDefaultBranch.
	// This operation requires the use of network, and will fail if offline.
	// When offline, CachedRemoteDefaultBranch can be used as a fallback.
	RemoteBranchAndRevision(dir string) (branch string, revision string, err error)

	// CachedRemoteDefaultBranch returns a locally cached remote default branch,
	// if it can do so successfully. It can be used to make a best effort guess
	// of the remote default branch when offline. If it fails, the only viable
	// next best fallback before online again is to use NoRemoteDefaultBranch.
	CachedRemoteDefaultBranch() (string, error)

	// NoRemoteDefaultBranch returns the default value of default branch for this vcs.
	// It can only be relied on when there's no remote, since remote can have a custom
	// value of default branch.
	NoRemoteDefaultBranch() string
}

VCS describes how to use a version control system to get the status of a repository rooted at dir.

func NewVCS

func NewVCS(vcs *vcs.Cmd) (VCS, error)

NewVCS creates a VCS with same type as vcs.

Jump to

Keyboard shortcuts

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