Git.Config (git v0.4.0)

Copy Markdown View Source

Configuration for the git CLI wrapper.

Holds the path to the git binary, working directory, environment variables, and timeout settings used when executing git commands.

Summary

Functions

Returns the base arguments for all git commands.

Builds the options keyword list for System.cmd/3.

Finds the git binary on the system.

Creates a new Git.Config struct.

Types

t()

@type t() :: %Git.Config{
  binary: String.t(),
  env: [{String.t(), String.t()}],
  timeout: pos_integer(),
  working_dir: String.t() | nil
}

Functions

base_args(config)

@spec base_args(t()) :: [String.t()]

Returns the base arguments for all git commands.

Git does not require any global flags, so this returns an empty list.

cmd_opts(config)

@spec cmd_opts(t()) :: keyword()

Builds the options keyword list for System.cmd/3.

Includes :cd, :env, and :stderr_to_stdout based on the config.

find_binary()

@spec find_binary() :: String.t()

Finds the git binary on the system.

Checks the GIT_PATH environment variable first, then falls back to System.find_executable("git").

Raises if git cannot be found.

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new Git.Config struct.

Options

  • :binary - path to the git executable (default: auto-detected)
  • :working_dir - working directory for git commands (default: nil, uses current directory)
  • :env - list of {key, value} tuples for environment variables (default: [])
  • :timeout - command timeout in milliseconds (default: 30000)

Examples

iex> config = Git.Config.new()
iex> String.ends_with?(config.binary, "git")
true

iex> config = Git.Config.new(working_dir: "/tmp", timeout: 10_000)
iex> config.working_dir
"/tmp"
iex> config.timeout
10_000