module documentation

Reading and writing Git configuration files.

Todo

  • preserve formatting when updating configuration files
Class CaseInsensitiveOrderedMultiDict A case-insensitive ordered dictionary that can store multiple values per key.
Class Config A Git configuration.
Class ConfigDict Git configuration stored in a dictionary.
Class ConfigFile A Git configuration file, like .git/config or ~/.gitconfig.
Class StackedConfig Configuration which reads from multiple config files..
Function apply_instead_of Apply insteadOf / pushInsteadOf to a URL.
Function get_git_proxy_command Look up the core.gitProxy command for the given host.
Function get_win_legacy_system_paths Get legacy Windows system Git config paths.
Function get_win_system_paths Get current Windows system Git config paths.
Function get_xdg_config_home_path Get a path in the XDG config home directory.
Function iter_instead_of Iterate over insteadOf / pushInsteadOf values.
Function lower_key Convert a config key to lowercase, preserving subsection case.
Function match_glob_pattern Match a value against a glob pattern.
Function parse_submodules Parse a gitmodules GitConfig file, returning submodules.
Function read_submodules Read a .gitmodules file.
Constant DEFAULT_MAX_INCLUDE_DEPTH Undocumented
Constant MAX_INCLUDE_FILE_SIZE Undocumented
Type Variable K Undocumented
Type Variable V Undocumented
Type Alias ConditionMatcher Undocumented
Type Alias FileOpener Undocumented
Type Alias Section Undocumented
Variable ConfigKey Undocumented
Variable ConfigValue Undocumented
Variable logger Undocumented
Variable NameLike Undocumented
Variable SectionLike Undocumented
Variable ValueLike Undocumented
Function _check_section_name Undocumented
Function _check_variable_name Undocumented
Function _escape_value Escape a value.
Function _find_git_in_win_path Undocumented
Function _find_git_in_win_reg Undocumented
Function _format_string Undocumented
Function _is_line_continuation Check if a value ends with a line continuation backslash.
Function _match_gitdir_pattern Simple gitdir pattern matching for includeIf conditions.
Function _parse_section_header_line Undocumented
Function _parse_string Undocumented
Function _strip_comments Undocumented
Constant _COMMENT_CHARS Undocumented
Constant _ESCAPE_TABLE Undocumented
Constant _WHITESPACE_CHARS Undocumented
Type Variable _T Undocumented
def apply_instead_of(config: Config, orig_url: str, push: bool = False) -> str:

Apply insteadOf / pushInsteadOf to a URL.

def get_git_proxy_command(config: Config, host: str) -> str | None:

Look up the core.gitProxy command for the given host.

The core.gitProxy variable can appear multiple times, each with an optional for <domain> suffix. The first entry whose domain suffix matches the end of host wins; an entry without a for clause is a catch-all default.

Parameters
config:ConfigA Config instance.
host:strThe hostname being connected to.
Returns
str | NoneThe proxy command string, or None if no proxy is configured.
def get_win_legacy_system_paths() -> Iterator[str]:

Get legacy Windows system Git config paths.

Returns all possible config paths including deprecated locations. This function can be used for diagnostics or migration purposes.

def get_win_system_paths() -> Iterator[str]:

Get current Windows system Git config paths.

Only returns the current Git for Windows config location, not legacy paths.

def get_xdg_config_home_path(*path_segments: str) -> str:

Get a path in the XDG config home directory.

Parameters
*path_segments:strPath segments to join to the XDG config home
Returns
strFull path in XDG config home directory
def iter_instead_of(config: Config, push: bool = False) -> Iterable[tuple[str, str]]:

Iterate over insteadOf / pushInsteadOf values.

def lower_key(key: ConfigKey) -> ConfigKey:

Convert a config key to lowercase, preserving subsection case.

Parameters
key:ConfigKeyConfiguration key (str, bytes, or tuple)
Returns
ConfigKeyKey with section names lowercased, subsection names preserved
Raises
TypeErrorIf key is not str, bytes, or tuple
def match_glob_pattern(value: str, pattern: str) -> bool:

Match a value against a glob pattern.

Supports simple glob patterns like * and **.

Raises
ValueErrorIf the pattern is invalid
def parse_submodules(config: ConfigFile) -> Iterator[tuple[bytes, bytes, bytes]]:

Parse a gitmodules GitConfig file, returning submodules.

Parameters
config:ConfigFileA ConfigFile
Returns
Iterator[tuple[bytes, bytes, bytes]]
list of tuples (submodule path, url, name),
where name is quoted part of the section's name.
def read_submodules(path: str | os.PathLike[str]) -> Iterator[tuple[bytes, bytes, bytes]]:

Read a .gitmodules file.

DEFAULT_MAX_INCLUDE_DEPTH: int =

Undocumented

Value
10
MAX_INCLUDE_FILE_SIZE =

Undocumented

Value
1024 * 1024
K =

Undocumented

Value
TypeVar('K',
        bound=ConfigKey)
V =

Undocumented

Value
TypeVar('V')
ConditionMatcher =

Undocumented

Value
Callable[[str], bool]
FileOpener =

Undocumented

Value
Callable[[(str | os.PathLike[str])], IO[bytes]]
Section =

Undocumented

Value
tuple[bytes, ...]
ConfigKey =

Undocumented

ConfigValue =

Undocumented

logger =

Undocumented

NameLike =

Undocumented

SectionLike =

Undocumented

ValueLike =

Undocumented

def _check_section_name(name: bytes) -> bool:

Undocumented

def _check_variable_name(name: bytes) -> bool:

Undocumented

def _escape_value(value: bytes) -> bytes:

Escape a value.

def _find_git_in_win_path() -> Iterator[str]:

Undocumented

def _find_git_in_win_reg() -> Iterator[str]:

Undocumented

def _format_string(value: bytes) -> bytes:

Undocumented

def _is_line_continuation(value: bytes) -> bool:

Check if a value ends with a line continuation backslash.

A line continuation occurs when a line ends with a backslash that is: 1. Not escaped (not preceded by another backslash) 2. Not within quotes

Parameters
value:bytesThe value to check
Returns
boolTrue if the value ends with a line continuation backslash
def _match_gitdir_pattern(path: bytes, pattern: bytes, ignorecase: bool = False) -> bool:

Simple gitdir pattern matching for includeIf conditions.

This handles the basic gitdir patterns used in includeIf directives.

def _parse_section_header_line(line: bytes) -> tuple[Section, bytes]:

Undocumented

def _parse_string(value: bytes) -> bytes:

Undocumented

def _strip_comments(line: bytes) -> bytes:

Undocumented

_COMMENT_CHARS =

Undocumented

Value
[ord(b'#'), ord(b';')]
_ESCAPE_TABLE =

Undocumented

Value
{ord(b'\\'): ord(b'\\'),
 ord(b'"'): ord(b'"'),
 ord(b'n'): ord(b'\n'),
 ord(b't'): ord(b'\t'),
 ord(b'b'): ord(b'\x08')}
_WHITESPACE_CHARS =

Undocumented

Value
[ord(b'\t'), ord(b' ')]
_T =

Undocumented

Value
TypeVar('_T')