dulwich.config module

Reading and writing Git configuration files.

class dulwich.config.CaseInsensitiveDict

Bases: collections.OrderedDict

get(key, default=<object object>)

Return the value for key if key is in the dictionary, else default.

classmethod make(dict_in=None)
setdefault(key, default=<object object>)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

class dulwich.config.Config

Bases: object

A Git configuration.

get(section, name)

Retrieve the contents of a configuration setting.

Parameters
  • section – Tuple with section name and optional subsection namee

  • subsection – Subsection name

Returns

Contents of the setting

Raises

KeyError – if the value is not set

get_boolean(section, name, default=None)

Retrieve a configuration setting as boolean.

Parameters
  • section – Tuple with section name and optional subsection name

  • name – Name of the setting, including section and possible subsection.

Returns

Contents of the setting

Raises

KeyError – if the value is not set

has_section(name)

Check if a specified section exists.

Parameters

name – Name of section to check for

Returns

boolean indicating whether the section exists

iteritems(section)

Iterate over the configuration pairs for a specific section.

Parameters

section – Tuple with section name and optional subsection namee

Returns

Iterator over (name, value) pairs

itersections()

Iterate over the sections.

Returns: Iterator over section tuples

set(section, name, value)

Set a configuration value.

Parameters
  • section – Tuple with section name and optional subsection namee

  • name

    Name of the configuration value, including section

    and optional subsection

    value: value of the setting

class dulwich.config.ConfigDict(values=None, encoding=None)

Bases: dulwich.config.Config, collections.abc.MutableMapping

Git configuration stored in a dictionary.

Create a new ConfigDict.

get(section, name)

Retrieve the contents of a configuration setting.

Parameters
  • section – Tuple with section name and optional subsection namee

  • subsection – Subsection name

Returns

Contents of the setting

Raises

KeyError – if the value is not set

iteritems(section)

Iterate over the configuration pairs for a specific section.

Parameters

section – Tuple with section name and optional subsection namee

Returns

Iterator over (name, value) pairs

itersections()

Iterate over the sections.

Returns: Iterator over section tuples

set(section, name, value)

Set a configuration value.

Parameters
  • section – Tuple with section name and optional subsection namee

  • name

    Name of the configuration value, including section

    and optional subsection

    value: value of the setting

class dulwich.config.ConfigFile(values=None, encoding=None)

Bases: dulwich.config.ConfigDict

A Git configuration file, like .git/config or ~/.gitconfig.

Create a new ConfigDict.

classmethod from_file(f: BinaryIO)dulwich.config.ConfigFile

Read configuration from a file-like object.

classmethod from_path(path)dulwich.config.ConfigFile

Read configuration from a file on disk.

write_to_file(f: BinaryIO)None

Write configuration to a file-like object.

write_to_path(path=None)None

Write configuration to a file on disk.

class dulwich.config.StackedConfig(backends, writable=None)

Bases: dulwich.config.Config

Configuration which reads from multiple config files..

classmethod default()
classmethod default_backends()

Retrieve the default configuration.

See git-config(1) for details on the files searched.

get(section, name)

Retrieve the contents of a configuration setting.

Parameters
  • section – Tuple with section name and optional subsection namee

  • subsection – Subsection name

Returns

Contents of the setting

Raises

KeyError – if the value is not set

set(section, name, value)

Set a configuration value.

Parameters
  • section – Tuple with section name and optional subsection namee

  • name

    Name of the configuration value, including section

    and optional subsection

    value: value of the setting

dulwich.config.get_win_system_paths()
dulwich.config.get_xdg_config_home_path(*path_segments)
dulwich.config.lower_key(key)
dulwich.config.parse_submodules(config)

Parse a gitmodules GitConfig file, returning submodules.

Parameters

config – A ConfigFile

Returns

list of tuples (submodule path, url, name),

where name is quoted part of the section’s name.