git

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthTypeBasic               = "basic"
	AuthTypeBasicSuffixUsername = ".basic.username"
	AuthTypeBasicSuffixPassword = ".basic.password"

	AuthTypeSSH                 = "ssh"
	AuthTypeSSHSuffixPrivateKey = ".ssh.privateKey"
	AuthTypeSSHSuffixPassword   = ".ssh.password"
	AuthTypeSSHSuffixKnownHosts = ".ssh.known_hosts"
)

Variables

View Source
var (
	ErrAuthorIsRequired = errors.New("author is required")
	ErrURLIsRequired    = errors.New("URL is required")
)

Functions

This section is empty.

Types

type GitAuthor

type GitAuthor struct {
	Name  string
	Email string
}

type GitClient

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

GitClient is a small wrapper around go-git library methods. It provides clone/pull/push options as needed and has a simpler interface.

func NewGitClient

func NewGitClient(config *GitConfig) (*GitClient, error)

NewGitClient creates a new go-git library wrapper

func (*GitClient) Add

func (c *GitClient) Add(_ context.Context, filePath string) error

Add stages the given file

func (*GitClient) AddAll

func (c *GitClient) AddAll(_ context.Context) error

AddAll stages all changes in the working directory

func (*GitClient) AddAllAndCommit

func (c *GitClient) AddAllAndCommit(ctx context.Context, msg string) error

AddAndCommit stages all changes an creates a commit

func (*GitClient) AddAndCommit

func (c *GitClient) AddAndCommit(ctx context.Context, filePath, msg string) error

AddAndCommit stages the given file an creates a commit

func (*GitClient) Clone

func (c *GitClient) Clone(ctx context.Context) error

Clone clones the configured repo

func (*GitClient) Close

func (c *GitClient) Close() error

Close cleans up the clone directory

func (*GitClient) Commit

func (c *GitClient) Commit(_ context.Context, msg string) error

Commit commits all changes with the given commit message

func (*GitClient) GetLocalDirectory

func (c *GitClient) GetLocalDirectory() string

GetLocalDirectory returns the directory where the repo is cloned to

func (*GitClient) Pull

func (c *GitClient) Pull(ctx context.Context) error

Pull pulls the latest changes of the configured repo

func (*GitClient) Push

func (c *GitClient) Push(ctx context.Context) error

Push pushes all outstanding changes

type GitConfig

type GitConfig struct {
	// The (possibly remote) repository URL to clone from.
	URL string `yaml:"url"`
	// Auth credentials, if required, to use with the remote repository.
	Auth transport.AuthMethod `yaml:"-"`
	// Fetch only ReferenceName if true.
	SingleBranch bool `yaml:"singleBranch"`
	// Limit fetching to the specified number of commits.
	Depth int `yaml:"depth"`
	// InsecureSkipTLS skips ssl verify if protocol is https
	InsecureSkipTLS bool `yaml:"insecureSkipTLS"`
	// CABundle specify additional ca bundle with system cert pool
	CABundle string `yaml:"caBundle"`
	// Remote branch to clone. If empty, uses HEAD.
	ReferenceName plumbing.ReferenceName `yaml:"referenceName"`
	// AuthType is the type of authentication
	AuthType string `yaml:"authType"`
	// EnvPrefix is the prefix for environment variables to configure
	EnvPrefix string `yaml:"envPrefix"`
	// Timeout is an optional field to specify a timeout for Git operations like cloning. Defaults to 60s.
	Timeout *time.Duration `yaml:"timeout"`
	// Author is the author of commits done by the client
	Author *GitAuthor `yaml:"author"`
	// contains filtered or unexported fields
}

func NewGitConfig

func NewGitConfig(url string, author *GitAuthor) (*GitConfig, error)

NewGitConfig creates a new configuration

func (*GitConfig) Validate

func (c *GitConfig) Validate() error

Validate validates the configuration

Jump to

Keyboard shortcuts

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