scm

package
v0.0.0-...-a29b1dd Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package scm implements repository management specific for Go projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change interface {
	// Repo references back to the repository.
	Repo() ReadOnlyRepo
	// Package returns the package name to reference Repo().Root(). Returns an
	// empty string if the repository is located outside of $GOPATH.
	Package() string
	// Changed is the directly affected files and packages.
	Changed() Set
	// Indirect returns the Set of everything affected indirectly, e.g. all
	// modified files plus all packages importing a package that was modified by
	// this Change. It is useful for example to run all tests that could be
	// indirectly impacted by a change. Indirect().GoFiles() ==
	// Changed().GoFiles(). Only Packages() and TestPackages() can be longer, up
	// to values returned by All()'s.
	Indirect() Set
	// All returns all the files in the repository.
	All() Set
	// Content returns the content of a file.
	Content(name string) []byte
	// IsIgnored returns true if this path is ignored. This is mostly relevant
	// when using tools that work at the package level instead of at the file
	// level and generated files (like proto-gen-go generated files) should be
	// ignored.
	IsIgnored(p string) bool
}

Change represents a change to test against.

This interface is specialized for Go projects.

type Commit

type Commit string

Commit represents a commit reference, normally a digest.

const (
	// Initial is the root invisible commit.
	Initial Commit = "<initial>"
	// Head is the reference to the current checkout as referenced by what is
	// checked in.
	Head Commit = "<head>"
	// Current is a meta-reference to the current tree as on the file system.
	Current Commit = "<current>"
	// Upstream is the commit on the remote repository against with the current
	// branch is based on.
	Upstream Commit = "<upstream>"
	// Invalid is an invalid commit reference.
	Invalid Commit = "<invalid>"
)

type IgnorePatterns

type IgnorePatterns []string

IgnorePatterns is a list of glob that when matching, means the file should be ignored.

func (*IgnorePatterns) Match

func (i *IgnorePatterns) Match(p string) bool

Match returns true when the file should be ignored.

func (*IgnorePatterns) Set

func (i *IgnorePatterns) Set(value string) error

Set implements flag.Value.

func (*IgnorePatterns) String

func (i *IgnorePatterns) String() string

type ReadOnlyRepo

type ReadOnlyRepo interface {
	// Root returns the root directory of this repository.
	Root() string
	// Scmdir returns the directory containing the source control specific files,
	// e.g. it is ".git" by default for git repositories. It can be different
	// when GIT_DIR is specified or in the case of git submodules.
	ScmDir() (string, error)
	// HookPath returns the directory containing the commit and push hooks.
	HookPath() (string, error)
	// Ref returns the branch name referencing to commit c. If there is no branch
	// name, "" is returned.
	Ref(c Commit) string
	// Eval returns the commit hash by evaluating refish. Returns Invalid in case
	// of failure.
	Eval(refish string) Commit
	// Between returns a change with files touched between from and to in it.
	// If recent is Current, it diffs against the current tree, independent of
	// what is versioned.
	//
	// To get files in the staging area, use (Current, Head).
	//
	// Untracked files are always excluded.
	//
	// Files with untracked change will be included if recent == Current. To
	// exclude untracked changes to tracked files, use Stash() first or specify
	// Head for recent.
	//
	// To get the list of all files in the tree and the index, use
	// Between(Current, Initial, ...).
	//
	// Returns nil and no error if there's no file difference.
	Between(recent, old Commit, ignorePatterns IgnorePatterns) (Change, error)
	// GOPATH returns the GOPATH. Mostly used in tests.
	GOPATH() string
}

ReadOnlyRepo represents a source control managemed checkout.

ReadOnlyRepo exposes no function that would modify the state of the checkout.

The implementation of this interface must be thread safe.

type Repo

type Repo interface {
	ReadOnlyRepo
	// Stash stashes the content that is not in the index.
	Stash() (bool, error)
	// Stash restores the stash generated from Stash.
	Restore() error
	// Checkout checks out a commit or a branch.
	Checkout(refish string) error
}

Repo represents a source control managed checkout.

It is possible to modify this repository with the functions exposed by this interface.

func GetRepo

func GetRepo(wd, gopath string) (Repo, error)

GetRepo returns a valid Repo if one is found.

type Set

type Set interface {
	// GoFiles returns all the source files, including tests.
	GoFiles() []string
	// Packages returns all the packages included in this set, using the relative
	// notation, e.g. with prefix "./" relative to the checkout root. So this
	// package "scm" would be represented as "./scm".
	Packages() []string
	// TestPackages returns all the packages included in this set that contain
	// tests, using the relative notation, e.g. with prefix "./".
	//
	// In summary, it is the same result as Packages() but without the ones with
	// no test.
	TestPackages() []string
}

Set is a subset of files/directories/packages relative to the change and the overall repository.

Each list is guaranteed to be sorted according to sort.StringsAreStored().

Jump to

Keyboard shortcuts

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