Module: Git::Repository::Configuring

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

Overview

Legacy facade methods for reading and writing git configuration

Provides the #config and #global_config dispatch methods for 4.x compatibility. These methods return raw String / Hash values instead of ConfigEntryInfo objects and are retained so that internal callers such as Git::Status continue to work unchanged.

The structured config_* methods (e.g. config_get, config_list) are provided by Configuring, which is included directly into Git::Repository.

Included by Git::Repository.

Instance Method Summary collapse

Instance Method Details

#config(options = {}) ⇒ Hash{String => String} #config(name, options = {}) ⇒ 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:

  • #config(options = {}) ⇒ Hash{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" }

    List all entries from a custom config file

    repo.config(file: '/path/to/.gitconfig')
    #=> { "user.name" => "Alice", "core.bare" => "false" }

    Parameters:

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

      options for the list operation

    Options Hash (options):

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

      path to a custom config file to read from instead of the default resolution chain

    Returns:

    • (Hash{String => String})

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

    Raises:

    • (ArgumentError)

      if unsupported options are provided

  • #config(name, options = {}) ⇒ String

    Returns the value of the config entry.

    Examples:

    Read the committer name from config

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

    Read a value from a custom config file

    repo.config('user.name', file: '/path/to/.gitconfig') #=> "Alice"

    Parameters:

    • name (String)

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

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

      options for the get operation

    Options Hash (options):

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

      path to a custom config file to read from instead of the default resolution chain

    Returns:

    • (String)

      the value of the config entry

    Raises:

    • (ArgumentError)

      if unsupported options are provided

  • #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 (#to_s)

      the value to assign; must not be nil (a nil value is treated as "no value" and routes to the get overload). Must not be a Hash (a Hash is treated as the options argument; call value.to_s explicitly before passing if a stringified Hash is genuinely needed). Any other non-nil object is converted to a String via #to_s before being passed to git

    • 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:



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/git/repository/configuring.rb', line 110

def config(name = nil, value = nil, options = {})
  name, value, options = Private.normalize_config_args(name, value, options)

  if !name.nil? && !value.nil?
    Private.config_set(@execution_context, name, value, **options)
  elsif name
    Private.config_get(@execution_context, name, **options)
  else
    Private.config_list(@execution_context, **options)
  end
end

#global_configHash{String => String} #global_config(name) ⇒ String #global_config(name, value) ⇒ Git::CommandLineResult

Read or write a global git configuration entry

Dispatches to one of three modes depending on the arguments supplied, targeting the git global config scope (git config --global):

  • Listglobal_config() returns all global config entries as a Hash.
  • Getglobal_config(name) returns the value for a single key as a String.
  • Setglobal_config(name, value) writes a value and returns the raw command result.

Overloads:

  • #global_configHash{String => String}

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

    Examples:

    List all global config entries

    repo.global_config #=> { "user.name" => "Alice", "core.autocrlf" => "false" }

    Returns:

    • (Hash{String => String})

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

    Raises:

  • #global_config(name) ⇒ String

    Returns the value of the global config entry.

    Examples:

    Read the global committer name

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

    Parameters:

    • name (String)

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

    Returns:

    • (String)

      the value of the global config entry

    Raises:

  • #global_config(name, value) ⇒ Git::CommandLineResult

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

    Examples:

    Set the global committer name

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

    Parameters:

    • name (String)

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

    • value (#to_s)

      the value to assign; any object is accepted and converted to a String via #to_s before being passed to git

    Returns:

    Raises:



168
169
170
171
172
173
174
175
176
# File 'lib/git/repository/configuring.rb', line 168

def global_config(name = nil, value = nil)
  if !name.nil? && !value.nil?
    Private.global_config_set(@execution_context, name, value)
  elsif !name.nil?
    Private.global_config_get(@execution_context, name)
  else
    Private.global_config_list(@execution_context)
  end
end