Documentation
¶
Overview ¶
Package gitrepo provides operations on git repos.
Index ¶
- type Commit
- type Repository
- func (r *Repository) AddAll() (git.Status, error)
- func (r *Repository) Checkout(commit string) error
- func (r *Repository) CleanAndRevertCommits(count int) error
- func (r *Repository) CleanAndRevertHeadCommit() error
- func (r *Repository) CleanWorkingTree() error
- func (r *Repository) Commit(msg string, userName, userEmail string) error
- func (r *Repository) GetCommitsForPathsSinceCommit(paths []string, sinceCommit string) ([]*Commit, error)
- func (r *Repository) GetCommitsForPathsSinceTag(paths []string, tagName string) ([]*Commit, error)
- func (r *Repository) GetCommitsForReleaseID(releaseID string) ([]*Commit, error)
- func (r *Repository) HeadHash() (string, error)
- func (r *Repository) IsClean() (bool, error)
- func (r *Repository) PrintStatus() error
- func (r *Repository) PushBranch(remoteBranch string, accessToken string) error
- func (r *Repository) Remotes() ([]*git.Remote, error)
- type RepositoryOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Repository ¶
type Repository struct {
Dir string
// contains filtered or unexported fields
}
Repository represents a git repository.
func NewRepository ¶
func NewRepository(opts *RepositoryOptions) (*Repository, 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 (*Repository) AddAll ¶
func (r *Repository) 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 (*Repository) Checkout ¶
func (r *Repository) Checkout(commit string) error
Checkout checks out the given commit in the repository.
func (*Repository) CleanAndRevertCommits ¶
func (r *Repository) CleanAndRevertCommits(count int) error
CleanAndRevertCommits the specified number of commits in the repository, by counting commits backwards from the head and then doing a hard reset for the target commit, then a clean.
func (*Repository) CleanAndRevertHeadCommit ¶
func (r *Repository) CleanAndRevertHeadCommit() error
CleanAndRevertHeadCommit drops any local changes, and also reset to the parent of the current head commit. This is a special case of CleanAndRevertCommits where the count is 1.
func (*Repository) CleanWorkingTree ¶
func (r *Repository) CleanWorkingTree() error
CleanWorkingTree Drops any local changes NOT committed, but keeps any local commits
func (*Repository) Commit ¶
func (r *Repository) Commit(msg string, userName, userEmail string) error
Commit creates a new commit with the provided message and author information.
func (*Repository) GetCommitsForPathsSinceCommit ¶
func (r *Repository) 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 (*Repository) GetCommitsForPathsSinceTag ¶
func (r *Repository) GetCommitsForPathsSinceTag(paths []string, tagName string) ([]*Commit, error)
GetCommitsForPathsSinceTag returns all commits since tagName that contains files in paths.
If tagName is empty, all commits for the given paths are returned.
func (*Repository) GetCommitsForReleaseID ¶
func (r *Repository) GetCommitsForReleaseID(releaseID string) ([]*Commit, error)
GetCommitsForReleaseID returns all commits with the given release ID, i.e. where the commit message contains a line of `Librarian-Release-Id: <release-id>`. These commits are expected to be contiguous, from head, with all commits having a single parent.
func (*Repository) HeadHash ¶
func (r *Repository) HeadHash() (string, error)
HeadHash returns the hash of the head commit in the repository's current branch.
func (*Repository) IsClean ¶
func (r *Repository) IsClean() (bool, error)
IsClean reports whether the working tree has no uncommitted changes.
func (*Repository) PrintStatus ¶
func (r *Repository) PrintStatus() error
PrintStatus prints the status of the working tree of the repository, similar to running "git status" from the command line.
func (*Repository) PushBranch ¶
func (r *Repository) PushBranch(remoteBranch string, accessToken string) error
PushBranch creates a branch with the given name in the default remote.
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 must also be set. Optional.
MaybeClone bool
// RemoteURL is the URL of the remote repository to clone from. Required if Clone is not CloneOptionNone.
RemoteURL string
// CI is the type of Continuous Integration (CI) environment in which
// the tool is executing.
CI string
}
RepositoryOptions are used to configure a Repository.