Module: Git::Repository::Configuring

Included in:
Git::Repository
Defined in:
lib/git/repository/configuring.rb

Overview

Facade methods for reading and writing git configuration

Provides the #config method, which dispatches to read a single entry, list all entries, or write a value depending on the arguments supplied.

Included by Git::Repository.

Instance Method Summary collapse

Instance Method Details

#configHash{String => String} #config(name) ⇒ String #config(name, value, options = {}) ⇒ Git::CommandLineResult

Read or write a git configuration entry

Dispatches to one of three modes depending on the arguments supplied:

  • Listconfig() returns all visible config entries as a Hash.
  • Getconfig(name) returns the value for a single key as a String.
  • Setconfig(name, value) writes a value and returns the raw command result.

Overloads:

  • #configHash{String => String}

    Returns all visible config entries, keyed by their full dotted key names (e.g. "user.name").

    Examples:

    List all config entries

    repo.config #=> { "user.name" => "Alice", "core.bare" => "false" }

    Returns:

    • (Hash{String => String})

      all visible config entries, keyed by their full dotted key names (e.g. "user.name")

  • #config(name) ⇒ String

    Returns the value of the config entry.

    Examples:

    Read the committer name from config

    repo.config('user.name') #=> "Alice"

    Parameters:

    • name (String)

      the dotted config key to look up (e.g. "user.name")

    Returns:

    • (String)

      the value of the config entry

  • #config(name, value, options = {}) ⇒ Git::CommandLineResult

    Returns the raw result of git config <name> <value>.

    Examples:

    Set the committer name in local config

    repo.config('user.name', 'Alice')

    Write a value to a custom config file

    repo.config('user.name', 'Alice', file: '/path/to/custom/config')

    Parameters:

    • name (String)

      the dotted config key to write (e.g. "user.name")

    • value (String)

      the value to assign

    • options (Hash) (defaults to: {})

      options for the set operation

    Options Hash (options):

    • :file (String, nil) — default: nil

      path to a custom config file to write to instead of the repository's default .git/config

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

Raises:



74
75
76
77
78
79
80
81
82
# File 'lib/git/repository/configuring.rb', line 74

def config(name = nil, value = nil, options = {})
  if name && value
    Private.config_set(@execution_context, name, value, **options)
  elsif name
    Private.config_get(@execution_context, name)
  else
    Private.config_list(@execution_context)
  end
end