Documentation
¶
Overview ¶
Package gitrepo provides operations on git repos.
Index ¶
- type Commit
- type LocalRepository
- func (r *LocalRepository) AddAll() (git.Status, error)
- func (r *LocalRepository) ChangedFilesInCommit(commitHash string) ([]string, error)
- func (r *LocalRepository) Commit(msg string) error
- func (r *LocalRepository) CreateBranchAndCheckout(name string) error
- func (r *LocalRepository) GetCommit(commitHash string) (*Commit, error)
- func (r *LocalRepository) GetCommitsForPathsSinceCommit(paths []string, sinceCommit string) ([]*Commit, error)
- func (r *LocalRepository) GetCommitsForPathsSinceTag(paths []string, tagName string) ([]*Commit, error)
- func (r *LocalRepository) GetDir() string
- func (r *LocalRepository) HeadHash() (string, error)
- func (r *LocalRepository) IsClean() (bool, error)
- func (r *LocalRepository) Push(branchName string) error
- func (r *LocalRepository) Remotes() ([]*git.Remote, error)
- type Repository
- type RepositoryOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LocalRepository ¶
type LocalRepository struct {
Dir string
// contains filtered or unexported fields
}
LocalRepository represents a git repository.
func NewRepository ¶
func NewRepository(opts *RepositoryOptions) (*LocalRepository, error)
NewRepository provides access to a git repository based on the provided options.
If opts.Clone is CloneOptionNone, it opens an existing repository at opts.Dir. If opts.Clone is CloneOptionMaybe, it opens the repository if it exists, otherwise it clones from opts.RemoteURL. If opts.Clone is CloneOptionAlways, it always clones from opts.RemoteURL.
func (*LocalRepository) AddAll ¶
func (r *LocalRepository) AddAll() (git.Status, error)
AddAll adds all pending changes from the working tree to the index, so that the changes can later be committed.
func (*LocalRepository) ChangedFilesInCommit ¶
func (r *LocalRepository) ChangedFilesInCommit(commitHash string) ([]string, error)
ChangedFilesInCommit returns the files changed in the given commit.
func (*LocalRepository) Commit ¶
func (r *LocalRepository) Commit(msg string) error
Commit creates a new commit with the provided message and author information.
func (*LocalRepository) CreateBranchAndCheckout ¶
func (r *LocalRepository) CreateBranchAndCheckout(name string) error
CreateBranchAndCheckout creates a new git branch and checks out the branch in the local git repository.
func (*LocalRepository) GetCommit ¶
func (r *LocalRepository) GetCommit(commitHash string) (*Commit, error)
GetCommit returns a commit for the given commit hash.
func (*LocalRepository) GetCommitsForPathsSinceCommit ¶
func (r *LocalRepository) GetCommitsForPathsSinceCommit(paths []string, sinceCommit string) ([]*Commit, error)
GetCommitsForPathsSinceCommit returns the commits affecting any of the given paths, stopping looking at the given commit (which is not included in the results). The returned commits are ordered such that the most recent commit is first.
If sinceCommit is not provided, all commits are searched; otherwise, if no commit matching sinceCommit is found, an error is returned.
func (*LocalRepository) GetCommitsForPathsSinceTag ¶
func (r *LocalRepository) GetCommitsForPathsSinceTag(paths []string, tagName string) ([]*Commit, error)
GetCommitsForPathsSinceTag returns all commits since tagName that contains files in paths.
If tagName empty, all commits for the given paths are returned.
func (*LocalRepository) GetDir ¶
func (r *LocalRepository) GetDir() string
GetDir returns the directory of the repository.
func (*LocalRepository) HeadHash ¶
func (r *LocalRepository) HeadHash() (string, error)
HeadHash returns hash of the commit for the repository's HEAD.
func (*LocalRepository) IsClean ¶
func (r *LocalRepository) IsClean() (bool, error)
IsClean reports whether the working tree has no uncommitted changes.
func (*LocalRepository) Push ¶
func (r *LocalRepository) Push(branchName string) error
Push pushes the local branch to the origin remote.
type Repository ¶
type Repository interface {
AddAll() (git.Status, error)
Commit(msg string) error
IsClean() (bool, error)
Remotes() ([]*git.Remote, error)
GetDir() string
HeadHash() (string, error)
ChangedFilesInCommit(commitHash string) ([]string, error)
GetCommit(commitHash string) (*Commit, error)
GetCommitsForPathsSinceTag(paths []string, tagName string) ([]*Commit, error)
GetCommitsForPathsSinceCommit(paths []string, sinceCommit string) ([]*Commit, error)
CreateBranchAndCheckout(name string) error
Push(branchName string) error
}
Repository defines the interface for git repository operations.
type RepositoryOptions ¶
type RepositoryOptions struct {
// Dir is the directory where the repository will reside locally. Required.
Dir string
// MaybeClone will try to clone the repository if it does not exist locally.
// If set to true, RemoteURL and RemoteBranch must also be set. Optional.
MaybeClone bool
// RemoteURL is the URL of the remote repository to clone from. Required if MaybeClone is set to true.
RemoteURL string
// RemoteBranch is the remote branch to clone. Required if MaybeClone is set to true.
RemoteBranch string
// CI is the type of Continuous Integration (CI) environment in which
// the tool is executing.
CI string
// GitPassword is used for HTTP basic auth.
GitPassword string
}
RepositoryOptions are used to configure a LocalRepository.