vcs

package
v0.0.0-...-e600875 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2016 License: Apache-2.0 Imports: 19 Imported by: 11

Documentation

Overview

Package vcs provides methods for VCS.

Index

Constants

View Source
const (
	Secure securityMode = iota
	Insecure
)

Security mode options

Variables

View Source
var Bzr = &Cmd{
	Name: "Bazaar",
	Cmd:  "bzr",

	CreateCmd: []string{"branch {repo} {dir}"},

	DownloadCmd: []string{"pull --overwrite"},

	TagCmd:         []TagCmd{{"tags", `^(\S+)`}},
	TagSyncCmd:     "update -r {tag}",
	TagSyncDefault: "update -r revno:-1",

	Scheme:      []string{"https", "http", "bzr", "bzr+ssh"},
	PingCmd:     "info {scheme}://{repo}",
	RemoteRepo:  bzrRemoteRepo,
	ResolveRepo: bzrResolveRepo,
}

Bzr describes how to use Bazaar.

View Source
var Git = &Cmd{
	Name: "Git",
	Cmd:  "git",

	CreateCmd:   []string{"clone {repo} {dir}", "-go-internal-cd {dir} submodule update --init --recursive"},
	DownloadCmd: []string{"pull --ff-only", "submodule update --init --recursive"},

	TagCmd: []TagCmd{

		{"show-ref", `(?:tags|origin)/(\S+)$`},
	},
	TagLookupCmd: []TagCmd{
		{"show-ref tags/{tag} origin/{tag}", `((?:tags|origin)/\S+)$`},
	},
	TagSyncCmd:     "checkout {tag}",
	TagSyncDefault: "checkout master",

	Scheme:     []string{"git", "https", "http", "git+ssh", "ssh"},
	PingCmd:    "ls-remote {scheme}://{repo}",
	RemoteRepo: gitRemoteRepo,
}

Git describes how to use Git.

View Source
var Hg = &Cmd{
	Name: "Mercurial",
	Cmd:  "hg",

	CreateCmd:   []string{"clone -U {repo} {dir}"},
	DownloadCmd: []string{"pull"},

	TagCmd: []TagCmd{
		{"tags", `^(\S+)`},
		{"branches", `^(\S+)`},
	},
	TagSyncCmd:     "update -r {tag}",
	TagSyncDefault: "update default",

	Scheme:     []string{"https", "http", "ssh"},
	PingCmd:    "identify {scheme}://{repo}",
	RemoteRepo: hgRemoteRepo,
}

Hg describes how to use Mercurial.

View Source
var List = []*Cmd{
	Hg,
	Git,
	Svn,
	Bzr,
}

List lists the known version control systems

View Source
var ShowCmd bool

ShowCmd controls whether VCS commands are printed.

View Source
var Svn = &Cmd{
	Name: "Subversion",
	Cmd:  "svn",

	CreateCmd:   []string{"checkout {repo} {dir}"},
	DownloadCmd: []string{"update"},

	Scheme:     []string{"https", "http", "svn", "svn+ssh"},
	PingCmd:    "info {scheme}://{repo}",
	RemoteRepo: svnRemoteRepo,
}

Svn describes how to use Subversion.

View Source
var Verbose bool

Verbose enables verbose operation logging.

Functions

func HTTPSorHTTP

func HTTPSorHTTP(importPath string, security securityMode, verbose bool) (urlStr string, body io.ReadCloser, err error)

HTTPSorHTTP returns the body of either the importPath's https resource or, if unavailable, the http resource.

Types

type Cmd

type Cmd struct {
	Name string
	Cmd  string // name of binary to invoke command

	CreateCmd   []string // commands to download a fresh copy of a repository
	DownloadCmd []string // commands to download updates into an existing repository

	TagCmd         []TagCmd // commands to list tags
	TagLookupCmd   []TagCmd // commands to lookup tags before running tagSyncCmd
	TagSyncCmd     string   // commands to sync to specific tag
	TagSyncDefault string   // commands to sync to default tag

	Scheme  []string
	PingCmd string

	RemoteRepo  func(v *Cmd, rootDir string) (remoteRepo string, err error)
	ResolveRepo func(v *Cmd, rootDir, remoteRepo string) (realRepo string, err error)
}

