Documentation
¶
Overview ¶
Package git provides a simple lightweight library for performing fluent git operations against an existing cloned repository
Index ¶
- type Client
- func (c *Client) Clone(url string) (string, error)
- func (c *Client) Commit(msg string) (string, error)
- func (c *Client) DeleteTag(tag string) (string, error)
- func (c *Client) Log(opts ...LogOption) (*Log, error)
- func (c *Client) Pull() (string, error)
- func (c *Client) Push() (string, error)
- func (c *Client) PushTag(tag string) (string, error)
- func (c *Client) Repository() (Repository, error)
- func (c *Client) Stage(opts ...StageOption) (string, error)
- func (c *Client) Tag(tag string, opts ...TagOption) (string, error)
- func (c *Client) Version() string
- type ErrGitExecCommand
- type ErrGitMissing
- type Log
- type LogEntry
- type LogOption
- func WithGrep(matches ...string) LogOption
- func WithInvertGrep(matches ...string) LogOption
- func WithMatchAll() LogOption
- func WithPaths(paths ...string) LogOption
- func WithRawOnly() LogOption
- func WithRef(ref string) LogOption
- func WithRefRange(fromRef string, toRef string) LogOption
- func WithSkip(n int) LogOption
- func WithTake(n int) LogOption
- type Repository
- type StageOption
- type TagOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a way of performing fluent operations against git. Any git operation exposed by this client are effectively handed-off to an installed git client on the current OS. Git operations will be mapped as closely as possible to the official Git specification
func (*Client) Clone ¶ added in v0.2.0
Clone a repository by its provided URL into a newly created directory. Remote tracking branches are created for each branch within the repository with only the default branch being checked out fully
func (*Client) Commit ¶
Commit a snapshot of changes within the current repository (working directory) and describe those changes with a given log message
func (*Client) Log ¶
Log retrieves the commit log of the current repository (working directory) in an easy-to-parse format. Options can be provided to customize log retrieval, creating a targeted snapshot. By default, the entire history from the repository HEAD (most recent commit) will be retrieved. The logs are generated using the default git options:
git log --pretty=oneline --no-decorate --no-color
func (*Client) Pull ¶
Pull all changes from a remote repository and immediately update the current repository (current working) directory with those changes. This ensures that your current repository keeps track of remote changes and stays in sync
func (*Client) Repository ¶ added in v0.2.0
func (c *Client) Repository() (Repository, error)
Repository returns details about the current repository (working directory), by carrying out a series of checks. Answers to which are returned as a snapshot for querying
func (*Client) Stage ¶
func (c *Client) Stage(opts ...StageOption) (string, error)
Stage changes to any file or folder within the current repository (working directory) ready for inclusion in the next commit
func (*Client) Tag ¶
Tag a specific point within a repositories history and push it to the configured remote. Tagging comes in two flavours:
- A lightweight tag, which points to a specific commit within the history and marks a specific point in time
- An annotated tag, which is treated as a full object within git, and must include a tagging message (or annotation)
By default, a lightweight tag will be created, unless specific tag options are provided
type ErrGitExecCommand ¶
type ErrGitExecCommand struct {
// Cmd contains the command that caused the git client to error
Cmd string
// Out contains any raw output from the git client as a result
// of the error
Out string
}
ErrGitExecCommand is raised when a git command fails to execute
func (ErrGitExecCommand) Error ¶
func (e ErrGitExecCommand) Error() string
Error returns a friendly formatted message of the current error
type ErrGitMissing ¶
type ErrGitMissing struct {
// PathEnv contains the value of the PATH environment variable
PathEnv string
}
ErrGitMissing is raised when no git client was identified within the PATH environment variable on the current OS
func (ErrGitMissing) Error ¶
func (e ErrGitMissing) Error() string
Error returns a friendly formatted message of the current error
type Log ¶
type Log struct {
// Raw contains the raw commit log
Raw string
// Commits contains the optionally parsed commit log. By default
// the parsed history will always be present, unless the
// [WithRawOnly] option is provided during retrieval
Commits []LogEntry
}
Log represents a snapshot of commit history from a repository
type LogEntry ¶
type LogEntry struct {
// Hash contains the unique identifier associated with the commit
Hash string
// AbbrevHash contains the seven character abbreviated commit hash
AbbrevHash string
// Message contains the message associated with the commit
Message string
}
LogEntry represents a single parsed entry from within the commit history of a repository
type LogOption ¶
type LogOption func(*logOptions)
LogOption provides a way for setting specific options during a log operation. Each supported option can customize the way the log history of the current repository (working directory) is processed before retrieval
func WithGrep ¶ added in v0.2.0
WithGrep limits the number of commits that will be output within the log history to any with a log message that contains one of the provided matches (regular expressions). All leading and trailing whitespace will be trimmed, allowing empty matches to be ignored
func WithInvertGrep ¶ added in v0.2.0
WithInvertGrep limits the number of commits that will be output within the log history to any with a log message that does not contain one of the provided matches (regular expressions). All leading and trailing whitespace will be trimmed, allowing empty matches to be ignored
func WithMatchAll ¶ added in v0.2.0
func WithMatchAll() LogOption
WithMatchAll when used in combination with git.WithGrep will limit the number of returned commits to those whose log message contains all of the provided matches (regular expressions)
func WithPaths ¶
WithPaths allows the log history to be retrieved for any number of files and folders within the current repository (working directory). Only commits that have had a direct impact on those files and folders will be retrieved. Paths to files and folders are relative to the root of the repository. All leading and trailing whitespace will be trimmed from the file paths, allowing empty paths to be ignored
func WithRawOnly ¶
func WithRawOnly() LogOption
WithRawOnly ensures only the raw output from the git log of the current repository (working directory) is retrieved. No post-processing is carried out, resulting in an empty Log.Commits slice
func WithRef ¶
WithRef provides a starting point other than HEAD (most recent commit) when retrieving the log history of the current repository (working directory). Typically a reference can be either a commit hash, branch name or tag. The output of this option will typically be a shorter, fine-tuned history. This option is mutually exclusive with WithRefRange. All leading and trailing whitespace are trimmed from the reference, allowing empty references to be ignored
func WithRefRange ¶
WithRefRange provides both a start and end point when retrieving a focused snapshot of the log history from the current repository (working directory). Typically a reference can be either a commit hash, branch name or tag. The output of this option will be a shorter, fine-tuned history, for example, the history between two tags. This option is mutually exclusive with WithRef. All leading and trailing whitespace are trimmed from the references, allowing empty references to be ignored
func WithSkip ¶ added in v0.2.0
WithSkip skips any number of most recent commits from within the log history. A positive number (greater than zero) is expected. Skipping more commits than exists, will result in no history being retrieved. Skipping zero commits, will retrieve the entire log. This option has a higher order of precedence than git.WithTake
func WithTake ¶ added in v0.2.0
WithTake limits the number of commits that will be output within the log history. A positive number (greater than zero) is expected. Taking more commits than exists, has the same effect as retrieving the entire log. Taking zero commits, will retrieve an empty log. This option has a lower order of precedence than git.WithSkip
type Repository ¶ added in v0.2.0
Repository provides a snapshot of the current state of a repository (working directory)
type StageOption ¶ added in v0.2.0
type StageOption func(*stageOptions)
StageOption provides a way for setting specific options during a stage operation. Each supported option can customize the way files are staged within the current repository (working directory)
func WithPathSpecs ¶ added in v0.2.0
func WithPathSpecs(specs ...string) StageOption
WithPathSpecs permits a series of PathSpecs (or globs) to be defined that will stage any matching files within the current repository (working directory). Paths to files and folders are relative to the root of the repository. All leading and trailing whitespace will be trimmed from the file paths, allowing empty paths to be ignored
type TagOption ¶
type TagOption func(*tagOptions)
TagOption provides a way for setting specific options during a tag operation. Each supported option can customize the way the tag is applied against the current repository (working directory)
func WithAnnotation ¶
WithAnnotation ensures the created tag is annotated with the provided message. This ultimately converts the standard lightweight tag into an annotated tag which is stored as a full object within the git database. Any leading and trailing whitespace will automatically be trimmed from the message. This allows empty messages to be ignored