Skip to documentation

Merger

Class
implements MergerInterface
Final: Yes

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.

Table of Contents

Interfaces

MergerInterface

Merges export-ignore entries with existing .gitattributes content.

Methods

merge()

Merges generated export-ignore entries with existing .gitattributes content.

 : string
extractExportIgnorePathSpec()

Extracts the path spec from a simple export-ignore line.

 : string|null
isLiteralPathSpec()

Determines whether a path spec is a literal path and not a glob pattern.

 : bool
keepInExportLookup()

Builds a lookup table for paths that MUST stay in the exported archive.

 : array<string, true>
normalizePathKey()

Normalizes a path spec for deduplication and keep-in-export matching.

 : string
normalizePathSpec()

Normalizes a gitattributes path spec for sorting.

 : string
parseExistingLines()

Parses the raw .gitattributes content into trimmed non-empty lines.

 : array<int, string>
Methods

merge()

Public

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:

  1. Preserves custom user-defined entries in their original order
  2. Prepends missing generated defaults before consumer overrides
  3. Omits generated duplicates without deduplicating existing rules
  4. 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
string

Description

The merged .gitattributes content

extractExportIgnorePathSpec()

Private

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
string|null

Description

the extracted path spec when the line is a simple export-ignore rule

isKeptPath()

Private
private isKeptPath( string  $pathKey, array<string, true>  $keptExportLookup) : bool
Parameters
$pathKey : string
$keptExportLookup : array<string, true>
Return values
bool

isLiteralPathSpec()

Private

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
bool

Description

true when the path spec is a literal path

keepInExportLookup()

Private

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
array<string, true>

Description

the normalized path lookup

normalizePathKey()

Private

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
string

Description

the normalized deduplication key

normalizePathSpec()

Private

Normalizes a gitattributes path spec for sorting.

private normalizePathSpec( string  $pathSpec) : string
Parameters
$pathSpec : string

Description

the raw path spec to normalize

Return values
string

Description

the normalized path spec

parseExistingLines()

Private

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
array<int, string>

Description

the non-empty lines from the file

Search results