git

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInitialized = fmt.Errorf("git repo is not initialized, call repo.Initialize first")

Functions

func AuthFromConfig

func AuthFromConfig(authCfg *config.GitRepoAuth) (transport.AuthMethod, error)

func AuthViaUsernamePassword

func AuthViaUsernamePassword(username, password string) transport.AuthMethod

func FSWrap

func FSWrap(fs vfs.FileSystem) billy.Filesystem

func FWrap

func FWrap(fs vfs.File) billy.File

func K8SyncerAuthor

func K8SyncerAuthor() *object.Signature

K8SyncerAuthor returns a dummy signature object which is used for commits.

Types

type DummyRemote

type DummyRemote struct {
	RootPath string
	Branch   string
	Fs       vfs.FileSystem
	GitFs    vfs.FileSystem
	Repo     *git.Repository
	// contains filtered or unexported fields
}

DummyRemote is a helper struct to spin up a local git repository which can be used as remote for integration testing.

func NewDummyRemote

func NewDummyRemote(fs vfs.FileSystem, branch string) (*DummyRemote, error)

func (*DummyRemote) Close

func (dr *DummyRemote) Close() error

Close deletes the directory containing the remote.

func (*DummyRemote) NewRepo

func (dr *DummyRemote) NewRepo() (*GitRepo, error)

NewRepo returns a new GitRepo configured for the dummy remote. The repository uses a temporary directory on the remote's filesystem and is already initialized.

type FSWrapper

type FSWrapper struct {
	vfs.FileSystem
}

FSWrapper is a helper struct to map the billy.Filesystem interface to an underlying vfs.FileSystem

func (*FSWrapper) Chroot

func (fsw *FSWrapper) Chroot(path string) (billy.Filesystem, error)

func (*FSWrapper) Create

func (fsw *FSWrapper) Create(filename string) (billy.File, error)

func (*FSWrapper) Join

func (fsw *FSWrapper) Join(elem ...string) string

func (*FSWrapper) Lstat

func (fsw *FSWrapper) Lstat(filename string) (os.FileInfo, error)

func (*FSWrapper) Open

func (fsw *FSWrapper) Open(filename string) (billy.File, error)

func (*FSWrapper) OpenFile

func (fsw *FSWrapper) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error)

func (*FSWrapper) ReadDir

func (fsw *FSWrapper) ReadDir(path string) ([]os.FileInfo, error)

func (*FSWrapper) Rename

func (fsw *FSWrapper) Rename(oldpath, newpath string) error

func (*FSWrapper) Root

func (fsw *FSWrapper) Root() string

Root returns the root path of the filesystem.

func (*FSWrapper) Stat

func (fsw *FSWrapper) Stat(filename string) (os.FileInfo, error)

func (*FSWrapper) TempFile

func (fsw *FSWrapper) TempFile(dir string, prefix string) (billy.File, error)

type FWrapper

type FWrapper struct {
	vfs.File
	// contains filtered or unexported fields
}

FWrapper is a helper struct to map the billy.File interface to an underlying vfs.File

func (*FWrapper) Lock

func (fw *FWrapper) Lock() error

func (*FWrapper) Unlock

func (fw *FWrapper) Unlock() error

type GitRepo

type GitRepo struct {
	// URL is the git repo URL.
	URL string
	// Branch is the branch of the repo which should be used.
	Branch string
	// LocalPath is the filesystem path where the repo should be checked out to.
	LocalPath string
	// Auth is the authentification information for the git repository.
	Auth transport.AuthMethod
	// SecondaryAuth is the secondary authentification information for the git repository. It is used if the first one failed and may be nil.
	SecondaryAuth transport.AuthMethod
	// Fs is the filesystem used for the repository.
	Fs vfs.FileSystem
	// contains filtered or unexported fields
}

GitRepo is a helper struct which abstracts from the git commands. Use NewRepo to instantiate this struct.

func NewRepo

func NewRepo(baseFs vfs.FileSystem, url, branch, localPath string, auth, secondaryAuth transport.AuthMethod) (*GitRepo, error)

NewRepo creates a new GitRepo instance, which can be used to interact with a git repository. Note that this only initializes the struct, in order to perform any git actions on the repository, Initialize has to be called first. The GitRepo uses a projection filesystem projecting to the given localPath. This means that all operations on the returned GitRepo's filesystem have to treat the repository directory as root.

func (*GitRepo) Commit

func (r *GitRepo) Commit(log logging.Logger, msg string, paths ...string) (bool, error)

Commit builds a commit containing the specified paths or all changes, if empty. It does not push. If the commit message is empty, a generic one is generated. If there are no changes staged after adding the specified paths, commit aborts early. The first return value determines whether a commit has actually been made (true = there is an unpushed commit).

func (*GitRepo) CommitAndPush

func (r *GitRepo) CommitAndPush(log logging.Logger, pullBefore bool, msg string, paths ...string) error

CommitAndPush is the same as Commit + Push, but it keeps the lock for both commands, preventing other git commands from being executed in between both commands. It pushes only if Commit returns (true, nil).

func (*GitRepo) Initialize

func (r *GitRepo) Initialize(log logging.Logger) error

Initialize opens the repository if it exists and clones it otherwise.

func (*GitRepo) IsInitialized

func (r *GitRepo) IsInitialized() bool

func (*GitRepo) Pull

func (r *GitRepo) Pull(log logging.Logger) error

Pull pulls from the remote repository.

func (*GitRepo) Push

func (r *GitRepo) Push(log logging.Logger, pullBefore bool) error

Push pushes all unpushed commits to the remote repository. If pullBefore is true, it pulls before pushing to avoid conflicts. If an error occurs during the push, it tries to pull and then retries the push.

Jump to

Keyboard shortcuts

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