Skip to content
github-actions edited this page Apr 9, 2026 · 1 revision

Merges, deduplicates, and sorts .gitignore entries.

This service SHALL combine canonical and project-specific .gitignore definitions into a single normalized result. The resulting entry list MUST exclude blank lines and comment lines from the merged output, MUST remove duplicate entries, and MUST group directory entries before file entries. Directory and file groups SHALL be sorted independently in ascending string order to provide deterministic output.


Methods

__construct

Initializes the merger with a classifier implementation.

public __construct(\FastForward\DevTools\GitIgnore\ClassifierInterface $classifier = new \FastForward\DevTools\GitIgnore\Classifier()): mixed

The classifier MUST be capable of determining whether a normalized .gitignore entry represents a directory or a file pattern. When no classifier is provided, a default Classifier instance SHALL be used.

Parameters:

Parameter Type Description
$classifier \FastForward\DevTools\GitIgnore\ClassifierInterface the classifier responsible for
distinguishing directory entries
from file entries during merging

merge

Merges canonical and project .gitignore entries into a normalized result.

public merge(\FastForward\DevTools\GitIgnore\GitIgnoreInterface $canonical, \FastForward\DevTools\GitIgnore\GitIgnoreInterface $project): \FastForward\DevTools\GitIgnore\GitIgnoreInterface

The implementation MUST combine entries from both sources, MUST remove duplicates, and MUST ignore blank or commented entries after trimming. Entries identified as directories SHALL be collected separately from file entries. Each group MUST be sorted using string comparison, and directory entries MUST appear before file entries in the final result.

The returned GitIgnore instance SHALL preserve the project path provided by the $project argument.

Parameters:

Parameter Type Description
$canonical \FastForward\DevTools\GitIgnore\GitIgnoreInterface The canonical .gitignore source whose
entries provide the shared baseline.
$project \FastForward\DevTools\GitIgnore\GitIgnoreInterface The project-specific .gitignore source
whose path MUST be preserved in the
merged result.

Return Value:

A new merged .gitignore representation containing normalized, deduplicated, and ordered entries.


Clone this wiki locally