API reference¶
Generated by go doc as part of task build:docs. Do not edit by hand —
changes here are overwritten on the next docs build.
Package .¶
Command v manages vendored git repositories.
It resolves refs (branches, tags, or commit hashes) to exact commit hashes,
downloads repository contents into vendor/ (without the .git directory),
and records everything in vendors.toml. All CLI logic lives in the cmd package;
this file only wires up the entry point.
FUNCTIONS
func main()
Package ./cmd¶
package cmd // import "github.com/frob/v/cmd"
Package cmd implements the v command-line interface.
Each subcommand lives in its own file (add.go, update.go) and registers itself
on rootCmd via an init function. Subcommands return errors up the stack;
only Execute, the single error boundary, calls os.Exit. The package exports
only Execute — everything else (the cobra command values, their RunE handlers,
and the vendoring helpers) is unexported because nothing here is meant to be
imported by other packages.
CONSTANTS
const vendorsFile = "vendors.toml"
VARIABLES
var addCmd = &cobra.Command{
Use: "add <url> [ref]",
Short: "Add a git repository to vendors.toml",
Long: `Add resolves a git repository ref to an exact commit hash, downloads the
repository contents into vendor/ (without the .git directory), and records
the entry in vendors.toml.
The ref can be a branch name, tag, or full commit hash. If omitted, the
remote's default branch is used.
By default the repository is placed at vendor/<host>/<path>. Use --destination
to override.`,
Args: cobra.RangeArgs(1, 2),
RunE: runAdd,
}
var addDestination string
var downloadRepo = cloneRepo
downloadRepo is a variable so tests can replace the implementation.
var listRemoteRefs = func(repoURL string) ([]*plumbing.Reference, error) {
rem := git.NewRemote(memory.NewStorage(), &config.RemoteConfig{
Name: "origin",
URLs: []string{repoURL},
})
return rem.List(&git.ListOptions{})
}
listRemoteRefs lists the refs a remote advertises. It is a variable so tests
can replace it with a fixture instead of reaching the network.
var resolveCommit = remoteCommit
resolveCommit resolves a URL and optional ref to (resolvedRef, commitHash).
When ref is empty the default branch name and its HEAD commit are returned.
It is a variable so tests can replace the implementation.
var rootCmd = &cobra.Command{
Use: "v",
Short: "Manage vendored git repositories",
Long: `v manages vendored git repositories.
It resolves refs (branches, tags, or commit hashes) to exact commit hashes,
downloads repository contents into vendor/ (without the .git directory),
and records everything in vendors.toml.`,
Version: version,
}
var updateCmd = &cobra.Command{
Use: "update [url [ref]]",
Short: "Update vendored repositories to the latest commit for their ref",
Long: `Update re-fetches vendored repositories and updates vendors.toml with the
latest commit hash for each entry's ref.
With no arguments all vendors are updated. Provide a URL to update a single
entry. Provide a URL and a ref to switch that entry to a different branch,
tag, or commit hash.`,
Args: cobra.MaximumNArgs(2),
RunE: runUpdate,
}
var version = "dev"
version is the build version, injected via -ldflags at release time by
GoReleaser. It defaults to "dev" for local and source builds.
FUNCTIONS
func Execute()
func cloneRepo(repoURL, commit, dest string) error
func defaultPath(repoURL string) (string, error)
func init()
func isCommitHash(s string) bool
func remoteCommit(repoURL, ref string) (resolvedRef, commit string, err error)
func runAdd(cmd *cobra.Command, args []string) error
func runUpdate(cmd *cobra.Command, args []string) error
TYPES
type vendor struct {
URL string `toml:"url"`
Ref string `toml:"ref,omitempty"`
Commit string `toml:"commit,omitempty"`
Path string `toml:"path"`
}
type vendorsConfig = map[string]vendor