git

package
v0.0.0-...-cc69b76 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

type Repository struct {
	Repo *gogit.Repository
	// contains filtered or unexported fields
}

Repository represents a Git repository, as an abstraction layer above the go-git library in order to also store the current configuration and the authentication data needed to talk to the Git remote.

func NewRepository

func NewRepository(cfg *config.GitSettings) (r *Repository, invalidRepo bool, err error)

NewRepository creates a new instance of the Repository structure and fills it accordingly to the current configuration. Returns a boolean if the clone path doesn't contain a valid Git repository and needs the repository to be cloned from remote before it is usable. Returns an error if there was an issue opening the clone path or loading authentication data.

func (*Repository) GetFilesContentsAtCommit

func (r *Repository) GetFilesContentsAtCommit(commit *object.Commit) (map[string][]byte, error)

GetFilesContentsAtCommit retrieves the state of the repository at a given commit, and returns a map contaning the contents of all files in the repository at this time. Returns an error if there was an issue loading the commit's tree, or loading a file's content.

func (*Repository) GetLatestCommit

func (r *Repository) GetLatestCommit() (*object.Commit, error)

GetLatestCommit retrieves the latest commit from the local Git repository and returns it. Returns an error if there was an issue fetching the references or loading the latest one.

func (*Repository) GetModifiedAndRemovedFiles

func (r *Repository) GetModifiedAndRemovedFiles(
	from *object.Commit, to *object.Commit,
) (modified []string, removed []string, err error)

GetModifiedAndRemovedFiles takes to commits and returns the name of files that were added, modified or removed between these two commits. Note that the added/modified files and the removed files are returned in two separated slices, mainly because some features using this function need to load the files' contents afterwards, and this is done differently depending on whether the file was removed or not. "from" refers to the oldest commit of both, and "to" to the latest one. Returns empty slices and no error if both commits have the same hash. Returns an error if there was an issue loading the repository's log, the commits' stats, or retrieving a file from the repository.

func (*Repository) Log

func (r *Repository) Log(fromHash string) (object.CommitIter, error)

Log loads the Git repository's log, with the most recent commit having the given hash. Returns an error if the log couldn't be loaded.

func (*Repository) Push

func (r *Repository) Push() (err error)

Push uses a given repository and configuration to push the local history of the said repository to the remote, using an authentication structure instance created from the configuration to authenticate on the remote. Returns with an error if there was an issue creating the authentication structure instance or pushing to the remote. In the latter case, if the error is a known non-error, doesn't return any error.

func (*Repository) Sync

func (r *Repository) Sync(dontClone bool) (err error)

Sync synchronises a Git repository using a given configuration. "synchronises" means that, if the repo from the configuration isn't already cloned in the directory specified in the configuration, it will clone the repository (unless if explicitly told not to), else it will simply pull it in order to be up to date with the remote. Returns the go-git representation of the repository. Returns an error if there was an issue loading the SSH private key, checking whether the clone path already exists, or synchronising the repo with the remote.

Jump to

Keyboard shortcuts

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