Documentation
¶
Index ¶
- Constants
- Variables
- type CmdOptionFunc
- func WithAction(action string) CmdOptionFunc
- func WithAlternateObjectDirs(dirs ...string) CmdOptionFunc
- func WithArg(args ...string) CmdOptionFunc
- func WithAuthor(name, email string) CmdOptionFunc
- func WithAuthorAndDate(name, email string, date time.Time) CmdOptionFunc
- func WithCommitter(name, email string) CmdOptionFunc
- func WithCommitterAndDate(name, email string, date time.Time) CmdOptionFunc
- func WithConfig(key, value string) CmdOptionFunc
- func WithEnv(keyValPairs ...string) CmdOptionFunc
- func WithFlag(flags ...string) CmdOptionFunc
- func WithGlobal(flags ...string) CmdOptionFunc
- func WithPostSepArg(args ...string) CmdOptionFunc
- type Command
- type Envs
- type Error
- type RunOption
- type RunOptionFunc
Constants ¶
const ( // NoRefUpdates denotes a command which will never update refs. NoRefUpdates = 1 << iota // NoEndOfOptions denotes a command which doesn't know --end-of-options. NoEndOfOptions )
const ( GitCommitterName = "GIT_COMMITTER_NAME" GitCommitterEmail = "GIT_COMMITTER_EMAIL" GitCommitterDate = "GIT_COMMITTER_DATE" GitAuthorName = "GIT_AUTHOR_NAME" GitAuthorEmail = "GIT_AUTHOR_EMAIL" GitAuthorDate = "GIT_AUTHOR_DATE" GitTrace = "GIT_TRACE" GitTracePack = "GIT_TRACE_PACK_ACCESS" GitTracePackAccess = "GIT_TRACE_PACKET" GitTracePerformance = "GIT_TRACE_PERFORMANCE" GitTraceSetup = "GIT_TRACE_SETUP" GitExecPath = "GIT_EXEC_PATH" // tells Git where to find its binaries. GitObjectDir = "GIT_OBJECT_DIRECTORY" GitAlternateObjectDirs = "GIT_ALTERNATE_OBJECT_DIRECTORIES" )
Variables ¶
var ( // ErrInvalidArg represent family of errors to report about bad argument used to make a call. ErrInvalidArg = errors.New("invalid argument") )
var (
GitExecutable = "git"
)
Functions ¶
This section is empty.
Types ¶
type CmdOptionFunc ¶
type CmdOptionFunc func(c *Command)
func WithAction ¶
func WithAction(action string) CmdOptionFunc
WithAction set the action of the Git command, e.g. "set-url" in `git remote set-url`.
func WithAlternateObjectDirs ¶
func WithAlternateObjectDirs(dirs ...string) CmdOptionFunc
WithAlternateObjectDirs function sets alternates directories for object access.
func WithArg ¶
func WithArg(args ...string) CmdOptionFunc
WithArg add arguments that shall be passed after all flags.
func WithAuthor ¶
func WithAuthor(name, email string) CmdOptionFunc
WithAuthor sets given author to the command.
func WithAuthorAndDate ¶
func WithAuthorAndDate(name, email string, date time.Time) CmdOptionFunc
WithAuthorAndDate sets given author and date to the command.
func WithCommitter ¶
func WithCommitter(name, email string) CmdOptionFunc
WithCommitter sets given committer to the command.
func WithCommitterAndDate ¶
func WithCommitterAndDate(name, email string, date time.Time) CmdOptionFunc
WithCommitterAndDate sets given committer and date to the command.
func WithConfig ¶
func WithConfig(key, value string) CmdOptionFunc
WithConfig function sets key and value for config command.
func WithEnv ¶
func WithEnv(keyValPairs ...string) CmdOptionFunc
WithEnv sets environment variable using key value pair for example: WithEnv("GIT_TRACE", "true").
func WithFlag ¶
func WithFlag(flags ...string) CmdOptionFunc
WithFlag set optional flags to pass before positional arguments.
func WithGlobal ¶
func WithGlobal(flags ...string) CmdOptionFunc
WithGlobal set the global optional flag of the Git command.
func WithPostSepArg ¶
func WithPostSepArg(args ...string) CmdOptionFunc
WithPostSepArg set arguments that shall be passed as positional arguments after the `--`.
type Command ¶
type Command struct {
// Globals is the number of optional flags to pass before command name.
// example: git --shallow-file pack-objects ...
Globals []string
// Name is the name of the Git command to run, e.g. "log", "cat-file" or "worktree".
Name string
// Action is the action of the Git command, e.g. "set-url" in `git remote set-url`
Action string
// Flags is the number of optional flags to pass before positional arguments, e.g.
// `--oneline` or `--format=fuller`.
Flags []string
// Args is the arguments that shall be passed after all flags. These arguments must not be
// flags and thus cannot start with `-`. Note that it may be unsafe to use this field in the
// case where arguments are directly user-controlled. In that case it is advisable to use
// `PostSepArgs` instead.
Args []string
// PostSepArgs is the arguments that shall be passed as positional arguments after the `--`
// separator. Git recognizes that separator as the point where it should stop expecting any
// options and treat the remaining arguments as positionals. This should be used when
// passing user-controlled input of arbitrary form like for example paths, which may start
// with a `-`.
PostSepArgs []string
// Git environment variables
Envs Envs
// contains filtered or unexported fields
}
Command contains options for running a git command.
func New ¶
func New(name string, options ...CmdOptionFunc) *Command
New creates new command for interacting with the git process.
func Parse ¶
Parse os args to Command object. This is very basic parser which doesn't care about flags or positional args values it just injects into proper slice of command struct. Every git command can contain globals:
git --help
command:
git version git diff
action:
git remote set-url ...
command or action flags:
git diff --shortstat
command or action args:
git diff --shortstat main...dev
post args:
git diff main...dev -- file1
func (*Command) Add ¶
func (c *Command) Add(options ...CmdOptionFunc) *Command
Add appends given options to the command.
type Error ¶
Error type with optional ExitCode and Stderr payload.
func (*Error) IsAmbiguousArgErr ¶
func (*Error) IsExitCode ¶
func (*Error) IsInvalidRefErr ¶
type RunOption ¶
type RunOption struct {
// Dir is location of repo.
Dir string
// Stdin is the input to the command.
Stdin io.Reader
// Stdout is the outputs from the command.
Stdout io.Writer
// Stderr is the error output from the command.
Stderr io.Writer
// Envs is environments slice containing (final) immutable
// environment pair "ENV=value"
Envs []string
}
RunOption contains option for running a command.
type RunOptionFunc ¶
type RunOptionFunc func(option *RunOption)
func WithDir ¶
func WithDir(dir string) RunOptionFunc
WithDir set directory RunOption.Dir, this is repository dir where git command should be running.
func WithEnvs ¶
func WithEnvs(envs ...string) RunOptionFunc
WithEnvs sets immutable values as slice, it is always added et the end of env slice.
func WithStderr ¶
func WithStderr(stderr io.Writer) RunOptionFunc
WithStderr set RunOption.Stderr writer.
func WithStdin ¶
func WithStdin(stdin io.Reader) RunOptionFunc
WithStdin set RunOption.Stdin reader.
func WithStdout ¶
func WithStdout(stdout io.Writer) RunOptionFunc
WithStdout set RunOption.Stdout writer.