repos

package
v0.0.0-...-7954b2e Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package repos provides the Repo type

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortTargetNames

func SortTargetNames(targets map[string]Target) []string

SortTargetNames returns the sorted keys of a target map

Types

type Repo

type Repo struct {
	// Requested URL and git ref, these may not be the same as actual
	URL string
	Ref string
	// contains filtered or unexported fields
}

Repo is an in-memory git repository.

func GetLocalRepo

func GetLocalRepo() (rep *Repo, err error)

GetLocalRepo returns a local Repo reference assuming we're executing this somewhere in the context of a git repository structure.

func New

func New(url string, refs ...string) (repo *Repo, err error)

New returns a new Repo instance from the URL and tarrge ref

func (*Repo) ApplyExcludes

func (repo *Repo) ApplyExcludes(excludes []string) (targets map[string]Target, err error)

ApplyExcludes applies the given excludes to the current targets.

The returned value is the mapping of all targets.

func (*Repo) ApplyIncludes

func (repo *Repo) ApplyIncludes(includes []string) (found map[string]Target, err error)

ApplyIncludes applies the given includes to the current targets.

The returned value is the mapping of all targets.

func (*Repo) ApplyRenames

func (repo *Repo) ApplyRenames(renames []config.Rename) map[string]Target

ApplyRenames applies the given renames.

The returned value is the mapping of the renamed file to the original file. It can be mutated manually to change the internal state of the repo renames.

func (*Repo) ApplyTemplates

func (repo *Repo) ApplyTemplates(templates []string, templateVars map[string]interface{}) (err error)

ApplyTemplates creates the templates in our map of targets.

func (*Repo) Check

func (repo *Repo) Check() (err error)

Check makes sure the Repo has been initialized and cloned and is ready.

func (*Repo) Clone

func (repo *Repo) Clone() (err error)

Clone the given repository into this Repo and populate the list of files.

func (*Repo) FS

func (repo *Repo) FS() billy.Filesystem

FS returns the Repo's filesystem

func (*Repo) Glob

func (repo *Repo) Glob(pattern string) (matches []string, err error)

Glob returns a list of file names matching the given pattern.

func (*Repo) GlobTargets

func (repo *Repo) GlobTargets(pattern string) (matches map[string]Target, err error)

GlobTargets returns a mapping of renamed filename to original filenames matching the given pattern.

func (*Repo) Init

func (repo *Repo) Init() (err error)

Init creates the memory filesystem and storage for the repository.

This will make network requests to find the default branch, as well as read the filesystem to load the gitconfig.

func (*Repo) LoadConfig

func (repo *Repo) LoadConfig(search ...string) (cfg *config.Config, err error)

LoadConfig returns the config in this Repo if it exists.

func (*Repo) Open

func (repo *Repo) Open(name string) (io.Reader, error)

Open returns a file handle for the given file name.

func (*Repo) ReadFile

func (repo *Repo) ReadFile(name string) ([]byte, error)

ReadFile reads the named file and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.

This implementation is stolen from os.ReadFile

func (*Repo) ResetTargets

func (repo *Repo) ResetTargets()

ResetTargets initializes the renamed map to the current list of files.

func (*Repo) Stat

func (repo *Repo) Stat(name string) (os.FileInfo, error)

Stat returns fs.FileInfo from stat() on a file name

func (*Repo) Targets

func (repo *Repo) Targets() map[string]Target

Targets returns the targets and initializes it if it hasn't been

type Target

type Target struct {
	Name string                 // Original file name
	Vars map[string]interface{} // Template variables, if it is a template
	// contains filtered or unexported fields
}

Target represents a single target file or template

func (*Target) CopyTo

func (targ *Target) CopyTo(dest io.Writer) (err error)

CopyTo copies the given file to the given writer

func (*Target) RenderTo

func (targ *Target) RenderTo(dest io.Writer) (err error)

RenderTo renders the template with the current Vars

func (*Target) Stat

func (targ *Target) Stat() (os.FileInfo, error)

Stat returns the os.FileInfo for the target

func (*Target) String

func (targ *Target) String() string

String returns a Target as a string

func (*Target) Write

func (targ *Target) Write(dest io.Writer) (err error)

Write writes the target file to the given writer

Jump to

Keyboard shortcuts

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