Merges .gitattributes content with generated export-ignore rules.
Description
This class preserves existing custom entries while adding missing export-ignore defaults before consumer rules. Existing rules MUST retain their order and repetitions so later unset and unspecified attributes keep precedence.
Interfaces
Methods
Merges generated export-ignore entries with existing .gitattributes content.
Extracts the path spec from a simple export-ignore line.
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 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.
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
- Prepends missing generated defaults before consumer overrides
- Omits generated duplicates without deduplicating existing rules
- Removes simple positive rules for explicitly kept paths
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
private
isKeptPath(
string
$pathKey,
array<string, true>
$keptExportLookup) : bool
Parameters
$pathKey
:
string
$keptExportLookup
:
array<string, true>
Return values
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 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