A Cmd describes how to use a version control system like Mercurial, Git, or Subversion.

func ByCmd

func ByCmd(cmd string) *Cmd

ByCmd returns the version control system for the given command name (hg, git, svn, bzr).

func FromDir

func FromDir(dir, srcRoot string) (vcs *Cmd, root string, err error)

FromDir inspects dir and its parents to determine the version control system and code repository to use. On return, root is the import path corresponding to the root of the repository (thus root is a prefix of importPath).

func (*Cmd) Create

func (c *Cmd) Create(dir, repo string) error

Create creates a new copy of repo in dir. The parent of dir must exist; dir must not.

func (*Cmd) CreateAtRev

func (c *Cmd) CreateAtRev(dir, repo, rev string) error

CreateAtRev creates a new copy of repo in dir at revision rev. The parent of dir must exist; dir must not. rev must be a valid revision in repo.

func (*Cmd) Download

func (c *Cmd) Download(dir string, verbose bool) error

Download downloads any new changes for the repo in dir.

func (*Cmd) Ping

func (c *Cmd) Ping(scheme, repo string) error

Ping pings to determine scheme to use.

func (*Cmd) String

func (c *Cmd) String() string

func (*Cmd) TagSync

func (c *Cmd) TagSync(dir, tag string) error

TagSync syncs the repo in dir to the named tag, which either is a tag returned by tags or is v.tagDefault.

func (*Cmd) Tags

func (c *Cmd) Tags(dir string) ([]string, error)

Tags returns the list of available tags for the repo in dir.

type MetaImport

type MetaImport struct {
	Prefix, VCS, RepoRoot string
}

MetaImport represents the parsed <meta name="go-import" content="prefix vcs reporoot" /> tags from HTML files.

func MetaImportsForPrefix

func MetaImportsForPrefix(importPrefix string, security securityMode, verbose bool) (urlStr string, imports []MetaImport, err error)

MetaImportsForPrefix takes a package's root import path as declared in a <meta> tag and returns its HTML discovery URL and the parsed metaImport lines found on the page.

The importPath is of the form "golang.org/x/tools". It is an error if no imports are found. urlStr will still be valid if err != nil. The returned urlStr will be of the form "https://golang.org/x/tools?go-get=1"

func ParseMetaGoImports

func ParseMetaGoImports(r io.Reader) (imports []MetaImport, err error)

ParseMetaGoImports returns meta imports from the HTML in r. Parsing ends at the end of the <head> section or the beginning of the <body>.

type RepoRoot

type RepoRoot struct {
	VCS *Cmd

	// repo is the repository URL, including scheme
	Repo string

	// root is the import path corresponding to the root of the
	// repository
	Root string
}

RepoRoot represents a version control system, a repo, and a root of where to put it on disk.

func RepoRootForImportDynamic

func RepoRootForImportDynamic(importPath string, security securityMode, verbose bool) (*RepoRoot, error)

RepoRootForImportDynamic finds a *repoRoot for a custom domain that's not statically known by RepoRootForImportPathStatic.

This handles custom import paths like "name.tld/pkg/foo" or just "name.tld".

func RepoRootForImportPath

func RepoRootForImportPath(importPath string, security securityMode, verbose bool) (*RepoRoot, error)

RepoRootForImportPath analyzes importPath to determine the version control system, and code repository to use.

func RepoRootFromVCSPaths

func RepoRootFromVCSPaths(importPath, scheme string, security securityMode, vcsPaths []*vcsPath) (*RepoRoot, error)

RepoRootFromVCSPaths attempts to map importPath to a repoRoot using the mappings defined in vcsPaths. If scheme is non-empty, that scheme is forced.

type TagCmd

type TagCmd struct {
	Cmd     string // command to list tags
	Pattern string // regexp to extract tags from list
}

A TagCmd describes a command to list available tags that can be passed to tagSyncCmd.

Directories

Path Synopsis
internal
singleflight
Package singleflight provides a duplicate function call suppression mechanism.
Package singleflight provides a duplicate function call suppression mechanism.

Jump to

Keyboard shortcuts

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