class documentation

A collection of gitattributes patterns that can match paths.

Class Method from_file Create GitAttributes from a gitattributes file.
Class Method from_path Create GitAttributes from .gitattributes in a directory.
Method __init__ Initialize GitAttributes.
Method __iter__ Iterate over patterns.
Method __len__ Return the number of patterns.
Method add_patterns Add patterns to the collection.
Method match_path Get attributes for a path by matching against patterns.
Method remove_pattern Remove all attributes for a pattern.
Method set_attribute Set an attribute for a pattern.
Method to_bytes Convert GitAttributes to bytes format suitable for writing to file.
Method write_to_file Write GitAttributes to a file.
Instance Variable _patterns Undocumented
def from_file(cls, filename: str | bytes) -> GitAttributes:

Create GitAttributes from a gitattributes file.

Parameters
filename:str | bytesPath to the .gitattributes file
Returns
GitAttributesNew GitAttributes instance
def from_path(cls, path: str | bytes) -> GitAttributes:

Create GitAttributes from .gitattributes in a directory.

Parameters
path:str | bytesDirectory path to check for .gitattributes
Returns
GitAttributesNew GitAttributes instance
def __init__(self, patterns: list[tuple[Pattern, Mapping[bytes, AttributeValue]]] | None = None):

Initialize GitAttributes.

Parameters
patterns:list[tuple[Pattern, Mapping[bytes, AttributeValue]]] | NoneOptional list of (Pattern, attributes) tuples
def __iter__(self) -> Iterator[tuple[Pattern, Mapping[bytes, AttributeValue]]]:

Iterate over patterns.

def __len__(self) -> int:

Return the number of patterns.

def add_patterns(self, patterns: Sequence[tuple[Pattern, Mapping[bytes, AttributeValue]]]):

Add patterns to the collection.

Parameters
patterns:Sequence[tuple[Pattern, Mapping[bytes, AttributeValue]]]List of (Pattern, attributes) tuples to add
def match_path(self, path: bytes) -> dict[bytes, AttributeValue]:

Get attributes for a path by matching against patterns.

Parameters
path:bytesPath to match (relative to repository root)
Returns
dict[bytes, AttributeValue]Dictionary of attributes that apply to this path
def remove_pattern(self, pattern: bytes):

Remove all attributes for a pattern.

Parameters
pattern:bytesThe file pattern to remove
def set_attribute(self, pattern: bytes, name: bytes, value: AttributeValue):

Set an attribute for a pattern.

Parameters
pattern:bytesThe file pattern
name:bytesAttribute name
value:AttributeValueAttribute value (bytes, True, False, or None)
def to_bytes(self) -> bytes:

Convert GitAttributes to bytes format suitable for writing to file.

Returns
bytesBytes representation of the gitattributes file
def write_to_file(self, filename: str | bytes):

Write GitAttributes to a file.

Parameters
filename:str | bytesPath to write the .gitattributes file
_patterns =

Undocumented