Merges .gitattributes content with generated export-ignore rules.
Description
This class preserves existing custom entries while adding missing export-ignore rules for known candidate paths, deduplicates semantically equivalent entries, and sorts export-ignore rules with directories before files.
Interfaces
Methods
Merges generated export-ignore entries with existing .gitattributes content.
Extracts the path spec from a simple export-ignore line.
Builds a lookup table of generated directory candidates.
Determines whether a path spec is a literal path and not a glob pattern.
Builds a lookup table for paths that MUST stay in the exported archive.
Normalizes a .gitattributes line for deterministic comparison and output.
Normalizes a path spec for deduplication and keep-in-export matching.
Normalizes a gitattributes path spec for sorting.
Parses the raw .gitattributes content into trimmed non-empty lines.
Builds the natural sort key for a path spec.
Merges generated export-ignore entries with existing .gitattributes content.
public
merge(
string
$existingContent,
array<int, string>
$exportIgnoreEntries[,
array<int, string>
$keepInExportPaths = []]) : string
Description
This method:
- Preserves custom user-defined entries in their original order
- Adds missing generated export-ignore entries for existing paths
- Deduplicates entries using normalized path comparison
- Sorts export-ignore entries with directories before files
Parameters
$existingContent
:
string
Description
The raw .gitattributes content currently stored.
$exportIgnoreEntries
:
array<int, string>
Description
the export-ignore entries to manage
$keepInExportPaths
:
array<int, string>
=
[]
Description
the paths that MUST remain exported
Return values
Description
The merged .gitattributes content
Extracts the path spec from a simple export-ignore line.
private
extractExportIgnorePathSpec(
string
$line) : string|null
Parameters
$line
:
string
Description
the line to inspect
Return values
Description
the extracted path spec when the line is a simple export-ignore rule
Builds a lookup table of generated directory candidates.
private
generatedDirectoryLookup(
array<int, string>
$exportIgnoreEntries) : array<string, true>
Parameters
$exportIgnoreEntries
:
array<int, string>
Description
the generated export-ignore path list
Return values
Description
the normalized directory lookup
Determines whether a path spec is a literal path and not a glob pattern.
private
isLiteralPathSpec(
string
$pathSpec) : bool
Parameters
$pathSpec
:
string
Description
the normalized path spec to inspect
Return values
Description
true when the path spec is a literal path
Builds a lookup table for paths that MUST stay in the exported archive.
private
keepInExportLookup(
array<int, string>
$keepInExportPaths) : array<string, true>
Parameters
$keepInExportPaths
:
array<int, string>
Description
the configured keep-in-export paths
Return values
Description
the normalized path lookup
Normalizes a .gitattributes line for deterministic comparison and output.
private
normalizeLine(
string
$line) : string
Parameters
$line
:
string
Description
the raw line to normalize
Return values
Description
the normalized line
Normalizes a path spec for deduplication and keep-in-export matching.
private
normalizePathKey(
string
$pathSpec) : string
Description
Literal root paths are compared without leading slash differences, while pattern-based specs preserve their original anchoring semantics.
Parameters
$pathSpec
:
string
Description
the raw path spec to normalize
Return values
Description
the normalized deduplication key
Normalizes a gitattributes path spec for sorting.
private
normalizePathSpec(
string
$pathSpec) : string
Parameters
$pathSpec
:
string
Description
the raw path spec to normalize
Return values
Description
the normalized path spec
Parses the raw .gitattributes content into trimmed non-empty lines.
private
parseExistingLines(
string
$content) : array<int, string>
Parameters
$content
:
string
Description
The full .gitattributes content.
Return values
Description
the non-empty lines from the file
Builds the natural sort key for a path spec.
private
sortKey(
string
$pathSpec) : string
Parameters
$pathSpec
:
string
Description
the raw path spec to normalize for sorting
Return values
Description
the natural sort key