git

package
v0.0.0-...-a8e4d9d Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2020 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package git provides access to git repository metadata such as refs, authors, branches and commits.

The package goes to some length to intelligently handle URLs, and be wise about protocol schemes.

Since URLs can embed credentials (username, password) the package attempts to parse them and handle them correctly. Incase of SSH-like protocol schemes (handled by giturl package) an intelligent guess of `git` as a username is made.

Calls to SetCredential mutate the given URL if the URL protocol scheme is http(s) and the given credential is compatible. Hence calls to NewRepository() with a URL sans credentials, followed by a call to SetCredential() with an httpCredential instance is equivilent to having called NewRepository() with the credentials embedded in the URL

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSshExectableNotFound            = errors.New("git: ssh executable not found")
	ErrCatExectableNotFound            = errors.New("git: ssh executable not found")
	ErrGitExecutableNonZeroReturn      = errors.New("git: git executable returned non-zero")
	ErrGitExecutableNotFound           = errors.New("git: git executable not found")
	ErrIllegalCharactersInURL          = errors.New("git: illegal characters in url")
	ErrIncompatibleCredentialType      = errors.New("git: credential type is not compatible with the url protocol scheme")
	ErrNotImplemented                  = errors.New("git: not implemented")
	ErrUnparsablePrivateKey            = errors.New("git: unparsable private key")
	ErrUnparsableURL                   = errors.New("git: unparsable url")
	ErrWritingSshWrapperToDisk         = errors.New("git: error writing ssh wrapper to disk")
	ErrWritingSshPrivateKeyToDisk      = errors.New("git: error writing ssh private key to disk")
	ErrRemovingSensitveFiles           = errors.New("git: error removing sensitive files")
	ErrWritingHttpsCredentialCacheFile = errors.New("git: error writing https credential cache helper file to disk")
	ErrCallingGitConfig                = errors.New("git: error calling `git config'")
)
View Source
var (
	ErrURLIsWhitespacePadded = fmt.Errorf("git: url contains trailing or leading whitespace")
	ErrURLHostMissing        = fmt.Errorf("git: url host missing")
	ErrURLPathMissing        = fmt.Errorf("git: url path missing")
	ErrURLSchemeUnsupported  = fmt.Errorf("git: url scheme unsupported")
)
View Source
var (
	DefaultSSHUserInfo = url.User("git")
)

Functions

func NewHTTPCredential

func NewHTTPCredential(username, password string) (*httpCredential, error)

func NewSshCredential

func NewSshCredential(username string, keydata []byte) (*sshCredential, error)

Types

type ClonedRepository

type ClonedRepository struct {
	// contains filtered or unexported fields
}

func NewClonedRepository

func NewClonedRepository(os System, cloneURL *url.URL) *ClonedRepository

func (*ClonedRepository) Clone

func (self *ClonedRepository) Clone() error

func (*ClonedRepository) Contributors

func (self *ClonedRepository) Contributors() ([]*Person, error)

func (*ClonedRepository) FetchMetadata

func (self *ClonedRepository) FetchMetadata() (*RepositoryMetadata, error)

func (*ClonedRepository) IsAccessible

func (self *ClonedRepository) IsAccessible() (bool, error)

func (*ClonedRepository) MakePersistent

func (self *ClonedRepository) MakePersistent()

func (*ClonedRepository) Pull

func (self *ClonedRepository) Pull() error

func (*ClonedRepository) References

func (self *ClonedRepository) References() ([]*Reference, error)

func (*ClonedRepository) Remove

func (self *ClonedRepository) Remove() error

func (*ClonedRepository) SetCredential

func (self *ClonedRepository) SetCredential(credential Credential) error

func (*ClonedRepository) UsesHTTP

func (self *ClonedRepository) UsesHTTP() bool

func (*ClonedRepository) UsesSSH

func (self *ClonedRepository) UsesSSH() bool

type Credential

type Credential interface {
	String() string
	Username() string
	Secret() string
	Protocol() string
}

type Error

type Error struct {
	Err error
}

type OperatingSystem

type OperatingSystem struct {
	// contains filtered or unexported fields
}

func NewOperatingSystem

func NewOperatingSystem(tempDir string) *OperatingSystem

func (*OperatingSystem) CreateFile

func (self *OperatingSystem) CreateFile(filename string) (io.WriteCloser, error)

func (*OperatingSystem) DeleteFile

func (self *OperatingSystem) DeleteFile(filename string) error

func (*OperatingSystem) PersistentDir

func (self *OperatingSystem) PersistentDir(key string) (string, error)

func (*OperatingSystem) Run

