Class: Git::Commands::ConfigOptionSyntax::Set Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/config_option_syntax/set.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

arguments block audited against https://git-scm.com/docs/git-config/2.53.0

Set a config value

Wraps the implicit git config <name> <value> set mode to assign a value to a config key, optionally replacing only the entry matching a value regex.

Examples:

Set a local config value

cmd = Git::Commands::ConfigOptionSyntax::Set.new(lib)
cmd.call('user.name', 'Alice')

Set a global config value

cmd = Git::Commands::ConfigOptionSyntax::Set.new(lib)
cmd.call('user.name', 'Alice', global: true)

Set a value with a type constraint

cmd = Git::Commands::ConfigOptionSyntax::Set.new(lib)
cmd.call('core.bare', 'true', type: 'bool')

See Also:

Instance Method Summary collapse

Methods inherited from Base

allow_exit_status, arguments, #initialize, requires_git_version, skip_version_validation

Constructor Details

This class inherits a constructor from Git::Commands::Base

Instance Method Details

#call(name, value, value_regex = nil, **options) ⇒ Git::CommandLineResult

Execute the git config <name> <value> command

Parameters:

  • name (String)

    the config key name to set

  • value (String)

    the value to assign

  • value_regex (String, nil) (defaults to: nil)

    (nil) optional regex to match the existing value to replace

  • options (Hash)

    command options

Options Hash (**options):

  • :replace_all (Boolean, nil) — default: nil

    replace all lines matching the key

  • :append (Boolean, nil) — default: nil

    add a new line without altering existing values

  • :comment (String) — default: nil

    append a comment at the end of new or modified lines

  • :global (Boolean, nil) — default: nil

    write to global config (~/.gitconfig)

  • :system (Boolean, nil) — default: nil

    write to system config

  • :local (Boolean, nil) — default: nil

    write to repository config (.git/config)

  • :worktree (Boolean, nil) — default: nil

    write to worktree config

  • :file (String) — default: nil

    write to the specified file

    Alias: :f

  • :blob (String) — default: nil

    read from the specified blob

  • :fixed_value (Boolean, nil) — default: nil

    treat the value regex as an exact string

  • :type (String) — default: nil

    ensure the value conforms to the given type

  • :no_type (Boolean, nil) — default: nil

    unset the previously set type specifier; true emits --no-type

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (Git::FailedError)

    if git exits with a non-zero exit status



# File 'lib/git/commands/config_option_syntax/set.rb', line 65