Git.Command behaviour (git v0.4.0)

Copy Markdown View Source

Behaviour and runner for git commands.

Modules implementing this behaviour define how to build argument lists for a specific git subcommand and how to parse the resulting output.

Summary

Callbacks

Returns the argument list for this command.

Parses the stdout and exit code from the git process into a result.

Functions

Runs a git command.

Callbacks

args(command)

@callback args(command :: struct()) :: [String.t()]

Returns the argument list for this command.

parse_output(stdout, exit_code)

@callback parse_output(stdout :: String.t(), exit_code :: non_neg_integer()) ::
  {:ok, term()} | {:error, term()}

Parses the stdout and exit code from the git process into a result.

Functions

run(mod, command, config)

@spec run(module(), struct(), Git.Config.t()) :: {:ok, term()} | {:error, term()}

Runs a git command.

Takes a module implementing the Git.Command behaviour, a command struct, and a Git.Config. Builds the full argument list, executes git via System.cmd/3, and delegates parsing to the command module.

If the command exceeds the configured timeout, returns {:error, :timeout}.

Examples

Git.Command.run(Git.Commands.Status, %Git.Commands.Status{}, config)