func (self *OperatingSystem) Run(cmd *SystemCommand) ([]byte, error)

func (*OperatingSystem) SetPermissions

func (self *OperatingSystem) SetPermissions(filename string, mode int) error

func (*OperatingSystem) TempDir

func (self *OperatingSystem) TempDir() (string, error)

type Person

type Person struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

type Reference

type Reference struct {
	Name string
	Hash string
}

type Repository

type Repository struct {
	URL *URL
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(u string) (*Repository, error)

NewRepository returns a new instance of repository. The URL given must be parsable, else an error will be returned. If the URL includes a username and password these will be stored and available to other calls which may need such information without requring a call to repository.SetCredential()

func (*Repository) CloneURL

func (self *Repository) CloneURL() string

CloneURL returns something we can pass to `ls-remote` or similar it is mostly used in the older code (rootfs builder) where the newer `Credential` and `git.Repository` stuff is more modern. In the SSH case it returns the host alias with the clone path, assuming that a corresponding entry is made somewhere else in a `man (1) ssh_config`.

func (*Repository) Contributors

func (self *Repository) Contributors() ([]*Person, error)

Contributors returns the list of contributors to this repository. In order to do its work, it requires a clone of the repository. If this repository has not been cloned yet, this method attempts to clone the repository first before extracting information from it.

func (*Repository) FetchMetadata

func (self *Repository) FetchMetadata() (*RepositoryMetadata, error)

FetchMetadata gathers metadata about the repository. Metadata includes all refs and what they point to as well as contributors (identified by their email address) to the repository.

func (*Repository) IsAccessible

func (self *Repository) IsAccessible() bool

IsAccessible returns true if references can be collected without error (self.References())

func (*Repository) References

func (self *Repository) References() ([]*Reference, error)

References runs the equivalent of a `git ls-remote` returning the complete unabridge list of all remote references.

func (*Repository) SSHHost

func (self *Repository) SSHHost() string

func (*Repository) SSHHostAlias

func (self *Repository) SSHHostAlias() string

SSHHostAlias returns something usable as an SSH alias in ~/.ssh/config for clones over SSH.

func (*Repository) SSHPort

func (self *Repository) SSHPort() string

func (*Repository) SetCredential

func (self *Repository) SetCredential(c Credential) error

func (*Repository) Username

func (self *Repository) Username() string

func (*Repository) UsesHTTP

func (self *Repository) UsesHTTP() bool

func (*Repository) UsesSSH

func (self *Repository) UsesSSH() bool

type RepositoryMetadata

type RepositoryMetadata struct {
	Contributors map[string]*Person `json:"contributors"`
	Refs         map[string]string  `json:"refs"`
}

func NewRepositoryMetadata

func NewRepositoryMetadata() *RepositoryMetadata

func (*RepositoryMetadata) AddContributor

func (self *RepositoryMetadata) AddContributor(contributor *Person) *RepositoryMetadata

func (*RepositoryMetadata) AddRef

func (self *RepositoryMetadata) AddRef(ref *Reference) *RepositoryMetadata

type System

type System interface {
	TempDir() (string, error)
	PersistentDir(key string) (string, error)
	CreateFile(filename string) (io.WriteCloser, error)
	DeleteFile(filename string) error
	SetPermissions(filename string, mode int) error
	Run(cmd *SystemCommand) ([]byte, error)
}

type SystemCommand

type SystemCommand struct {
	Exec string   // name of the executable
	Args []string // arguments to pass to the executable
	Env  []string // environment in which the command runs
	Dir  string   // working directory of the command
}

func NewSystemCommand

func NewSystemCommand(exec string, args ...string) *SystemCommand

func (*SystemCommand) QuotedArgs

func (self *SystemCommand) QuotedArgs() []string

func (*SystemCommand) SetEnv

func (self *SystemCommand) SetEnv(name, value string) *SystemCommand

func (*SystemCommand) String

func (self *SystemCommand) String() string

func (*SystemCommand) WorkingDirectory

func (self *SystemCommand) WorkingDirectory(dir string) *SystemCommand

type URL

type URL struct {
	url.URL
}

func Parse

func Parse(rawurl string) (*URL, error)

func (*URL) Copy

func (self *URL) Copy() *URL

func (*URL) String

func (self *URL) String() string

type ValidationError

type ValidationError map[string]string

func (ValidationError) Error

func (self ValidationError) Error() string

func (ValidationError) IsZero

func (self ValidationError) IsZero() bool

func (ValidationError) MergeOverwrite

func (self ValidationError) MergeOverwrite(m error)

Jump to

Keyboard shortcuts

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